From 513ccbc2a582b0de17813ea839ae30d06de23049 Mon Sep 17 00:00:00 2001
From: EmbeddedMan <brian@schmalzhaus.com>
Date: Mon, 10 Apr 2023 13:04:01 -0500
Subject: [PATCH] Added Windows speciffic lines to all example Makefiles (that
 didn't already have it) so they get the rigiht copy of libgcc.a. All examples
 now compile out of the box on Windows.

---
 examples/adc_polled/Makefile       |   9 ++++++++-
 examples/blink/blink.bin           | Bin 548 -> 520 bytes
 examples/debugprintfdemo/Makefile  |   9 ++++++++-
 examples/i2c_oled/Makefile         |   9 ++++++++-
 examples/sandbox/Makefile          |   9 ++++++++-
 examples/self_modify_code/Makefile |   9 ++++++++-
 examples/systick_irq/Makefile      |   9 ++++++++-
 examples/tim1_pwm/Makefile         |   9 ++++++++-
 examples/uartdemo/Makefile         |   9 ++++++++-
 examples/ws2812bdemo/Makefile      |   9 ++++++++-
 10 files changed, 72 insertions(+), 9 deletions(-)

diff --git a/examples/adc_polled/Makefile b/examples/adc_polled/Makefile
index a460104..d2635f6 100644
--- a/examples/adc_polled/Makefile
+++ b/examples/adc_polled/Makefile
@@ -9,9 +9,16 @@ GPIO_Toggle:=EXAM/GPIO/GPIO_Toggle/User
 CH32V003FUN:=../../ch32v003fun
 MINICHLINK:=../../minichlink
 
+ifeq ($(OS),Windows_NT)
+# On Windows, all the major RISC-V GCC installs are missing the -ec libgcc.
+LIB_GCC=../../misc/libgcc.a
+else
+LIB_GCC=-lgcc
+endif
+
 CFLAGS:= \
 	-g -Os -flto -ffunction-sections \
-	-static-libgcc -lgcc \
+	-static-libgcc $(LIB_GCC) \
 	-march=rv32ec \
 	-mabi=ilp32e \
 	-I/usr/include/newlib \
diff --git a/examples/blink/blink.bin b/examples/blink/blink.bin
index b0cf5a4fa20b888e4185c78fd1a5230786bc2059..f4a7fa56e5eb064927ec95f85687b82ff2dc8db8 100755
GIT binary patch
literal 520
zcmb`Au}i~16vkg_FW14LC8bda5-ixYf_S4TN7GGlsFPc<9UX#$gHV;AP^y(Hc-X-z
zf`38Ds4<F#4&r3Ds#QA|EN;~cA~-qu!M*S9-tT*F74&fs3I@K9fB#E9=j*rsWdGa!
zJ<bO_w&{AU?U7y#6pUwiD}IK7Q>CB+_u3Sd);e4e+}kQHM&#?stEo#z4HyK26hFlx
zqlUO=n<No1q8`D=z;7KH0z@zx9qbP}%k;$T*H|wB%buTX)9F%o;$g@ah}{3&h$#g;
z!taPG84P2iN}V9+?orjNQuY=D-}`%hP37-}Yt*f2qOzU}nn$93DrlrLyoEAjO*H3-
zIRr<5?O=nq+=AAep4&bTf{o+#cW^HbCD7UCQ(oDWKtT|)!YElbt%_Mx5s07kYqo5K
zvq|yN6}0lg>{L-Qb4v{fyAjl#ZwwVw)DK0M+4i$43rd!sbGtVXO;rVPfVxLFLxvwm
Nt%^Ehfu5A=0AD^kf%gCa

literal 548
zcmd02cp%9D1hW_+7{ta0K<YpMnTF}5HVv|8`*(&1H=HYH-#BdkT#P}Oo!xB4Y2_vC
z3^SaC)5RHP9KPYq+Fg2o22jO}!%Yo=f^0{W4yhg3F3#j&&d$K7yoepBN1S8E;Z`?u
zbtVUq!{+Ss8D<<e2g=JhPo9>}@c1s<zZmC*ZXah)ey+|Ca~P!ahO=S!W4Y`9X83Ps
z`}qH_m~c8f^NjP`#Tgx#m$N%;XJJrqoUOdzIhY4>1&m$V4`Urn3k9=hI6DH}1#_#p
z2&03myRya;2Ud596SC&!?1Bs+Q<YadcQ}|Xb3)L*c{vM1E4%W7FANv==L3B|osmId
za-(9Ja3dpwFe?K`u>h;VWHtka;t6gI;;alnvD7EVsaF|_1wsvgd<7u?@#I#=24OY^
zhUAE?49W^efofbC9{X(lC(P=gG##jBa;xe?aW<e@wq*~JdyX<RtFZ!oa22d>aw|~n
Ww4?tfvp?V|o*-^g%%EVvzyJW?K9qd`

diff --git a/examples/debugprintfdemo/Makefile b/examples/debugprintfdemo/Makefile
index 64e8f95..09ebe05 100644
--- a/examples/debugprintfdemo/Makefile
+++ b/examples/debugprintfdemo/Makefile
@@ -9,9 +9,16 @@ GPIO_Toggle:=EXAM/GPIO/GPIO_Toggle/User
 CH32V003FUN:=../../ch32v003fun
 MINICHLINK:=../../minichlink
 
+ifeq ($(OS),Windows_NT)
+# On Windows, all the major RISC-V GCC installs are missing the -ec libgcc.
+LIB_GCC=../../misc/libgcc.a
+else
+LIB_GCC=-lgcc
+endif
+
 CFLAGS:= \
 	-g -Os -flto -ffunction-sections \
-	-static-libgcc -lgcc \
+	-static-libgcc $(LIB_GCC) \
 	-march=rv32ec \
 	-mabi=ilp32e \
 	-I/usr/include/newlib \
diff --git a/examples/i2c_oled/Makefile b/examples/i2c_oled/Makefile
index a69a60c..2f71bfb 100644
--- a/examples/i2c_oled/Makefile
+++ b/examples/i2c_oled/Makefile
@@ -9,9 +9,16 @@ GPIO_Toggle:=EXAM/GPIO/GPIO_Toggle/User
 CH32V003FUN:=../../ch32v003fun
 MINICHLINK:=../../minichlink
 
+ifeq ($(OS),Windows_NT)
+# On Windows, all the major RISC-V GCC installs are missing the -ec libgcc.
+LIB_GCC=../../misc/libgcc.a
+else
+LIB_GCC=-lgcc
+endif
+
 CFLAGS:= \
 	-g -Os -flto -ffunction-sections \
-	-static-libgcc -lgcc \
+	-static-libgcc $(LIB_GCC) \
 	-march=rv32ec \
 	-mabi=ilp32e \
 	-I/usr/include/newlib \
diff --git a/examples/sandbox/Makefile b/examples/sandbox/Makefile
index 621e2fc..b61a370 100644
--- a/examples/sandbox/Makefile
+++ b/examples/sandbox/Makefile
@@ -9,9 +9,16 @@ GPIO_Toggle:=EXAM/GPIO/GPIO_Toggle/User
 CH32V003FUN:=../../ch32v003fun
 MINICHLINK:=../../minichlink
 
+ifeq ($(OS),Windows_NT)
+# On Windows, all the major RISC-V GCC installs are missing the -ec libgcc.
+LIB_GCC=../../misc/libgcc.a
+else
+LIB_GCC=-lgcc
+endif
+
 CFLAGS:= \
 	-g -Os -flto -ffunction-sections \
-	-static-libgcc -lgcc \
+	-static-libgcc $(LIB_GCC) \
 	-march=rv32ec \
 	-mabi=ilp32e \
 	-I/usr/include/newlib \
diff --git a/examples/self_modify_code/Makefile b/examples/self_modify_code/Makefile
index f4d72fe..3200406 100644
--- a/examples/self_modify_code/Makefile
+++ b/examples/self_modify_code/Makefile
@@ -9,9 +9,16 @@ GPIO_Toggle:=EXAM/GPIO/GPIO_Toggle/User
 CH32V003FUN:=../../ch32v003fun
 MINICHLINK:=../../minichlink
 
+ifeq ($(OS),Windows_NT)
+# On Windows, all the major RISC-V GCC installs are missing the -ec libgcc.
+LIB_GCC=../../misc/libgcc.a
+else
+LIB_GCC=-lgcc
+endif
+
 CFLAGS:= \
 	-g -Os -flto -ffunction-sections \
-	-static-libgcc -lgcc \
+	-static-libgcc $(LIB_GCC) \
 	-march=rv32ec \
 	-mabi=ilp32e \
 	-I/usr/include/newlib \
diff --git a/examples/systick_irq/Makefile b/examples/systick_irq/Makefile
index c5d7348..7e9ef9e 100644
--- a/examples/systick_irq/Makefile
+++ b/examples/systick_irq/Makefile
@@ -9,9 +9,16 @@ GPIO_Toggle:=EXAM/GPIO/GPIO_Toggle/User
 CH32V003FUN:=../../ch32v003fun
 MINICHLINK:=../../minichlink
 
+ifeq ($(OS),Windows_NT)
+# On Windows, all the major RISC-V GCC installs are missing the -ec libgcc.
+LIB_GCC=../../misc/libgcc.a
+else
+LIB_GCC=-lgcc
+endif
+
 CFLAGS:= \
 	-g -Os -flto -ffunction-sections \
-	-static-libgcc -lgcc \
+	-static-libgcc $(LIB_GCC) \
 	-march=rv32ec \
 	-mabi=ilp32e \
 	-I/usr/include/newlib \
diff --git a/examples/tim1_pwm/Makefile b/examples/tim1_pwm/Makefile
index 67357ef..56fff11 100644
--- a/examples/tim1_pwm/Makefile
+++ b/examples/tim1_pwm/Makefile
@@ -9,9 +9,16 @@ GPIO_Toggle:=EXAM/GPIO/GPIO_Toggle/User
 CH32V003FUN:=../../ch32v003fun
 MINICHLINK:=../../minichlink
 
+ifeq ($(OS),Windows_NT)
+# On Windows, all the major RISC-V GCC installs are missing the -ec libgcc.
+LIB_GCC=../../misc/libgcc.a
+else
+LIB_GCC=-lgcc
+endif
+
 CFLAGS:= \
 	-g -Os -flto -ffunction-sections \
-	-static-libgcc -lgcc \
+	-static-libgcc $(LIB_GCC) \
 	-march=rv32ec \
 	-mabi=ilp32e \
 	-I/usr/include/newlib \
diff --git a/examples/uartdemo/Makefile b/examples/uartdemo/Makefile
index 24d8be3..a4e1a7c 100644
--- a/examples/uartdemo/Makefile
+++ b/examples/uartdemo/Makefile
@@ -9,9 +9,16 @@ GPIO_Toggle:=EXAM/GPIO/GPIO_Toggle/User
 CH32V003FUN:=../../ch32v003fun
 MINICHLINK:=../../minichlink
 
+ifeq ($(OS),Windows_NT)
+# On Windows, all the major RISC-V GCC installs are missing the -ec libgcc.
+LIB_GCC=../../misc/libgcc.a
+else
+LIB_GCC=-lgcc
+endif
+
 CFLAGS:= \
 	-g -Os -flto -ffunction-sections \
-	-static-libgcc -lgcc \
+	-static-libgcc $(LIB_GCC) \
 	-march=rv32ec \
 	-mabi=ilp32e \
 	-I/usr/include/newlib \
diff --git a/examples/ws2812bdemo/Makefile b/examples/ws2812bdemo/Makefile
index 50fb288..8f7bb98 100644
--- a/examples/ws2812bdemo/Makefile
+++ b/examples/ws2812bdemo/Makefile
@@ -7,9 +7,16 @@ PREFIX:=riscv64-unknown-elf
 CH32V003FUN:=../../ch32v003fun
 MINICHLINK:=../../minichlink
 
+ifeq ($(OS),Windows_NT)
+# On Windows, all the major RISC-V GCC installs are missing the -ec libgcc.
+LIB_GCC=../../misc/libgcc.a
+else
+LIB_GCC=-lgcc
+endif
+
 CFLAGS:= \
 	-g -Os -flto -ffunction-sections \
-	-static-libgcc -lgcc \
+	-static-libgcc $(LIB_GCC) \
 	-march=rv32ec \
 	-mabi=ilp32e \
 	-I/usr/include/newlib \
-- 
GitLab