#!/data/data/com.termux/files/usr/bin/bash -e
#set -x

#####################################################################
#                                                                   #
#               Compiles Faust programs to Max6/7/8 externals       #
#               using double precision samples                      #
#               (c) Grame, 2012-2024                                #
#                                                                   #
#####################################################################

. faustpath
. faustoptflags
. faustusage.sh

# Keep architecture headers in sync with the selected architecture directory.
# FAUST_ARCH_PATH is searched before the compiler's installed directories.
export FAUST_ARCH_PATH="${FAUST_ARCH_PATH:-$FAUSTARCH}"

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

OSCDEFS=""
OSCLIB=""
POLY=""
NOPATCH="0"
NOSRC="0"
NVOICES=-1
FILES=()
OPTIONS=()
EXTRA_CXXFLAGS=()
EFFECT=""
ARCH="auto"
SOUNDFILE="0"
SOUNDFILEDEFS=""
SOUNDFILELIBS=""
MC=""
OPT=""
US="0"
DS="0"
FILTER="0"
FAUSTFLOAT="double" # By default since Max6
POST="-DPOST"

# path to max SDK
# MAXSDK is declared in faustpath
MAXINC=$MAXSDK/max-includes
MSPINC=$MAXSDK/msp-includes

LINK_FLAGS="-Wl,-U,_object_post,-U,_object_new_imp,-U,_atom_getlong,-U,_atom_getobj,-U,_atom_getsym,-U,_atom_gettype,-U,_atom_setfloat,-U,_atom_setsym,-U,_class_addmethod,-U,_class_new,-U,_class_register,-U,_common_symbols_gettable,-U,_dictionary_appendlong,-U,_dictionary_appendstring,-U,_dictionary_getlong,-U,_dictionary_getstring,-U,_gensym,-U,_jbox_get_color,-U,_jbox_get_nextobject,-U,_jbox_get_object,-U,_jbox_get_varname,-U,_jbox_set_varname,-U,_jmouse_getposition_global,-U,_jpatcher_get_firstobject,-U,_jpatcher_set_dirty,-U,_jpopupmenu_additem,-U,_jpopupmenu_create,-U,_jpopupmenu_destroy,-U,_jpopupmenu_popup,-U,_jrgba_set,-U,_locatefile_extended,-U,_object_alloc,-U,_object_attr_setchar,-U,_object_attr_setsym,-U,_object_classname,-U,_object_classname_compare,-U,_object_error_obtrusive,-U,_object_free,-U,_object_method_imp,-U,_object_method_typed,-U,_object_obex_lookup,-U,_open_dialog,-U,_outlet_append,-U,_outlet_bang,-U,_outlet_delete,-U,_outlet_int,-U,_outlet_list,-U,_outlet_nth,-U,_path_createsysfile,-U,_path_opensysfile,-U,_path_setdefault,-U,_path_topathname,-U,_post,-U,_proxy_getinlet,-U,_saveas_dialog,-U,_strncpy_zero,-U,_sysfile_close,-U,_sysfile_readtextfile,-U,_sysfile_setpos,-U,_sysfile_writetextfile,-U,_sysmem_copyptr,-U,_sysmem_freehandle,-U,_sysmem_handlesize,-U,_sysmem_newhandle,-U,_sysmem_newhandleclear,-U,_jbox_set_color,-U,_path_getdefault,-U,_attr_args_process,-U,_attr_offset_new,-U,_class_addattr,-U,_class_attr_get,-U,_outlet_new,-U,_systhread_mutex_free,-U,_systhread_mutex_lock,-U,_systhread_mutex_new,-U,_systhread_mutex_trylock,-U,_systhread_mutex_unlock"

JSFILE_PATH="ui.js"

