Skip to content

Commit

Permalink
tools/faust2appls/faust2lv2: Adding -eou pipefail bash options to hav…
Browse files Browse the repository at this point in the history
…e stricter handling of return codes and potentially undefined variables. Guarding all potentially undefined variables. Removing debug echo for dspname.
  • Loading branch information
dvzrv committed Sep 28, 2019
1 parent 649b02f commit 49a6db9
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions tools/faust2appls/faust2lv2
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#!/usr/bin/env bash

#set -x
set -eou pipefail

# 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)
[ -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=$(command -v 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
# here, and fall back to the current directory if the file isn't found, so
# 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
Expand Down Expand Up @@ -149,7 +149,6 @@ if [ ! -f "$FAUSTLIB/lv2ui.cpp" ]; then echo "$0: faust-lv2 library files not fo
arch=lv2.cpp
archui=lv2ui.cpp
dspname="${FILES[0]}"
echo "dspname: $dspname"
SRCDIR=$(dirname "$dspname")
ABSDIR=$(cd "$SRCDIR" && pwd)
CURDIR=$(pwd)
Expand Down Expand Up @@ -186,13 +185,13 @@ 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
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
if [ -n "${plugin_gui:-}" ]; then
# Compile the UI module.
mkdir -p "$uitmpdir"
if [ "${#OPTIONS[@]}" -gt 0 ]; then
Expand All @@ -210,9 +209,9 @@ mkdir -p "$uitmpdir"
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
if [ -n "${plugin_gui:-}" ]; then
sed -e"s?@name@?$clsname?g" -e"s?@uri@?$URI_PREFIX/$clsname?g" -e"s?@dllext@?$dllext?g" > "$tmpdir/$lv2name/manifest.ttl" <<EOF
########## @uri@ ##########
Expand Down Expand Up @@ -288,7 +287,7 @@ EOF
fi
else
# Use a static manifest.
if [ -n "$plugin_gui" ]; then
if [ -n "${plugin_gui:-}" ]; then
sed -e"s?@name@?$clsname?g" -e"s?@uri@?$URI_PREFIX/$clsname?g" -e"s?@dllext@?$dllext?g" > "$tmpdir/$lv2name/manifest.ttl" <<EOF
########## @uri@ ##########
Expand Down Expand Up @@ -366,8 +365,8 @@ EOF
fi
# This compiles the plugin to an executable which is run to generate the
# plugin-specific part of the manifest.
if [ -n "$FAUSTTOOLSFLAGS" ]; then
"$CXX" "${CXXFLAGS[@]}" -DDLLEXT="\"$dllext\"" "$FAUSTTOOLSFLAGS" -I"$ABSDIR" "${CPPFLAGS[@]}" "$tmpdir/$cppname" -o "$tmpdir/$clsname" || exit 1
if [ -n "${FAUSTTOOLSFLAGS:-}" ]; then
"$CXX" "${CXXFLAGS[@]}" -DDLLEXT="\"$dllext\"" "${FAUSTTOOLSFLAGS:-}" -I"$ABSDIR" "${CPPFLAGS[@]}" "$tmpdir/$cppname" -o "$tmpdir/$clsname" || exit 1
else
"$CXX" "${CXXFLAGS[@]}" -DDLLEXT="\"$dllext\"" -I"$ABSDIR" "${CPPFLAGS[@]}" "$tmpdir/$cppname" -o "$tmpdir/$clsname" || exit 1
fi
Expand Down

0 comments on commit 49a6db9

Please sign in to comment.