From 2061167bd925b0b4197c35ada5476de2e560214d Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Mon, 3 Jul 2017 13:29:47 +1000 Subject: [PATCH 1/2] Add check for unresolved-but-unused symbols at build. From what I can tell they *should* be harmless, but I'd rather we keep a neat house in the first place. --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 28b69fec5c..5380a86ebd 100644 --- a/Makefile +++ b/Makefile @@ -188,6 +188,7 @@ endef $(BINODIR)/%.bin: $(IMAGEODIR)/%.out @mkdir -p $(BINODIR) + @$(NM) $< | grep -w U && { echo "Firmware has unresolved (but unused) symbols - should be fixed nevertheless!"; exit 1; } || true $(ESPTOOL) elf2image --flash_mode dio --flash_freq 40m $< -o $(FIRMWAREDIR) ############################################################# From ea4d33715f23e7df256debf2b0fd80ab1241b694 Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Mon, 3 Jul 2017 13:31:32 +1000 Subject: [PATCH 2/2] Cleaned up sjson module build. - Move jsonsl build to regular library build rather than #include the .c file - Provide wrappers for malloc/calloc/free to fix undefined symbol warnings. --- Makefile | 2 +- app/Makefile | 10 +++++---- app/modules/sjson.c | 6 ++---- app/sjson/Makefile | 47 +++++++++++++++++++++++++++++++++++++++++ app/sjson/json_config.h | 7 ++++++ app/sjson/memcompat.h | 11 ++++++++++ 6 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 app/sjson/Makefile create mode 100644 app/sjson/json_config.h create mode 100644 app/sjson/memcompat.h diff --git a/Makefile b/Makefile index 5380a86ebd..395339d4a5 100644 --- a/Makefile +++ b/Makefile @@ -188,7 +188,7 @@ endef $(BINODIR)/%.bin: $(IMAGEODIR)/%.out @mkdir -p $(BINODIR) - @$(NM) $< | grep -w U && { echo "Firmware has unresolved (but unused) symbols - should be fixed nevertheless!"; exit 1; } || true + @$(NM) $< | grep -w U && { echo "Firmware has undefined (but unused) symbols!"; exit 1; } || true $(ESPTOOL) elf2image --flash_mode dio --flash_freq 40m $< -o $(FIRMWAREDIR) ############################################################# diff --git a/app/Makefile b/app/Makefile index e18139a9b7..314f0f18e5 100644 --- a/app/Makefile +++ b/app/Makefile @@ -48,7 +48,8 @@ SUBDIRS= \ websocket \ swTimer \ misc \ - pm \ + pm \ + sjson \ endif # } PDIR @@ -94,14 +95,15 @@ COMPONENTS_eagle.app.v6 = \ dhtlib/libdhtlib.a \ tsl2561/tsl2561lib.a \ http/libhttp.a \ - pm/libpm.a \ + pm/libpm.a \ websocket/libwebsocket.a \ esp-gdbstub/libgdbstub.a \ net/libnodemcu_net.a \ - mbedtls/libmbedtls.a \ + mbedtls/libmbedtls.a \ modules/libmodules.a \ swTimer/libswtimer.a \ - misc/libmisc.a \ + misc/libmisc.a \ + sjson/libsjson.a \ # Inspect the modules library and work out which modules need to be linked. diff --git a/app/modules/sjson.c b/app/modules/sjson.c index ada01b5bb1..e5ed92f570 100644 --- a/app/modules/sjson.c +++ b/app/modules/sjson.c @@ -11,10 +11,8 @@ #include "c_limits.h" #endif -#define JSONSL_STATE_USER_FIELDS int lua_object_ref; int used_count; -#define JSONSL_NO_JPR - -#include "jsonsl.c" +#include "json_config.h" +#include "jsonsl.h" #define LUA_SJSONLIBNAME "sjson" diff --git a/app/sjson/Makefile b/app/sjson/Makefile new file mode 100644 index 0000000000..a439800492 --- /dev/null +++ b/app/sjson/Makefile @@ -0,0 +1,47 @@ +############################################################# +# Required variables for each makefile +# Discard this section from all parent makefiles +# Expected variables (with automatic defaults): +# CSRCS (all "C" files in the dir) +# SUBDIRS (all subdirs with a Makefile) +# GEN_LIBS - list of libs to be generated () +# GEN_IMAGES - list of images to be generated () +# COMPONENTS_xxx - a list of libs/objs in the form +# subdir/lib to be extracted and rolled up into +# a generated lib/image xxx.a () +# +ifndef PDIR +GEN_LIBS = libsjson.a +endif + +STD_CFLAGS=-std=gnu11 -Wimplicit + +############################################################# +# Configuration i.e. compile options etc. +# Target specific stuff (defines etc.) goes in here! +# Generally values applying to a tree are captured in the +# makefile at its root level - these are then overridden +# for a subtree within the makefile rooted therein +# +DEFINES += -include memcompat.h -include json_config.h + +############################################################# +# Recursion Magic - Don't touch this!! +# +# Each subtree potentially has an include directory +# corresponding to the common APIs applicable to modules +# rooted at that subtree. Accordingly, the INCLUDE PATH +# of a module can only contain the include directories up +# its parent path, and not its siblings +# +# Required for each makefile to inherit from the parent +# + +INCLUDES := $(INCLUDES) -I $(PDIR)include +INCLUDES += -I ./ +INCLUDES += -I ./include +INCLUDES += -I ../include +INCLUDES += -I ../../include +PDIR := ../$(PDIR) +sinclude $(PDIR)Makefile + diff --git a/app/sjson/json_config.h b/app/sjson/json_config.h new file mode 100644 index 0000000000..8bc13b8d3a --- /dev/null +++ b/app/sjson/json_config.h @@ -0,0 +1,7 @@ +#ifndef __JSON_CONFIG_H__ +#define __JSON_CONFIG_H__ + +#define JSONSL_STATE_USER_FIELDS int lua_object_ref; int used_count; +#define JSONSL_NO_JPR + +#endif diff --git a/app/sjson/memcompat.h b/app/sjson/memcompat.h new file mode 100644 index 0000000000..2e3f84fb39 --- /dev/null +++ b/app/sjson/memcompat.h @@ -0,0 +1,11 @@ +#ifndef __MEMCOMPAT_H__ +#define __MEMCOMPAT_H__ + +#include "c_types.h" +#include "mem.h" + +static inline void *malloc(size_t sz) { return os_malloc(sz); } +static inline void free(void *p) { return os_free(p); } +static inline void *calloc(size_t n, size_t sz) { return os_zalloc(n*sz); } + +#endif