createInfoPList()
{
    (
    echo '<?xml version="1.0" encoding="UTF-8"?>'
    echo '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">'
    echo '<plist version="1.0">'
    echo '<dict>'
    echo '  <key>CFBundleDevelopmentRegion</key>'
    echo '  <string>English</string>'
    echo '  <key>CFBundleExecutable</key>'
    echo "    <string>$1</string>"
    echo '  <key>CFBundleIconFile</key>'
    echo '  <string></string>'
    echo '  <key>CFBundleIdentifier</key>'
    echo "  <string>com.grame.$1</string>"
    echo '  <key>CFBundleInfoDictionaryVersion</key>'
    echo '  <string>1.0.0</string>'
    echo '  <key>CFBundlePackageType</key>'
    echo '  <string>iLaX</string>'
    echo '  <key>CFBundleSignature</key>'
    echo '  <string>max2</string>'
    echo '  <key>CFBundleVersion</key>'
    echo '  <string>1.0.0</string>'
    echo '  <key>CFBundleShortVersionString</key>'
    echo '  <string>1.0.0</string>'
    echo '  <key>CFBundleLongVersionString</key>'
    echo "  <string>$1 1.0.0, Copyright 2012-2024 Grame</string>"
    echo '  <key>CSResourcesFileMapped</key>'
    echo '  <true/>'
    echo '</dict>'
    echo '</plist>'
    ) > "$2"
}

echoHelp()
{
    status=${1:-0}
    usage faust2max6 "[options] [Faust options] <file.dsp>"
    require Max/MSP SDK
    echo "Compiles Faust programs to Max6 externals using double precision samples (see https://github.com/grame-cncm/faust/tree/master-dev/architecture/max-msp)"
    option
    options -osc -midi -soundfile
    option -soundfile-dynamic "similar to -soundfile, but using the installed libsndfile (so possibly using dynamic link)."
    option "-opt native|generic" "activates the best compilation options for the native or generic CPU."
    option "-nvoices <num>"
    option "-us <factor>"
    option "-ds <factor>"
    option "-filter <filter>"
    option "-effect <effect.dsp>"
    option -mc "to activate multi-channels model"
    option -native "to compile for the native CPU (otherwise the 'generic' mode is used by default)"
    option "-arch auto|arm64|x86_64|universal" "selects the macOS external architecture (auto keeps the historical behavior)"
    option -universal "alias for '-arch universal'"
    option -nopatch "to deactivate patch generation"
    option -nosrc "to omit the original DSP, expanded DSP, generated C++ and JSON description from the external"
    option -nopost "to disable informational Faust messages in the Max console"
    option "Faust options"
    exit "$status"
}

requireValue()
{
    option_name=$1
    if [ "$#" -lt 2 ] || [ -z "$2" ]; then
        echo "Missing value for $option_name" >&2
        exit 1
    fi
}

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

#-------------------------------------------------------------------
# Analyze command arguments :
# faust options                 -> OPTIONS
# if -omp : -openmp or -fopenmp -> OPENMP
# existing *.dsp files          -> FILES
#

