From 0187f297d141777eec9f336e855ff1a47a4d48d4 Mon Sep 17 00:00:00 2001
From: Dmitry Frank <dmitry.frank@cesanta.com>
Date: Fri, 4 Nov 2016 14:14:22 +0200
Subject: [PATCH] Make nRF51 example work with GCC

Unfortunately it turns out Nordic's examples were able to build with GCC
just because they suppressed all warnings; I had to do the same here
because there are some macro redefinitions of arm-none-eabi-gcc and
lwip.

TODO: resolve that and do not suppress warnings.

PUBLISHED_FROM=e65c7b0f2451f85765d958d7f67eb9262f7bc929
---
 .../http/boards/pca10028/armgcc/.gdbinit      |  2 ++
 .../http/boards/pca10028/armgcc/Makefile      | 26 +++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)
 create mode 100644 examples/nRF51/http/boards/pca10028/armgcc/.gdbinit

diff --git a/examples/nRF51/http/boards/pca10028/armgcc/.gdbinit b/examples/nRF51/http/boards/pca10028/armgcc/.gdbinit
new file mode 100644
index 000000000..1cfee81e6
--- /dev/null
+++ b/examples/nRF51/http/boards/pca10028/armgcc/.gdbinit
@@ -0,0 +1,2 @@
+target extended-remote localhost:2331
+file _build/nrf51422_xxac_s1xx_iot.out
diff --git a/examples/nRF51/http/boards/pca10028/armgcc/Makefile b/examples/nRF51/http/boards/pca10028/armgcc/Makefile
index 99f461b51..cb76de49d 100644
--- a/examples/nRF51/http/boards/pca10028/armgcc/Makefile
+++ b/examples/nRF51/http/boards/pca10028/armgcc/Makefile
@@ -46,13 +46,17 @@ C_SOURCE_FILES += \
 ../../../../nrf51_iot_sdk/components/libraries/trace/app_trace.c \
 ../../../../nrf51_iot_sdk/components/libraries/mem_manager/mem_manager.c \
 ../../../../nrf51_iot_sdk/components/libraries/util/nrf_assert.c \
-../../../../nrf51_iot_sdk/components/libraries/uart/retarget.c \
 ../../../../nrf51_iot_sdk/external/lwip/src/port/nrf_platform_port.c \
 ../../../../nrf51_iot_sdk/components/drivers_nrf/uart/app_uart_fifo.c \
 ../../../../nrf51_iot_sdk/components/drivers_nrf/hal/nrf_delay.c \
 ../../../../nrf51_iot_sdk/components/drivers_nrf/common/nrf_drv_common.c \
 ../../../../nrf51_iot_sdk/components/drivers_nrf/gpiote/nrf_drv_gpiote.c \
 ../../../main.c \
+../../../bleconfig.c \
+../../../rtt/RTT/SEGGER_RTT.c \
+../../../rtt/RTT/SEGGER_RTT_printf.c \
+../../../rtt/Syscalls/RTT_Syscalls_GCC.c \
+../../../../../../mongoose.c \
 ../../../../nrf51_iot_sdk/components/ble/common/ble_advdata.c \
 ../../../../nrf51_iot_sdk/components/ble/common/ble_srv_common.c \
 ../../../../nrf51_iot_sdk/components/iot/context_manager/iot_context_manager.c \
@@ -88,6 +92,8 @@ INC_PATHS += -I../../../../nrf51_iot_sdk/components/libraries/scheduler
 INC_PATHS += -I../../../../nrf51_iot_sdk/external/lwip/src/include/netif
 INC_PATHS += -I../../../../nrf51_iot_sdk/components/iot/include
 INC_PATHS += -I../../..
+INC_PATHS += -I../../../../../..
+INC_PATHS += -I../../../rtt/RTT
 INC_PATHS += -I../../../../nrf51_iot_sdk/components/iot/context_manager
 INC_PATHS += -I../../../../nrf51_iot_sdk/components/toolchain/gcc
 INC_PATHS += -I../../../../nrf51_iot_sdk/components/drivers_nrf/gpiote
@@ -105,6 +111,14 @@ OUTPUT_BINARY_DIRECTORY = $(OBJECT_DIRECTORY)
 # Sorting removes duplicates
 BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LISTING_DIRECTORY) )
 
+# Mongoose features
+MG_FEATURES_TINY = \
+                   -DMG_DISABLE_HTTP_DIGEST_AUTH \
+                   -DMG_DISABLE_MD5 \
+                   -DMG_DISABLE_HTTP_KEEP_ALIVE \
+                   -DMG_ENABLE_HTTP_SSI=0 \
+                   -DMG_ENABLE_HTTP_STREAMING_MULTIPART
+
 #flags common to all targets
 CFLAGS  = -D__HEAP_SIZE=512
 CFLAGS += -DSWI_DISABLE0
@@ -116,12 +130,20 @@ CFLAGS += -DBLE_STACK_SUPPORT_REQD
 CFLAGS += -DBSP_DEFINES_ONLY
 CFLAGS += -mcpu=cortex-m0
 CFLAGS += -mthumb -mabi=aapcs --std=gnu99
-CFLAGS += -Wall -Werror -O3
+CFLAGS += -Wall -g3 -O3
 CFLAGS += -mfloat-abi=soft
 # keep every function in separate section. This will allow linker to dump unused functions
 CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
 CFLAGS += -fno-builtin --short-enums
 
+CFLAGS += -DCS_ENABLE_STDIO
+
+# This macro is needed for stdout to be retargeted to either UART or RTT
+CFLAGS += -DENABLE_DEBUG_LOG_SUPPORT
+
+# Mongoose flags
+CFLAGS += -DCS_PLATFORM=CS_P_NRF52 $(MG_FEATURES_TINY) -DMG_MODULE_LINES
+
 # keep every function in separate section. This will allow linker to dump unused functions
 LDFLAGS += -Xlinker -Map=$(LISTING_DIRECTORY)/$(OUTPUT_FILENAME).map
 LDFLAGS += -mthumb -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT)
-- 
GitLab