diff --git a/scripts/setup.sh b/scripts/setup.sh index 1a4b8bc..656bd96 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -240,38 +240,30 @@ fi echo "Downloading and building ofxPiMapper Addon..." cd "$REAL_HOME/openFrameworks/addons" -[ ! -d "ofxPiMapper" ] && sudo -u "$REAL_USER" git clone --depth 1 https://github.com/kr15h/ofxPiMapper.git +# FORCE CLEAN CLONE to fix corrupted source files from previous failed runs +rm -rf ofxPiMapper +sudo -u "$REAL_USER" git clone --depth 1 https://github.com/kr15h/ofxPiMapper.git # Apply patches to the addon before building cd "$REAL_HOME/openFrameworks/addons/ofxPiMapper" -echo "Performing surgical cleanup and applying clean Global Compatibility Patches..." +echo "Applying clean Global Compatibility Patches..." -# SURGICAL SCRUB: Remove EXACT lines injected previously without breaking braces -find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i '/#include "cpp11_compat.h"/d' {} + -find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i '/template/d' {} + -find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i '/unique_ptr make_unique(Args&&... args)/d' {} + -find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i '/return unique_ptr(new T(std::forward(args)...));/d' {} + -find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i '/#if __cplusplus < 201402L/,/#endif/d' {} + - -# 1. Fix highlight patch (Heredoc fix) -if [ -f src/Osc/OscControl.cpp ] && ! grep -q "ofxPiMapper/surface/highlight" src/Osc/OscControl.cpp; then - cat <<'EOF_PATCH' > /tmp/highlight.patch +# 1. Fix highlight patch +cat <<'EOF_PATCH' > /tmp/highlight.patch if (m.getAddress() == "/ofxPiMapper/surface/highlight"){ int surfaceIndex = m.getArgAsInt32(0); mapper->getSurfaceManager()->selectSurface(surfaceIndex); return; } EOF_PATCH - sed -i '/if (m.getAddress() == "\/ofxPiMapper\/surface\/select"){/r /tmp/highlight.patch' src/Osc/OscControl.cpp - rm -f /tmp/highlight.patch -fi +sed -i '/if (m.getAddress() == "\/ofxPiMapper\/surface\/select"){/r /tmp/highlight.patch' src/Osc/OscControl.cpp +rm -f /tmp/highlight.patch -# 2. Fix unique_ptr and missing memory headers globally (Idempotent) -echo "Fixing namespaces and missing headers..." -find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/std::std::/std::/g' {} + +# 2. Fix unique_ptr and make_unique globally (Only if std:: is missing) find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/\([^:a-zA-Z0-9]\)unique_ptr\b/\1std::unique_ptr/g' {} + +find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/\([^:a-zA-Z0-9]\)make_unique\b/\1std::make_unique/g' {} + -# Create a single compatibility header +# 3. Create a single compatibility header for C++11 cat <<'EOF_COMPAT' > src/cpp11_compat.h #ifndef OFXPIMAPPER_CPP11_COMPAT_H #define OFXPIMAPPER_CPP11_COMPAT_H @@ -288,17 +280,12 @@ namespace std { #endif EOF_COMPAT -# Include the compat header in the main addon header ONLY (Top of file) -if ! grep -q "cpp11_compat.h" src/ofxPiMapper.h; then - sed -i '1i #include "cpp11_compat.h"' src/ofxPiMapper.h -fi +# 4. Include the compat header in the main addon header +sed -i '1i #include "cpp11_compat.h"' src/ofxPiMapper.h -# Also ensure unique_ptr and make_unique are namespaced in the source -find src -type f \( -name "*.h" -o -name "*.cpp" \) -exec sed -i 's/\([^:a-zA-Z0-9]\)make_unique\b/\1std::make_unique/g' {} + - -# Add memory header to all headers only if missing -for f in $(find src -type f -name "*.h"); do - grep -q "" "$f" || sed -i '1i #include ' "$f" +# 5. Add memory header to all headers where unique_ptr is used +for f in $(grep -l "unique_ptr" src/*.h 2>/dev/null); do + sed -i '1i #include ' "$f" done # Build Example @@ -306,8 +293,7 @@ cd "$REAL_HOME/openFrameworks/addons/ofxPiMapper/example_basic" echo "Cleaning old objects..." sudo -u "$REAL_USER" make clean -echo "Starting compilation (Global Flags)..." -# Using PLATFORM_CFLAGS ensures these flags propagate to the addon source as well +echo "Starting compilation (Forcing C++11 for Symbol Compatibility)..." GLOBAL_FLAGS="-Wno-error -Wno-reorder -Wno-sign-compare -Wno-delete-non-virtual-dtor -std=c++11" sudo -u "$REAL_USER" make -j1 PLATFORM_CFLAGS="$GLOBAL_FLAGS" USER_CFLAGS="$GLOBAL_FLAGS" USER_CPPFLAGS="-std=c++11" cp bin/example_basic /usr/local/bin/ofxPiMapper