From 76f4dd34e0ea87dc1cb403a4d7880c82ecc6fe21 Mon Sep 17 00:00:00 2001
From: Victor Oliveira <rhapsodyv@gmail.com>
Date: Sat, 31 Oct 2020 19:14:10 -0300
Subject: [PATCH] Put PIO "debug" build in the corner (#19975)

---
 buildroot/share/PlatformIO/scripts/common-cxxflags.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/buildroot/share/PlatformIO/scripts/common-cxxflags.py b/buildroot/share/PlatformIO/scripts/common-cxxflags.py
index 3e75434ee78..ee2afb1d26e 100644
--- a/buildroot/share/PlatformIO/scripts/common-cxxflags.py
+++ b/buildroot/share/PlatformIO/scripts/common-cxxflags.py
@@ -10,3 +10,13 @@ env.Append(CXXFLAGS=[
   #"-Wno-maybe-uninitialized",
   #"-Wno-sign-compare"
 ])
+
+# Useful for JTAG debugging
+#
+# It will separe release and debug build folders. 
+# It useful when we need keep two live versions: one debug, for debugging, 
+# other release, for flashing.
+# Without this, PIO will recompile everything twice for any small change.
+# 
+if env.GetBuildType() == "debug":
+	env['BUILD_DIR'] = '$PROJECT_BUILD_DIR/$PIOENV/debug'