#PHASE 2 : dispatch command arguments
while [ "$#" -gt 0 ]
do
    p=$1

    if [ "$p" = "-help" ] || [ "$p" = "--help" ] || [ "$p" = "-h" ]; then
       echoHelp
    elif [ "$p" = "-opt" ]; then
        shift
        requireValue -opt "${1:-}"
        OPT=$1
    elif [ "$p" = "-nvoices" ]; then
        shift
        if [[ ! "$1" =~ ^[1-9][0-9]*$ ]]; then
            echo "Invalid voice count '${1:-}' (expected a positive integer)" >&2
            exit 1
        fi
        POLY="POLY1"
        NVOICES=$1
        CXXFLAGS="$CXXFLAGS -DNVOICES=$NVOICES"
    elif [ "$p" = "-effect" ]; then
        POLYDEFS="-DPOLY2"
        shift
        requireValue -effect "${1:-}"
        EFFECT=$1
    elif [ "$p" = "-midi" ]; then
        MIDIDEFS="-DMIDICTRL"
    elif [ "$p" = "-arch" ]; then
        shift
        requireValue -arch "${1:-}"
        ARCH=$1
        if [[ "$ARCH" != "auto" && "$ARCH" != "arm64" && "$ARCH" != "x86_64" && "$ARCH" != "universal" ]]; then
            echo "Invalid architecture '$ARCH' (expected auto, arm64, x86_64, or universal)"
            exit 1
        fi
    elif [ "$p" = "-universal" ]; then
        ARCH="universal"
    elif [ "$p" = "-mc" ]; then
        MC="-DMC_VERSION"
    elif [ "$p" = "-soundfile-dynamic" ]; then
        SOUNDFILE="1"
        SOUNDFILEDEFS="-DSOUNDFILE"
        SOUNDFILELIBS=`pkg-config --cflags --static --libs sndfile`
    elif [ "$p" = "-soundfile" ]; then
        SOUNDFILE="1"
        SOUNDFILEDEFS="-DSOUNDFILE -I$FAUSTARCH/max-msp/sndfile"
        SFDIR=$FAUSTARCH/max-msp/sndfile
        SOUNDFILELIBS_ARM="$SFDIR/arm/libsndfile.a"
        SOUNDFILELIBS_INTEL="$SFDIR/intel/libsndfile.a"
    elif [ "$p" = "-osc" ]; then
        OSCDEFS="-DOSCCTRL"
        OSCLIBS="-lOSCFaust"
    elif [ "$p" = "-nopost" ]; then
        POST=""
    elif [ "$p" = "-nosrc" ]; then
        NOSRC="1"
    elif [ "$p" = "-nopatch" ]; then
        NOPATCH="1"
    elif [ "$p" = "-native" ]; then
        CXXFLAGS=$MYGCCFLAGS
    elif [ "$p" = "-single" ]; then
        FAUSTFLOAT="float"
    elif [ "$p" = "-us" ]; then
        shift
        requireValue -us "${1:-}"
        US=$1
    elif [ "$p" = "-ds" ]; then
        shift
        requireValue -ds "${1:-}"
        DS=$1
    elif [ "$p" = "-filter" ]; then
        shift
        requireValue -filter "${1:-}"
        FILTER=$1
    # '-A path' also added as '-I path' in the C++ command
    elif [ "$p" = "-A" ]; then
        shift
        requireValue -A "${1:-}"
        EXTRA_CXXFLAGS+=("-I" "$1")
        OPTIONS+=("-A" "$1")
    elif [ "${p:0:1}" = "-" ]; then
        OPTIONS+=("$p")
    elif [[ -f "$p" ]] && [ "${p: -4}" = ".dsp" ]; then
        FILES+=("$p")
    else
        OPTIONS+=("$p")
    fi

shift

done

