diff --git a/tools/faust2appls/faust2faustvst b/tools/faust2appls/faust2faustvst index bea29e32cc..24fd12d75a 100755 --- a/tools/faust2appls/faust2faustvst +++ b/tools/faust2appls/faust2faustvst @@ -1,10 +1,11 @@ -#! /bin/bash +#!/usr/bin/env bash -#set -x . faustpath . faustoptflags +set -eou > /dev/null + # Check for some common locations of the VST SDK files. This falls back to # /usr/local/src/vstsdk if none of these are found. In that case, or if make # picks the wrong location, you can also set the SDK variable explicitly. @@ -15,21 +16,20 @@ # the preferred path comes *last*. sdkpaths="/usr/src/VST* /usr/src/vst* /usr/include/VST* /usr/include/vst* /opt/local/src/VST* /opt/local/src/vst* /opt/local/include/VST* /opt/local/include/vst* /usr/local/src/VST* /usr/local/src/vst* /usr/local/include/VST* /usr/local/include/vst* $VSTSDK" # This should hopefully work on *BSD, Linux and Mac OSX. -[ -z "$SDK" ] && SDK=$(echo $sdkpaths | xargs ls -f -d 2>/dev/null | tail -n 1) -[ -z "$SDK" ] && SDK=/usr/local/src/vstsdk +[ -z "${SDK:-}" ] && SDK=$(echo "$sdkpaths" | xargs ls -f -d 2>/dev/null | tail -n 1) +[ -z "${SDK:-}" ] && SDK=/usr/local/src/vstsdk # SDKSRC should point to the SDK source files (vstplugmain.cpp et al). # Usually these are either directly under $SDK or in the # public.sdk/source/vst2.x subdirectory. -[ -z "$SDKSRC" -a -f "$SDK/vstplugmain.cpp" ] && SDKSRC="$SDK" -[ -z "$SDKSRC" -a -f "$SDK/public.sdk/source/vst2.x/vstplugmain.cpp" ] && SDKSRC="$SDK/public.sdk/source/vst2.x" -[ -z "$SDKSRC" ] && SDKSRC="$SDK/public.sdk/source/vst2.x" +[ -z "${SDKSRC:-}" ] && [ -f "$SDK/vstplugmain.cpp" ] && SDKSRC="$SDK" +[ -z "${SDKSRC:-}" ] && [ -f "$SDK/public.sdk/source/vst2.x/vstplugmain.cpp" ] && SDKSRC="$SDK/public.sdk/source/vst2.x" +[ -z "${SDKSRC:-}" ] && SDKSRC="$SDK/public.sdk/source/vst2.x" -# Default qmake setup (for GUI compilation). This requires Qt4 or Qt5 (Qt5 is -# preferred). We try to locate the qmake executable in some common locations -# here. If this doesn't work out then you can also set the QMAKE environment -# variable explicitly, or use one of the -qt4 and -qt5 options below. -[ -z "$QMAKE" ] && QMAKE=$(which qmake-qt5 || which /opt/local/libexec/qt5/bin/qmake || which qmake-qt4 || which /opt/local/libexec/qt4/bin/qmake || echo qmake) +# Default qmake setup (for GUI compilation). This requires Qt5. If qmake-qt5 or +# qmake can not be found in PATH, you can set the QMAKE environment variable +# explicitly, or use the -qt5 option below. +[ -z "${QMAKE:-}" ] && QMAKE=$(command -v qmake-qt5 || command -v qmake) # Where the Faust includes live. We assume that this is under the prefix of # whatever Faust binary 'which' locates. You can also specify this explicitly @@ -60,14 +60,17 @@ NVOICES=-1 KEEP="no" STYLE="" -PROCARCH="-fPIC" +FILES=() +OPTIONS=() + +PROCARCH=("-fPIC") dllext=".so" -CXXFLAGS="-O3 -std=c++11 -march=native -mfpmath=sse -msse -msse2 -msse3 -ffast-math -ftree-vectorize" +CXXFLAGS=("-O3" "-std=c++11" "-march=native" "-mfpmath=sse" "-msse" "-msse2" "-msse3" "-ffast-math" "-ftree-vectorize") # Darwin-specific #ARCH="-arch i386 -arch x86_64" -if [[ $(uname) == Darwin || $CROSSTARGET == Darwin ]]; then - CXXFLAGS="-O3 -std=c++11 $ARCH -mfpmath=sse -msse -msse2 -msse3 -ffast-math -ftree-vectorize -I/opt/local/include" +if [[ $(uname) == Darwin || ${CROSSTARGET:-} == Darwin ]]; then + CXXFLAGS=("-O3" "-std=c++11" "$ARCH" "-mfpmath=sse" "-msse" "-msse2" "-msse3" "-ffast-math" "-ftree-vectorize" "-I/opt/local/include") dllext=".vst" fi @@ -88,7 +91,7 @@ Options: -novoicectrls: no extra polyphony/tuning controls on GUI (instruments only) -nvoices N: number of synth voices (instruments only; arg must be an integer) -osc: activate OSC control --qt4, -qt5: select the GUI toolkit (requires Qt4/5; implies -gui) +-qt5: select the GUI toolkit (requires Qt5; implies -gui) -style S: select the stylesheet (arg must be Default, Blue, Grey or Salmon) Environment variables: @@ -108,7 +111,7 @@ EOF : ignore elif [ $p = "-icc" ]; then CXX=icpc - CXXFLAGS="-O3 -std=c++11 -xHost -ftz -fno-alias -fp-model fast=2" + CXXFLAGS=("-O3" "-std=c++11" "-xHost" "-ftz" "-fno-alias" "-fp-model" "fast=2") elif [ $p = "-osc" ]; then OSCDEFS="DEFINES += OSCCTRL" OSCLIBS="-lOSCFaust" @@ -128,23 +131,19 @@ EOF elif [ $p = "-gui" ]; then FAUST_UI=1 plugin_gui=yes - elif [ $p = "-qt4" ]; then - FAUST_UI=1 - plugin_gui=yes - QMAKE=$(which qmake-qt4 || which /opt/local/libexec/qt4/bin/qmake || echo qmake-qt4) elif [ $p = "-qt5" ]; then FAUST_UI=1 plugin_gui=yes - QMAKE=$(which qmake-qt5 || which /opt/local/libexec/qt5/bin/qmake || echo qmake-qt5) + QMAKE=$(command -v qmake-qt5 || command -v qmake) elif [ $p = "-nvoices" ]; then (( i++ )) NVOICES=${!i} elif [ $p = "-arch32" ]; then - PROCARCH="-m32 -L/usr/lib32" + PROCARCH=("-m32" "-L/usr/lib32") elif [ $p = "-arch64" ]; then - PROCARCH="-m64 -fPIC" + PROCARCH=("-m64" "-fPIC") elif [ $p = "-osx" ]; then - CXXFLAGS="-O3 -std=c++11 $ARCH -mfpmath=sse -msse -msse2 -msse3 -ffast-math -ftree-vectorize -I/opt/local/include" + CXXFLAGS=("-O3" "-std=c++11" "$ARCH" "-mfpmath=sse" "-msse" "-msse2" "-msse3" "-ffast-math" "-ftree-vectorize" "-I/opt/local/include") dllext=".vst" elif [ $p = "-keep" ]; then KEEP="yes" @@ -152,15 +151,14 @@ EOF (( i++ )) STYLE=${!i} elif [ ${p:0:1} = "-" ]; then - OPTIONS="$OPTIONS $p" + OPTIONS+=("$p") elif [[ -f "$p" ]]; then - FILES="$FILES $p" + FILES+=("$p") else - OPTIONS="$OPTIONS $p" + OPTIONS+=("$p") fi done -FILES=( $FILES ) if [ ${#FILES[@]} = 0 ]; then echo "$0: no filename specified" >&2 exit 1 @@ -171,27 +169,19 @@ fi # Check to see whether the required include and library files are where we # expect them, and bail out with an error message otherwise. -if [ ! -f "$FAUSTINC/faust/gui/QTUI.h" ]; then echo "$0: faust include files not found" >&2; exit 1; fi -if [ ! -f "$FAUSTARCH/faustvstqt.h" ]; then echo "$0: faust-vst library files not found" >&2; exit 1; fi - -# Determine the Qt version so that we can pick the needed compilation options. -QTVERSION=$($QMAKE -v 2>/dev/null | tail -1 | sed 's/.*Qt version \([0-9]\).*/\1/') - -QTEXTRA= -if [ $QTVERSION = 5 ]; then -QTEXTRA=x11extras -fi +if [ ! -f "${FAUSTINC:-}/faust/gui/QTUI.h" ]; then echo "$0: faust include files not found" >&2; exit 1; fi +if [ ! -f "${FAUSTARCH:-}/faustvstqt.h" ]; then echo "$0: faust-vst library files not found" >&2; exit 1; fi arch=faustvst.cpp dspname=${FILES[0]} SRCDIR=$(dirname "$dspname") -ABSDIR=$(cd $SRCDIR && pwd) +ABSDIR=$(cd "$SRCDIR" && pwd) CURDIR=$(pwd) -clsname=`basename "$dspname" .dsp` +clsname=$(basename "$dspname" .dsp) cppname="$clsname.cpp" soname="$clsname$dllext" -tmpdir=`mktemp -d /tmp/faust2faustvst.XXXXXX` +tmpdir=$(mktemp -d /tmp/faust2faustvst.XXXXXX) RESOURCES= STYLE_CXXFLAGS= @@ -202,9 +192,9 @@ fi # now set in faustoptflags #CXX=g++ -CPPFLAGS="-DFAUST_META=$FAUST_META -DFAUST_MIDICC=$FAUST_MIDICC -DFAUST_MTS=$FAUST_MTS -DFAUST_UI=$FAUST_UI -DVOICE_CTRLS=$VOICE_CTRLS -I$SDK -I$SDKSRC -D__cdecl=" +CPPFLAGS=("-DFAUST_META=$FAUST_META" "-DFAUST_MIDICC=$FAUST_MIDICC" "-DFAUST_MTS=$FAUST_MTS" "-DFAUST_UI=$FAUST_UI" "-DVOICE_CTRLS=$VOICE_CTRLS" "-I$SDK" "-I$SDKSRC" "-D__cdecl=") if [ $NVOICES -ge 0 ]; then -CPPFLAGS="$CPPFLAGS -DNVOICES=$NVOICES" +CPPFLAGS+=("-DNVOICES=$NVOICES") fi # Extra SDK modules needed to build a working plugin. @@ -219,24 +209,28 @@ sdksrc="$SDKSRC/$main $SDKSRC/$afx $SDKSRC/$afxx" #OPTIONS="$OPTIONS -cn \"$clsname\"" # Create the temp directory. -mkdir -p $tmpdir +mkdir -p "$tmpdir" #trap "echo $0: compile error, intermediate files left in $tmpdir >&2" EXIT # Compile the Faust module. -faust -i -a "$FAUSTARCH/$arch" $OPTIONS "$dspname" -o "$tmpdir/$cppname" || exit 1 -if [ -n "$plugin_gui" ]; then +if [ "${#OPTIONS[@]}" ]; then + faust -i -a "$FAUSTARCH/$arch" "${OPTIONS[@]}" "$dspname" -o "$tmpdir/$cppname" || exit 1 +else + faust -i -a "$FAUSTARCH/$arch" "$dspname" -o "$tmpdir/$cppname" || exit 1 +fi +if [ -n "${plugin_gui:-}" ]; then # We have to use qmake here. # XXXTODO: OSX support ( cd "$tmpdir" - $QMAKE -project -t lib -o ${clsname}.pro "CONFIG += gui plugin no_plugin_name_prefix warn_off" "QT += widgets printsupport network $QTEXTRA" "INCLUDEPATH+=$ABSDIR" "INCLUDEPATH+=$CURDIR" "INCLUDEPATH+=$FAUSTARCH" "INCLUDEPATH+=$FAUSTINC" "QMAKE_CXXFLAGS=-std=c++11 $CPPFLAGS" $STYLE_CXXFLAGS "LIBS+=$ARCHLIB $OSCLIBS $HTTPLIBS" "SOURCES+=$SDKSRC/$main $SDKSRC/$afx $SDKSRC/$afxx" "HEADERS+=$FAUSTARCH/faustvstqt.h $FAUSTINC/faust/gui/QTUI.h" $RESOURCES "$OSCDEFS" "$HTTPDEFS" "$QRDEFS" - $QMAKE *.pro + $QMAKE -project -t lib -o "${clsname}.pro" "CONFIG += gui plugin no_plugin_name_prefix warn_off" "QT += widgets printsupport network x11extras" "INCLUDEPATH+=$ABSDIR" "INCLUDEPATH+=$CURDIR" "INCLUDEPATH+=$FAUSTARCH" "INCLUDEPATH+=$FAUSTINC" "QMAKE_CXXFLAGS=-std=c++11 ${CPPFLAGS[*]}" "$STYLE_CXXFLAGS" "LIBS+=$ARCHLIB $OSCLIBS $HTTPLIBS" "SOURCES+=$SDKSRC/$main $SDKSRC/$afx $SDKSRC/$afxx" "HEADERS+=$FAUSTARCH/faustvstqt.h $FAUSTINC/faust/gui/QTUI.h" "$RESOURCES" "$OSCDEFS" "$HTTPDEFS" "$QRDEFS" + $QMAKE ./*.pro make ) > /dev/null || exit 1 else -if [[ $(uname) == Darwin || $CROSSTARGET == Darwin ]]; then - mkdir -p $tmpdir/$soname/Contents/MacOS - printf '%s' 'BNDL????' > $tmpdir/$soname/Contents/PkgInfo - sed -e "s?@name@?$clsname?g;s?@version@?1.0.0?g" > $tmpdir/$soname/Contents/Info.plist < "$tmpdir/$soname/Contents/PkgInfo" + sed -e "s?@name@?$clsname?g;s?@version@?1.0.0?g" > "$tmpdir/$soname/Contents/Info.plist" < @@ -263,23 +257,31 @@ if [[ $(uname) == Darwin || $CROSSTARGET == Darwin ]]; then EOF - $CXX -bundle $CXXFLAGS $FAUSTTOOLSFLAGS $PROCARCH -I"$ABSDIR" $CPPFLAGS $sdksrc "$tmpdir/$cppname" -o "$tmpdir/$soname/Contents/MacOS/$clsname" || exit 1 + if [ -n "${FAUSTTOOLSFLAGS:-}" ]; then + $CXX -bundle "${CXXFLAGS[@]}" "${FAUSTTOOLSFLAGS:-}" "${PROCARCH[@]}" -I"$ABSDIR" "${CPPFLAGS[@]}" "$sdksrc" "$tmpdir/$cppname" -o "$tmpdir/$soname/Contents/MacOS/$clsname" || exit 1 + else + $CXX -bundle "${CXXFLAGS[@]}" "${PROCARCH[@]}" -I"$ABSDIR" "${CPPFLAGS[@]}" "$sdksrc" "$tmpdir/$cppname" -o "$tmpdir/$soname/Contents/MacOS/$clsname" || exit 1 + fi else - $CXX -shared $CXXFLAGS $FAUSTTOOLSFLAGS $PROCARCH -I"$ABSDIR" $CPPFLAGS $sdksrc "$tmpdir/$cppname" -o "$tmpdir/$soname" || exit 1 + if [ -n "${FAUSTTOOLSFLAGS:-}" ]; then + $CXX -shared "${CXXFLAGS[@]}" "${FAUSTTOOLSFLAGS:-}" "${PROCARCH[@]}" -I"$ABSDIR" "${CPPFLAGS[@]}" "$sdksrc" "$tmpdir/$cppname" -o "$tmpdir/$soname" || exit 1 + else + $CXX -shared "${CXXFLAGS[@]}" "${PROCARCH[@]}" -I"$ABSDIR" "${CPPFLAGS[@]}" "$sdksrc" "$tmpdir/$cppname" -o "$tmpdir/$soname" || exit 1 + fi fi fi #trap - EXIT # copy down the plugin (bundle on OS X) -rm -rf "$SRCDIR/$soname" +rm -rf "${SRCDIR:?}/$soname" cp -r "$tmpdir/$soname" "$SRCDIR" if [[ $KEEP == yes ]]; then # keep the build directory - rm -rf "$SRCDIR/$clsname" - mv $tmpdir "$SRCDIR/$clsname" + rm -rf "${SRCDIR:?}/$clsname" + mv "$tmpdir" "$SRCDIR/$clsname" else # Clean up. - rm -rf $tmpdir + rm -rf "$tmpdir" fi # Print the name of the generated plugin. echo "$SRCDIR/$soname;" diff --git a/tools/faust2appls/faust2jaqt b/tools/faust2appls/faust2jaqt index 60c3fdbd88..bc707b7bf1 100755 --- a/tools/faust2appls/faust2jaqt +++ b/tools/faust2appls/faust2jaqt @@ -1,4 +1,4 @@ -#! /bin/bash -e +#!/usr/bin/env bash ##################################################################### # # @@ -10,9 +10,11 @@ . faustpath . faustoptflags -CXXFLAGS=$MYGCCFLAGS +set -euo pipefail -ARCHFILE=$FAUSTARCH/jack-qt.cpp +CXXFLAGS=("$MYGCCFLAGS") + +ARCHFILE="$FAUSTARCH/jack-qt.cpp" if [[ $(uname -s) != Darwin ]]; then LFLAGS+="-no-pie" @@ -21,19 +23,25 @@ fi #------------------------------------------------------------------- # Set Faust include path -ARCHLIB="`pkg-config --cflags --libs jack`" +ARCHLIB="$(pkg-config --cflags --libs jack)" #------------------------------------------------------------------------------- -# Search for qmake or qmake-qt4 +# Search for qmake-qt5 or qmake -QMAKE=$(which qmake-qt5 || which qmake-qt4 || echo qmake) +QMAKE=$(command -v qmake-qt5 || command -v qmake) #PHASE 2 : dispatch command arguments OSCINC="" QTDEFS="" -OSCLIB="" +OSCLIBS="" +OSCDEFS="" +HTTPLIBS="" +HTTPDEFS="" POLY="POLY" +QRDEFS="" +POLYDEFS="" +MIDIDEFS="" DEPLOY="" NVOICES=-1 SOUNDFILE="0" @@ -41,12 +49,15 @@ SOUNDFILEDEFS="" SOUNDFILELIBS="" SAMPLERATEDEFS="" SAMPLERATELIBS="" +SPEC="" +FILES=() +OPTIONS=() -while [ $1 ] +while [ "${1:-}" ] do - p=$1 + p="${1:-}" - if [ $p = "-help" ] || [ $p = "-h" ]; then + if [ "$p" = "-help" ] || [ "$p" = "-h" ]; then echo "faust2jaqt [-httpd] [-qrcode] [-soundfile] [-resample] [-nvoices ] [-effect auto|] [-midi] [-osc] [additional Faust options (-vec -vs 8...)] " echo "Use '-httpd' to activate HTTP control" echo "Use '-qrcode' to activate QR code generation" @@ -70,30 +81,30 @@ do if [ "$p" = -icc ]; then ignore=" " - elif [ $p = "-deploy" ]; then + elif [ "$p" = "-deploy" ]; then DEPLOY="yes" - elif [ $p = "-nvoices" ]; then + elif [ "$p" = "-nvoices" ]; then POLYDEFS="DEFINES += POLY" shift NVOICES=$1 - if [ $NVOICES -ge 0 ]; then - CXXFLAGS="$CXXFLAGS -DNVOICES=$NVOICES" + if [ "$NVOICES" -ge 0 ]; then + CXXFLAGS+=("-DNVOICES=$NVOICES") fi - elif [ $p = "-effect" ]; then + elif [ "$p" = "-effect" ]; then POLYDEFS="DEFINES += POLY2" POLY="POLY2" shift EFFECT=$1 - elif [ $p = "-midi" ]; then + elif [ "$p" = "-midi" ]; then MIDIDEFS="DEFINES += MIDICTRL" - elif [ $p = "-soundfile" ]; then + elif [ "$p" = "-soundfile" ]; then SOUNDFILE="1" SOUNDFILEDEFS="DEFINES += SOUNDFILE" - SOUNDFILELIBS=`pkg-config --cflags --static --libs sndfile` - elif [ $p = "-resample" ]; then + SOUNDFILELIBS=$(pkg-config --cflags --static --libs sndfile) + elif [ "$p" = "-resample" ]; then SAMPLERATEDEFS="DEFINES += SAMPLERATE" - SAMPLERATELIBS=`pkg-config --cflags --static --libs samplerate` - elif [ $p = "-osc" ]; then + SAMPLERATELIBS=$(pkg-config --cflags --static --libs samplerate) + elif [ "$p" = "-osc" ]; then OSCDEFS="DEFINES += OSCCTRL" OSCLIBS="-lOSCFaust" elif [ "$p" = "-httpd" ]; then @@ -101,12 +112,12 @@ do HTTPLIBS="-lHTTPDFaust -lmicrohttpd" elif [ "$p" = "-qrcode" ]; then # requires -httpd QRDEFS="DEFINES += QRCODECTRL" - elif [ ${p:0:1} = "-" ]; then - OPTIONS="$OPTIONS $p" + elif [ "${p:0:1}" = "-" ]; then + OPTIONS+=("$p") elif [[ -f "$p" ]]; then - FILES="$FILES $p" + FILES+=("$p") else - OPTIONS="$OPTIONS $p" + OPTIONS+=("$p") fi shift @@ -120,11 +131,11 @@ if [[ $(uname) == Darwin ]]; then ARCHLIB+=" -framework CoreMIDI -framework CoreFoundation -framework CoreAudio" HTTPLIBS="-L/opt/local/lib $HTTPLIBS" SYS_VERSION=$(uname -v | cut -d : -f1 | cut -d. -f1 | cut -d' ' -f4) - if [ $SYS_VERSION -ge 13 ] + if [ "$SYS_VERSION" -ge 13 ] then SPEC="-spec macx-clang" - CLANGOPT="QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9" - CXXFLAGS="$CXXFLAGS -mmacosx-version-min=10.9" + CLANGOPT="QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9" + CXXFLAGS+=("-mmacosx-version-min=10.9") else SPEC="-spec macx-g++" CLANGOPT="" @@ -142,7 +153,7 @@ fi #------------------------------------------------------------------- # compile the *.dsp files # -for p in $FILES; do +for p in "${FILES[@]}"; do CUR=$(pwd) f=$(basename "$p") @@ -155,8 +166,8 @@ for p in $FILES; do # compile faust to c++ if [ $POLY = "POLY2" ]; then - if [ $EFFECT = "auto" ]; then - cat > $TMP/effect.dsp << EndOfCode + if [ "$EFFECT" = "auto" ]; then + cat > "$TMP/effect.dsp" << EndOfCode adapt(1,1) = _; adapt(2,2) = _,_; adapt(1,2) = _ <: _,_; @@ -164,29 +175,49 @@ for p in $FILES; do adaptor(F,G) = adapt(outputs(F),inputs(G)); process = adaptor(library("$SRCDIR/$f").process, library("$SRCDIR/$f").effect) : library("$SRCDIR/$f").effect; EndOfCode - faust -i -json -a $ARCHFILE $OPTIONS "$SRCDIR/$f" -o "$TMP/${f%.dsp}_tmp.cpp" || exit + if [ "${#OPTIONS[@]}" -gt 0 ]; then + faust -i -json -a "$ARCHFILE" "${OPTIONS[@]}" "$SRCDIR/$f" -o "$TMP/${f%.dsp}_tmp.cpp" || exit + else + faust -i -json -a "$ARCHFILE" "$SRCDIR/$f" -o "$TMP/${f%.dsp}_tmp.cpp" || exit + fi faust -i -cn effect -a minimal-effect.cpp "$TMP/effect.dsp" -o "$TMP/effect.h" || exit rm "$TMP/effect.dsp" else - faust -i -json -a $ARCHFILE $OPTIONS "$SRCDIR/$f" -o "$TMP/${f%.dsp}_tmp.cpp" || exit + if [ "${#OPTIONS[@]}" -gt 0 ]; then + faust -i -json -a "$ARCHFILE" "${OPTIONS[@]}" "$SRCDIR/$f" -o "$TMP/${f%.dsp}_tmp.cpp" || exit + else + faust -i -json -a "$ARCHFILE" "$SRCDIR/$f" -o "$TMP/${f%.dsp}_tmp.cpp" || exit + fi faust -i -cn effect -a minimal-effect.cpp "$SRCDIR/$EFFECT" -o "$TMP/effect.h" || exit fi else - faust -i -json -a $ARCHFILE $OPTIONS "$SRCDIR/$f" -o "$TMP/${f%.dsp}_tmp.cpp" || exit + if [ "${#OPTIONS[@]}" -gt 0 ]; then + faust -i -json -a "$ARCHFILE" "${OPTIONS[@]}" "$SRCDIR/$f" -o "$TMP/${f%.dsp}_tmp.cpp" || exit + else + faust -i -json -a "$ARCHFILE" "$SRCDIR/$f" -o "$TMP/${f%.dsp}_tmp.cpp" || exit + fi fi # compile c++ to binary ( cd "$TMP" - $QMAKE -project "QT += widgets printsupport network" "CONFIG+=warn_off" "$CLANGOPT" "INCLUDEPATH+=$CUR" "INCLUDEPATH+=$FAUSTINC /opt/local/include" "QMAKE_CXXFLAGS=$CXXFLAGS -Wno-unused-parameter $FAUSTTOOLSFLAGS" "QMAKE_LFLAGS=$LFLAGS" "LIBS+=$ARCHLIB $SOUNDFILELIBS $SAMPLERATELIBS $OSCLIBS $HTTPLIBS" "HEADERS+=$FAUSTINC/faust/gui/QTUI.h" "RESOURCES+= $FAUSTINC/faust/gui/Styles/Grey.qrc" "$OSCDEFS" "$HTTPDEFS" "$QRDEFS" "$POLYDEFS" "$MIDIDEFS" "$SOUNDFILEDEFS" "$SAMPLERATEDEFS" - $QMAKE $SPEC QMAKE_CFLAGS_ISYSTEM=-I - make + if [ -n "${FAUSTTOOLSFLAGS:-}" ]; then + "$QMAKE" -project "QT += widgets printsupport network" "CONFIG+=warn_off" "${CLANGOPT:-}" "INCLUDEPATH+=$CUR" "INCLUDEPATH+=$FAUSTINC /opt/local/include" "QMAKE_CXXFLAGS=${CXXFLAGS[*]} -Wno-unused-parameter ${FAUSTTOOLSFLAGS:-}" "QMAKE_LFLAGS=$LFLAGS" "LIBS+=$ARCHLIB $SOUNDFILELIBS $SAMPLERATELIBS $OSCLIBS $HTTPLIBS" "HEADERS+=$FAUSTINC/faust/gui/QTUI.h" "RESOURCES+= $FAUSTINC/faust/gui/Styles/Grey.qrc" "$OSCDEFS" "$HTTPDEFS" "$QRDEFS" "$POLYDEFS" "$MIDIDEFS" "$SOUNDFILEDEFS" "$SAMPLERATEDEFS" + else + "$QMAKE" -project "QT += widgets printsupport network" "CONFIG+=warn_off" "${CLANGOPT:-}" "INCLUDEPATH+=$CUR" "INCLUDEPATH+=$FAUSTINC /opt/local/include" "QMAKE_CXXFLAGS=${CXXFLAGS[*]} -Wno-unused-parameter" "QMAKE_LFLAGS=$LFLAGS" "LIBS+=$ARCHLIB $SOUNDFILELIBS $SAMPLERATELIBS $OSCLIBS $HTTPLIBS" "HEADERS+=$FAUSTINC/faust/gui/QTUI.h" "RESOURCES+= $FAUSTINC/faust/gui/Styles/Grey.qrc" "$OSCDEFS" "$HTTPDEFS" "$QRDEFS" "$POLYDEFS" "$MIDIDEFS" "$SOUNDFILEDEFS" "$SAMPLERATEDEFS" + fi + if [ -n "$SPEC" ]; then + "$QMAKE" "$SPEC" QMAKE_CFLAGS_ISYSTEM=-I + else + "$QMAKE" QMAKE_CFLAGS_ISYSTEM=-I + fi + make ) > /dev/null || exit if [[ $(uname) == Darwin ]]; then if [ "$SOUNDFILE" = "1" ]; then # get all soundfiles from the JSON file - cat $p.json | awk ' + cat "$p.json" | awk ' BEGIN { FS=":"; SOFI=0; } /"soundfile"/ { SOFI=1; } /"url"/ { @@ -197,27 +228,27 @@ EndOfCode SOFI=0; } } - ' > $p-tmp.txt + ' > "$p-tmp.txt" # copy found soundfiles in the final binary - for snd in $(cat $p-tmp.txt); do - if [ -f $snd ]; then - if [ ${snd:0:1} = "/" ]; then + for snd in $(cat "$p-tmp.txt"); 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 + sfpath="$TMP/${f%.dsp}$EXT/Contents/Resources/$(dirname "$snd")/" + if ! [ -d "$sfpath" ]; then echo "Create $sfpath" - mkdir $sfpath + mkdir "$sfpath" fi echo "Copy $snd in ${f%.dsp}$EXT" - cp $snd $sfpath + cp "$snd" "$sfpath" fi else echo "Error: file $snd not found !" fi done - rm $p-tmp.txt + rm "$p-tmp.txt" fi fi @@ -229,15 +260,15 @@ EndOfCode fi #remove tempory files - rm -rf "$SRCDIR/${f%.dsp}$EXT" + rm -rf "${SRCDIR:?}/${f%.dsp}$EXT" cp -r "$TMP/${f%.dsp}$EXT" "$SRCDIR/${f%.dsp}$EXT" rm -rf "$TDR" - rm -f $p.json + rm -f "$p.json" # collect binary file name for FaustGIDE BINARIES="$BINARIES$SRCDIR/${f%.dsp}$EXT;" done -echo $BINARIES +echo "$BINARIES" diff --git a/tools/faust2appls/faust2lv2 b/tools/faust2appls/faust2lv2 index 1c540d159d..ace2b4aa72 100755 --- a/tools/faust2appls/faust2lv2 +++ b/tools/faust2appls/faust2lv2 @@ -1,18 +1,16 @@ -#! /bin/bash +#!/usr/bin/env bash -#set -x +set -eou pipefail - -# Default qmake setup (for GUI compilation). This requires Qt4 or Qt5 (Qt5 is -# preferred). We try to locate the qmake executable in some common locations -# here. If this doesn't work out then you can also set the QMAKE environment -# variable explicitly, or use one of the -qt4 and -qt5 options below. -[ -z "$QMAKE" ] && QMAKE=$(which qmake-qt5 || which /opt/local/libexec/qt5/bin/qmake || which qmake-qt4 || which /opt/local/libexec/qt4/bin/qmake || echo qmake) +# Default qmake setup (for GUI compilation). This requires Qt5. If qmake-qt5 or +# qmake can not be located in PATH, you can also set the QMAKE environment +# variable explicitly, or use the -qt5 option below. +[ -z "${QMAKE:-}" ] && QMAKE=$(command -v qmake-qt5 || command -v qmake) # Where the Faust includes live. We assume that this is under the prefix of # whatever Faust binary 'which' locates. You can also specify this explicitly # by setting the FAUSTINC environment variable accordingly. -[ -z "$FAUSTINC" ] && FAUSTINC=$(which faust 2>/dev/null | sed -e 's?/bin/faust?/include/faust?') +[ -z "${FAUSTINC:-}" ] && FAUSTINC=$(command -v faust 2>/dev/null | sed -e 's?/bin/faust?/include/faust?') # Where our own Faust library files are. This may be under a different prefix # or not installed anywhere. We try 'ls' on lv2ui.cpp in some common locations @@ -20,8 +18,8 @@ # that you can run the script from the faust-lv2 source directory. You can # also specify this explicitly by setting the FAUSTLIB environment variable # accordingly. -[ -z "$FAUSTLIB" ] && FAUSTLIB=$(dirname "$((ls -f /usr/share/faust/lv2ui.cpp /usr/local/share/faust/lv2ui.cpp /opt/local/share/faust/lv2ui.cpp "$PWD/lv2ui.cpp" 2>/dev/null)|tail -1)") -[ -z "$FAUSTLIB" ] && FAUSTLIB="$PWD" +[ -z "${FAUSTLIB:-}" ] && FAUSTLIB="$(dirname "$((ls -f /usr/share/faust/lv2ui.cpp /usr/local/share/faust/lv2ui.cpp /opt/local/share/faust/lv2ui.cpp "$PWD/lv2ui.cpp" 2>/dev/null) | tail -1)")" +[ -z "${FAUSTLIB:-}" ] && FAUSTLIB="$PWD" # defaults (these can be changed with the options listed below) URI_PREFIX=https://faustlv2.bitbucket.io @@ -35,9 +33,12 @@ NVOICES=-1 KEEP="no" STYLE="" +FILES=( ) +OPTIONS=( ) + PROCARCH="-fPIC" dllext=".so" -CXXFLAGS="-O3 -std=c++11 -mfpmath=sse -msse -msse2 -msse3 -ffast-math -ftree-vectorize" +CXXFLAGS=("-O3" "-std=c++11" "-mfpmath=sse" "-msse" "-msse2" "-msse3" "-ffast-math" "-ftree-vectorize") # Darwin specifics if [[ $(uname) == Darwin ]]; then @@ -79,7 +80,7 @@ EOF : ignore elif [ $p = "-icc" ]; then CXX=icpc - CXXFLAGS="-O3 -xHost -ftz -fno-alias -fp-model fast=2" + CXXFLAGS=("-O3" "-xHost" "-ftz" "-fno-alias" "-fp-model" "fast=2") elif [ $p = "-osc" ]; then OSCDEFS="DEFINES += OSCCTRL" OSCLIBS="-lOSCFaust" @@ -99,14 +100,10 @@ EOF elif [ $p = "-gui" ]; then FAUST_UI=1 plugin_gui=yes - elif [ $p = "-qt4" ]; then - FAUST_UI=1 - plugin_gui=yes - QMAKE=$(which qmake-qt4 || which /opt/local/libexec/qt4/bin/qmake || echo qmake-qt4) elif [ $p = "-qt5" ]; then FAUST_UI=1 plugin_gui=yes - QMAKE=$(which qmake-qt5 || which /opt/local/libexec/qt5/bin/qmake || echo qmake-qt5) + QMAKE=$(command -v qmake-qt5 || command -v qmake) elif [ $p = "-dyn-manifest" ]; then dyn_manifest=yes elif [ $p = "-uri-prefix" ]; then @@ -120,7 +117,7 @@ EOF elif [ $p = "-arch64" ]; then PROCARCH="-m64 -fPIC" elif [ $p = "-osx" ]; then - CXXFLAGS="-O3 -march=native -mfpmath=sse -msse -msse2 -msse3 -ffast-math -ftree-vectorize -I/opt/local/include" + CXXFLAGS=("-O3" "-march=native" "-mfpmath=sse" "-msse" "-msse2" "-msse3" "-ffast-math" "-ftree-vectorize" "-I/opt/local/include") dllext=".dylib" elif [ $p = "-keep" ]; then KEEP="yes" @@ -128,15 +125,14 @@ EOF (( i++ )) STYLE=${!i} elif [ ${p:0:1} = "-" ]; then - OPTIONS="$OPTIONS $p" + OPTIONS+=("$p") elif [[ -f "$p" ]]; then - FILES="$FILES $p" + FILES+=("$p") else - OPTIONS="$OPTIONS $p" + OPTIONS+=("$p") fi done -FILES=( $FILES ) if [ ${#FILES[@]} = 0 ]; then echo "$0: no filename specified" >&2 exit 1 @@ -150,24 +146,21 @@ fi if [ ! -f "$FAUSTINC/gui/QTUI.h" ]; then echo "$0: faust include files not found" >&2; exit 1; fi if [ ! -f "$FAUSTLIB/lv2ui.cpp" ]; then echo "$0: faust-lv2 library files not found" >&2; exit 1; fi -# Determine the Qt version so that we can edit the manifests accordingly. -QTVERSION=$($QMAKE -v 2>/dev/null | tail -1 | sed 's/.*Qt version \([0-9]\).*/\1/') - arch=lv2.cpp archui=lv2ui.cpp -dspname=${FILES[0]} +dspname="${FILES[0]}" SRCDIR=$(dirname "$dspname") -ABSDIR=$(cd $SRCDIR && pwd) +ABSDIR=$(cd "$SRCDIR" && pwd) CURDIR=$(pwd) -clsname=`basename "$dspname" .dsp` +clsname=$(basename "$dspname" .dsp) cppname="$clsname.cpp" soname="$clsname$dllext" uicppname="${clsname}ui.cpp" uisoname="${clsname}ui$dllext" lv2name="$clsname.lv2" -tmpdir=`mktemp -d /tmp/faust2lv2.XXXXXX` -uitmpdir=$tmpdir/${clsname}ui.src +tmpdir=$(mktemp -d /tmp/faust2lv2.XXXXXX) +uitmpdir="$tmpdir/${clsname}ui.src" RESOURCES= STYLE_CXXFLAGS= @@ -176,36 +169,50 @@ if [ -n "$STYLE" ]; then STYLE_CXXFLAGS="QMAKE_CXXFLAGS+=-DSTYLE=\"$STYLE\"" fi -CXX=g++ -CPPFLAGS="-DPLUGIN_URI=\"$URI_PREFIX/$clsname\" -DFAUST_META=$FAUST_META -DFAUST_MIDICC=$FAUST_MIDICC -DFAUST_MTS=$FAUST_MTS -DFAUST_UI=$FAUST_UI -DVOICE_CTRLS=$VOICE_CTRLS" +CXX=$(command -v g++) +CPPFLAGS=("-DPLUGIN_URI=\"$URI_PREFIX/$clsname\"" "-DFAUST_META=$FAUST_META" "-DFAUST_MIDICC=$FAUST_MIDICC" "-DFAUST_MTS=$FAUST_MTS" "-DFAUST_UI=$FAUST_UI" "-DVOICE_CTRLS=$VOICE_CTRLS") if [ $NVOICES -ge 0 ]; then -CPPFLAGS="$CPPFLAGS -DNVOICES=$NVOICES" + CPPFLAGS+=("-DNVOICES=$NVOICES") fi # Create the temp directory and the bundle directory inside it. -mkdir -p $tmpdir/$lv2name +mkdir -p "$tmpdir/$lv2name" #trap "echo $0: compile error, intermediate files left in $tmpdir >&2" EXIT # Compile the Faust module. -faust -i -a "$FAUSTLIB/$arch" -cn "$clsname" $OPTIONS "$dspname" -o "$tmpdir/$cppname" || exit 1 -$CXX -shared $CXXFLAGS -DDLLEXT="\"$dllext\"" $FAUSTTOOLSFLAGS $PROCARCH -I"$ABSDIR" $CPPFLAGS "$tmpdir/$cppname" -o "$tmpdir/$lv2name/$soname" || exit 1 -if [ -n "$plugin_gui" ]; then +if [ "${#OPTIONS[@]}" -gt 0 ]; then + faust -i -a "$FAUSTLIB/$arch" -cn "$clsname" "${OPTIONS[@]}" "$dspname" -o "$tmpdir/$cppname" || exit 1 +else + faust -i -a "$FAUSTLIB/$arch" -cn "$clsname" "$dspname" -o "$tmpdir/$cppname" || exit 1 +fi + +if [ -n "${FAUSTTOOLSFLAGS:-}" ]; then + "$CXX" -shared "${CXXFLAGS[@]}" -DDLLEXT="\"$dllext\"" "${FAUSTTOOLSFLAGS:-}" "$PROCARCH" -I"$ABSDIR" "${CPPFLAGS[@]}" "$tmpdir/$cppname" -o "$tmpdir/$lv2name/$soname" || exit 1 +else + "$CXX" -shared "${CXXFLAGS[@]}" -DDLLEXT="\"$dllext\"" "$PROCARCH" -I"$ABSDIR" "${CPPFLAGS[@]}" "$tmpdir/$cppname" -o "$tmpdir/$lv2name/$soname" || exit 1 +fi + +if [ -n "${plugin_gui:-}" ]; then # Compile the UI module. -mkdir -p $uitmpdir -faust -i -a "$FAUSTLIB/$archui" -cn "$clsname" $OPTIONS "$dspname" -o "$uitmpdir/$uicppname" || exit 1 -( - cd $uitmpdir - $QMAKE -project -t lib -o ${clsname}ui.pro "CONFIG += gui plugin no_plugin_name_prefix warn_off" "QT += widgets printsupport network" "INCLUDEPATH+=$ABSDIR" "INCLUDEPATH+=$CURDIR" "INCLUDEPATH+=$FAUSTLIB" "INCLUDEPATH+=$FAUSTINC" "QMAKE_CXXFLAGS=-std=c++11 $(echo $CPPFLAGS|sed -e 's/"/\\\\\\"/g')" $STYLE_CXXFLAGS "LIBS+=$ARCHLIB $OSCLIBS $HTTPLIBS" "HEADERS+=$FAUSTLIB/lv2qtgui.h $FAUSTINC/gui/QTUI.h" $RESOURCES "$OSCDEFS" "$HTTPDEFS" "$QRDEFS" - $QMAKE *.pro - make || exit 1 - mv $uisoname "$tmpdir/$lv2name" -) > /dev/null || exit 1 +mkdir -p "$uitmpdir" + if [ "${#OPTIONS[@]}" -gt 0 ]; then + faust -i -a "$FAUSTLIB/$archui" -cn "$clsname" "${OPTIONS[@]}" "$dspname" -o "$uitmpdir/$uicppname" || exit 1 + else + faust -i -a "$FAUSTLIB/$archui" -cn "$clsname" "$dspname" -o "$uitmpdir/$uicppname" || exit 1 + fi + ( + cd "$uitmpdir" + "$QMAKE" -project -t lib -o "${clsname}ui.pro" "CONFIG += gui plugin no_plugin_name_prefix warn_off" "QT += widgets printsupport network" "INCLUDEPATH+=$ABSDIR" "INCLUDEPATH+=$CURDIR" "INCLUDEPATH+=$FAUSTLIB" "INCLUDEPATH+=$FAUSTINC" "QMAKE_CXXFLAGS=-std=c++11 $(echo "${CPPFLAGS[@]}"|sed -e 's/"/\\\\\\"/g')" "$STYLE_CXXFLAGS" "LIBS+=$ARCHLIB $OSCLIBS $HTTPLIBS" "HEADERS+=$FAUSTLIB/lv2qtgui.h $FAUSTINC/gui/QTUI.h" "$RESOURCES" "$OSCDEFS" "$HTTPDEFS" "$QRDEFS" + "$QMAKE" ./*.pro + make || exit 1 + mv "$uisoname" "$tmpdir/$lv2name" + ) > /dev/null || exit 1 fi # Generate the manifest. There are four different variations of the manifest, # depending on whether dynamic manifests and the plugin gui is enabled or not. -if [ -n "$dyn_manifest" ]; then +if [ -n "${dyn_manifest:-}" ]; then # Use a dynamic manifest. -if [ -n "$plugin_gui" ]; then -sed -e"s?@name@?$clsname?g" -e"s?@uri@?$URI_PREFIX/$clsname?g" -e"s?@dllext@?$dllext?g" -e "s?ui:Qt5UI?ui:Qt${QTVERSION}UI?g" > "$tmpdir/$lv2name/manifest.ttl" < "$tmpdir/$lv2name/manifest.ttl" < "$tmpdir/$lv2name/manifest.ttl" < "$tmpdir/$lv2name/manifest.ttl" < "$tmpdir/$lv2name/$clsname.ttl" rm -f "$tmpdir/$clsname" fi #trap - EXIT # copy down the bundle -rm -rf "$SRCDIR/$lv2name" +rm -rf "${SRCDIR:?}/$lv2name" cp -r "$tmpdir/$lv2name" "$SRCDIR" if [[ $KEEP == yes ]]; then # keep the build directory - rm -rf "$SRCDIR/$clsname" - mv $tmpdir "$SRCDIR/$clsname" + rm -rf "${SRCDIR:?}/$clsname" + mv "$tmpdir" "$SRCDIR/$clsname" else # Clean up. - rm -rf $tmpdir + rm -rf "$tmpdir" fi # Print the name of the generated bundle zip file. echo "$SRCDIR/$lv2name;"