From f4c625d3a16be2c23e082c84714660ec969c8e01 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Mon, 1 Oct 2018 04:54:00 -0500
Subject: [PATCH] Ensure MIN/MAX overrides

---
 Marlin/src/core/minmax.h                     | 29 +++++++++++---------
 Marlin/src/inc/MarlinConfig.h                |  1 +
 frameworks/CMSIS/LPC1768/include/lpc_types.h |  2 --
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/Marlin/src/core/minmax.h b/Marlin/src/core/minmax.h
index 126a738b95..e45544ff69 100644
--- a/Marlin/src/core/minmax.h
+++ b/Marlin/src/core/minmax.h
@@ -20,26 +20,29 @@
  *
  */
 
-#pragma once
-
 #undef MIN
 #undef MAX
 
 #ifdef __cplusplus
 
-  extern "C++" {
+  #ifndef _MINMAX_H_
+  #define _MINMAX_H_
 
-    // C++11 solution that is standards compliant. Return type is deduced automatically
-    template <class L, class R> static inline constexpr auto MIN(const L lhs, const R rhs) -> decltype(lhs + rhs) {
-      return lhs < rhs ? lhs : rhs;
-    }
-    template <class L, class R> static inline constexpr auto MAX(const L lhs, const R rhs) -> decltype(lhs + rhs) {
-      return lhs > rhs ? lhs : rhs;
-    }
-    template<class T, class ... Ts> static inline constexpr const T MIN(T V, Ts... Vs) { return MIN(V, MIN(Vs...)); }
-    template<class T, class ... Ts> static inline constexpr const T MAX(T V, Ts... Vs) { return MAX(V, MAX(Vs...)); }
+    extern "C++" {
 
-  }
+      // C++11 solution that is standards compliant. Return type is deduced automatically
+      template <class L, class R> static inline constexpr auto MIN(const L lhs, const R rhs) -> decltype(lhs + rhs) {
+        return lhs < rhs ? lhs : rhs;
+      }
+      template <class L, class R> static inline constexpr auto MAX(const L lhs, const R rhs) -> decltype(lhs + rhs) {
+        return lhs > rhs ? lhs : rhs;
+      }
+      template<class T, class ... Ts> static inline constexpr const T MIN(T V, Ts... Vs) { return MIN(V, MIN(Vs...)); }
+      template<class T, class ... Ts> static inline constexpr const T MAX(T V, Ts... Vs) { return MAX(V, MAX(Vs...)); }
+
+    }
+
+  #endif
 
 #else
 
diff --git a/Marlin/src/inc/MarlinConfig.h b/Marlin/src/inc/MarlinConfig.h
index 539726e405..a6d48a18e5 100644
--- a/Marlin/src/inc/MarlinConfig.h
+++ b/Marlin/src/inc/MarlinConfig.h
@@ -43,5 +43,6 @@
 #include "../core/language.h"
 #include "../core/utility.h"
 #include "../core/serial.h"
+#include "../core/minmax.h"
 
 #endif // _MARLIN_CONFIG_H_
diff --git a/frameworks/CMSIS/LPC1768/include/lpc_types.h b/frameworks/CMSIS/LPC1768/include/lpc_types.h
index 022b88feeb..516e0114f7 100644
--- a/frameworks/CMSIS/LPC1768/include/lpc_types.h
+++ b/frameworks/CMSIS/LPC1768/include/lpc_types.h
@@ -145,8 +145,6 @@ typedef int32_t(*PFI)();
 /* External data/function define */
 #define EXTERN extern
 
-#include "../../../../src/core/minmax.h"
-
 /**
  * @}
  */