if [ ${#FILES[@]} -eq 0 ]; then
    echo "No DSP file was provided" >&2
    exit 1
fi

#customize CXXFLAGS
CXXFLAGS+=" -fbracket-depth=512"

#-------------------------------------------------------------------
# Check darwin specifics
#
if [[ $(uname) == Darwin  || $CROSSTARGET == Darwin ]]; then
    EXT="~.mxo"
fi

#-------------------------------------------------------------------
# compile the *.dsp files
#
PATH=$PATH:/data/data/com.termux/files/usr/bin

for p in "${FILES[@]}"; do

    CUR=$(pwd)
    f=$(basename "$p")
    SRCDIR=$(dirname "$p")
    FILE_OPTIONS=("${OPTIONS[@]}")

    FILE_POLY=$POLY
    FILE_NVOICES=$NVOICES
    if [ "$FILE_POLY" != "POLY1" ]; then
        DECLARED_NVOICES=$(sed -nE 's/.*declare[[:space:]]+nvoices[[:space:]]+"?([0-9]+)"?[[:space:]]*;.*/\1/p' "$p" | head -n 1)
        if [ -n "$DECLARED_NVOICES" ] && [ "$DECLARED_NVOICES" -gt 0 ]; then
            FILE_POLY="POLY1"
            FILE_NVOICES=$DECLARED_NVOICES
        fi
    fi
    if [ "$FILE_POLY" = "POLY1" ] && [ "$FILE_NVOICES" -lt 1 ]; then
        FILE_NVOICES=8
    fi

    # creates a temporary dir, outside of the working directory, and make sure
    # it is removed even when a step below exits early
    TDR=$(mktemp -d "${TMPDIR:-/tmp}/faust.XXXXXX")
    trap 'rm -rf "$TDR"; rm -f "$p.json"' EXIT
    TMP="$TDR/${f%.dsp}"
    mkdir "$TMP"

    # discover best compilation options
    if [ "$OPT" = "generic" ]; then
        echo "Look for best compilation options in 'generic' mode..."
        BENCH_OPTIONS=$(faustbench-llvm -notrace -generic "${FILE_OPTIONS[@]}" "$f")
        read -r -a DISCOVERED_OPTIONS <<< "$BENCH_OPTIONS"
        FILE_OPTIONS+=("${DISCOVERED_OPTIONS[@]}")
        echo "${FILE_OPTIONS[*]}"
    elif [ "$OPT" = "native" ]; then
        echo "Look for best compilation options in 'native' mode..."
        BENCH_OPTIONS=$(faustbench-llvm -notrace "${FILE_OPTIONS[@]}" "$f")
        read -r -a DISCOVERED_OPTIONS <<< "$BENCH_OPTIONS"
        FILE_OPTIONS+=("${DISCOVERED_OPTIONS[@]}")
        echo "${FILE_OPTIONS[*]}"
    fi

    # -double is used by default
    if [ "$FAUSTFLOAT" = "double" ]; then
        FILE_OPTIONS+=("-double")
    fi

    # compile Faust to c++
    if [ "$EFFECT" = "" ]; then
        faust -i -cn "${f%.dsp}" -json -a "$FAUSTARCH/max-msp/max-msp64.cpp" "${FILE_OPTIONS[@]}" "$SRCDIR/$f" -o "$TMP/${f%.dsp}.cpp" || exit
    else
        if [[ "$EFFECT" = /* ]]; then
            EFFECT_PATH=$EFFECT
        else
            EFFECT_PATH="$SRCDIR/$EFFECT"
        fi
        faust -i -cn "${f%.dsp}" -json -a "$FAUSTARCH/max-msp/max-msp64.cpp" "${FILE_OPTIONS[@]}" "$SRCDIR/$f" -o "$TMP/${f%.dsp}.cpp" || exit
        faust -i -cn effect -a "$FAUSTARCH/minimal-effect.cpp" "${FILE_OPTIONS[@]}" "$EFFECT_PATH" -o "$TMP/effect.h" || exit
    fi
    if [ "$NOSRC" = "0" ]; then
        # Compile a self-contained expansion with the same include and codegen options.
        faust -e "$SRCDIR/$f" "${FILE_OPTIONS[@]}" -o "$TMP/${f%.dsp}-exp.dsp"
    fi

    # compile c++ to binary
    (
        # FAUST_FILE_NAME is always added
        cd "$TMP"
        install -d "${f%.dsp}$EXT/Contents/MacOS"
        # Keep the historical default: universal binaries are produced on M1.
        if [[ "$ARCH" = "universal" || ("$ARCH" = "auto" && $(uname -p) = arm) ]]; then
            $CXX $CXXFLAGS "${EXTRA_CXXFLAGS[@]}" -DFAUST_FILE_NAME="\"$f\"" -arch arm64 -mmacosx-version-min=10.9 -Wfatal-errors -framework Carbon $MC $POLYDEFS $MIDIDEFS $SOUNDFILEDEFS $OSCDEFS $POST -DDOWN_SAMPLING=$DS -DUP_SAMPLING=$US -DFILTER_TYPE=$FILTER -DFAUSTFLOAT=$FAUSTFLOAT -I "$CUR" -I"$MAXINC" -I"$MSPINC" -F"$MAXINC" -F"$MSPINC" -framework MaxAudioAPI $SOUNDFILELIBS $SOUNDFILELIBS_ARM $OSCLIBS $LINK_FLAGS -bundle "${f%.dsp}.cpp" -o "${f%.dsp}$EXT/Contents/MacOS/${f%.dsp}~.arm64"
            $CXX $CXXFLAGS "${EXTRA_CXXFLAGS[@]}" -DFAUST_FILE_NAME="\"$f\"" -arch x86_64 -mmacosx-version-min=10.9 -Wfatal-errors -framework Carbon $MC $POLYDEFS $MIDIDEFS $SOUNDFILEDEFS $OSCDEFS $POST -DDOWN_SAMPLING=$DS -DUP_SAMPLING=$US -DFILTER_TYPE=$FILTER -DFAUSTFLOAT=$FAUSTFLOAT -I "$CUR" -I"$MAXINC" -I"$MSPINC" -F"$MAXINC" -F"$MSPINC" -framework MaxAudioAPI $SOUNDFILELIBS $SOUNDFILELIBS_INTEL $OSCLIBS $LINK_FLAGS -bundle "${f%.dsp}.cpp" -o "${f%.dsp}$EXT/Contents/MacOS/${f%.dsp}~.x86_64"
            $LIPO -create "${f%.dsp}$EXT/Contents/MacOS/${f%.dsp}~.arm64" "${f%.dsp}$EXT/Contents/MacOS/${f%.dsp}~.x86_64" -output "${f%.dsp}$EXT/Contents/MacOS/${f%.dsp}~" || exit
            # the per-architecture slices are merged now, and codesign would
            # treat the leftovers as unsigned subcomponents
            rm -f "${f%.dsp}$EXT/Contents/MacOS/${f%.dsp}~.arm64" "${f%.dsp}$EXT/Contents/MacOS/${f%.dsp}~.x86_64"
        elif [ "$ARCH" = "arm64" ]; then
            $CXX $CXXFLAGS "${EXTRA_CXXFLAGS[@]}" -DFAUST_FILE_NAME="\"$f\"" -arch arm64 -mmacosx-version-min=10.9 -Wfatal-errors -framework Carbon $MC $POLYDEFS $MIDIDEFS $SOUNDFILEDEFS $OSCDEFS $POST -DDOWN_SAMPLING=$DS -DUP_SAMPLING=$US -DFILTER_TYPE=$FILTER -DFAUSTFLOAT=$FAUSTFLOAT -I "$CUR" -I"$MAXINC" -I"$MSPINC" -F"$MAXINC" -F"$MSPINC" -framework MaxAudioAPI $SOUNDFILELIBS $SOUNDFILELIBS_ARM $OSCLIBS $LINK_FLAGS -bundle "${f%.dsp}.cpp" -o "${f%.dsp}$EXT/Contents/MacOS/${f%.dsp}~"
        elif [ "$ARCH" = "x86_64" ]; then
            $CXX $CXXFLAGS "${EXTRA_CXXFLAGS[@]}" -DFAUST_FILE_NAME="\"$f\"" -arch x86_64 -mmacosx-version-min=10.9 -Wfatal-errors -framework Carbon $MC $POLYDEFS $MIDIDEFS $SOUNDFILEDEFS $OSCDEFS $POST -DDOWN_SAMPLING=$DS -DUP_SAMPLING=$US -DFILTER_TYPE=$FILTER -DFAUSTFLOAT=$FAUSTFLOAT -I "$CUR" -I"$MAXINC" -I"$MSPINC" -F"$MAXINC" -F"$MSPINC" -framework MaxAudioAPI $SOUNDFILELIBS $SOUNDFILELIBS_INTEL $OSCLIBS $LINK_FLAGS -bundle "${f%.dsp}.cpp" -o "${f%.dsp}$EXT/Contents/MacOS/${f%.dsp}~"
        else
            # Native target on Intel (the Apple Silicon auto case is above).
            $CXX $CXXFLAGS "${EXTRA_CXXFLAGS[@]}" -DFAUST_FILE_NAME="\"$f\"" -arch x86_64 -mmacosx-version-min=10.9 -Wfatal-errors -framework Carbon $MC $POLYDEFS $MIDIDEFS $SOUNDFILEDEFS $OSCDEFS $POST -DDOWN_SAMPLING=$DS -DUP_SAMPLING=$US -DFILTER_TYPE=$FILTER -DFAUSTFLOAT=$FAUSTFLOAT -I "$CUR" -I"$MAXINC" -I"$MSPINC" -F"$MAXINC" -F"$MSPINC" -framework MaxAudioAPI $SOUNDFILELIBS $SOUNDFILELIBS_INTEL $OSCLIBS $LINK_FLAGS -bundle "${f%.dsp}.cpp" -o "${f%.dsp}$EXT/Contents/MacOS/${f%.dsp}~"
        fi
       ) > /dev/null || exit

    rm -rf "$SRCDIR/${f%.dsp}$EXT"

    # Runtime assets still need Resources when source packaging is disabled.
    # Bundle resources must be installed before code signing.
    install -d "$TMP/${f%.dsp}$EXT/Contents/Resources"
    if [ "$NOSRC" = "0" ]; then
        cp "$TMP/${f%.dsp}.cpp" "$TMP/${f%.dsp}$EXT/Contents/Resources"
        cp "$TMP/${f%.dsp}-exp.dsp" "$TMP/${f%.dsp}$EXT/Contents/Resources"
        cp "$SRCDIR/$f" "$TMP/${f%.dsp}$EXT/Contents/Resources"
        # The JSON description written by 'faust -json' next to the source
        # (name, inputs/outputs, compile options, metadata, UI).
        cp "$p.json" "$TMP/${f%.dsp}$EXT/Contents/Resources/${f%.dsp}.json"
    fi
 
    # Create Info.plist
    createInfoPList "${f%.dsp}~" "$TMP/${f%.dsp}$EXT/Contents/Info.plist"

    if [ "$SOUNDFILE" = "1" ]; then
        # get all soundfiles from the JSON file
        awk '
                        BEGIN { FS=":"; SOFI=0; }
                            /"soundfile"/ { SOFI=1; }
                            /"url"/ {
                            if (SOFI) {
                                match($2, /"[^"]*/);
                                split(substr($2, RSTART+2, RLENGTH-3), res, ";");
                                for (x in res) print substr(res[x], 2, length(res[x])-2);
                                SOFI=0;
                            }
                        }
        ' "$p.json" > "$p-tmp.txt"
        # copy found soundfiles in the final binary
        while IFS= read -r snd; do
            if [ -f "$snd" ]; then
                if [ "${snd:0:1}" = "/" ]; then
                    echo "Warning: soundfile with absolute path is not copied !"
                else
                    #create destination path and possibly create directory
                    sfpath="$TMP/${f%.dsp}$EXT/Contents/Resources/$(dirname "$snd")/"
                    if ! [ -d "$sfpath" ]; then
                        echo "Create $sfpath"
                        mkdir -p "$sfpath"
                    fi
                    echo "Copy $snd in ${f%.dsp}$EXT"
                    cp "$snd" "$sfpath"
                fi
            else
                echo "Error: file $snd not found !"
            fi
        done < "$p-tmp.txt"
        rm "$p-tmp.txt"
    fi

    cp -r "$TMP/${f%.dsp}$EXT" "$SRCDIR/${f%.dsp}$EXT"

    # Sign last: the file copies and createInfoPList above add content to the
    # bundle, which would break a seal made right after the link step
    if which codesign > /dev/null; then
        # copied files carry extended attributes that codesign rejects
        xattr -cr "$SRCDIR/${f%.dsp}$EXT"
        codesign --sign - --force "$SRCDIR/${f%.dsp}$EXT"
    fi

    rm -rf "$TDR"
    rm -f "$p.json"

    # collect binary file name for FaustGIDE
    BINARIES="$BINARIES$SRCDIR/${f%.dsp}$EXT;"

    # create Max patch
    if [ "$NOPATCH" = "0" ]; then
        if [ "$FILE_POLY" = "POLY1" ]; then
            if [ "$MC" = "-DMC_VERSION" ]; then
                cat "$FAUSTARCH/max-msp/mc-wrapper-poly.maxpat" > "${f%.dsp}-temp1.maxpat"
            else
                cat "$FAUSTARCH/max-msp/wrapper-poly.maxpat" > "${f%.dsp}-temp1.maxpat"
            fi
        else
            if [ "$MC" = "-DMC_VERSION" ]; then
                cat "$FAUSTARCH/max-msp/mc-wrapper.maxpat" > "${f%.dsp}-temp1.maxpat"
            else
                cat "$FAUSTARCH/max-msp/wrapper.maxpat" > "${f%.dsp}-temp1.maxpat"
            fi
        fi
        sed -e "s/DSP_NAME/${f%.dsp}~/g" -e "s/NVOICES/$FILE_NVOICES/g" \
            "${f%.dsp}-temp1.maxpat" > "${f%.dsp}-temp2.maxpat"
        sed -e "s/UI_FILE/$JSFILE_PATH/g" \
            "${f%.dsp}-temp2.maxpat" > "${f%.dsp}.maxpat"

        # copy JavaScript UI file
        cp "$FAUSTARCH/max-msp/$JSFILE_PATH" .

        rm "${f%.dsp}-temp1.maxpat"
        rm "${f%.dsp}-temp2.maxpat"
    fi

done

if [ "$NOPATCH" = "0" ]; then
    BINARIES="$BINARIES ${f%.dsp}.maxpat $JSFILE_PATH"
fi

echo $BINARIES
