@@ -6,10 +6,26 @@ LIBRARIES_PATH := ../../libraries
66FORCE32 ?= 1
77OPTZ ?= -Os
88V ?= 0
9+ R ?= noexec
910DEFSYM_FS ?= -Wl,--defsym,_FS_start=0x40300000 -Wl,--defsym,_FS_end=0x411FA000 -Wl,--defsym,_FS_page=0x100 -Wl,--defsym,_FS_block=0x2000 -Wl,--defsym,_EEPROM_start=0x411fb000
1011
1112MAKEFILE = $(word 1, $(MAKEFILE_LIST ) )
1213
14+ CXX = $(shell for i in g++-10 g++-9 g++-8 g++; do which $$i > /dev/null && { echo $$i; break; } done)
15+ CC = $(shell for i in gcc-10 gcc-9 gcc-8 gcc; do which $$i > /dev/null && { echo $$i; break; } done)
16+ GCOV = $(shell for i in gcov-10 gcov-9 gcov-8 gcov; do which $$i > /dev/null && { echo $$i; break; } done)
17+ $(warning using $(CXX))
18+ ifeq ($(CXX ) ,g++)
19+ CXXFLAGS += -std=gnu++11
20+ else
21+ CXXFLAGS += -std=gnu++17
22+ endif
23+ ifeq ($(CC ) ,gcc)
24+ CFLAGS += -std=gnu11
25+ else
26+ CFLAGS += -std=gnu17
27+ endif
28+
1329# I wasn't able to build with clang when -coverage flag is enabled, forcing GCC on OS X
1430ifeq ($(shell uname -s) ,Darwin)
1531CC ?= gcc
@@ -23,7 +39,7 @@ GENHTML ?= genhtml
2339ifeq ($(FORCE32 ) ,1)
2440SIZEOFLONG = $(shell echo 'int main() {return sizeof(long);}'|$(CXX ) -m32 -x c++ - -o sizeoflong 2>/dev/null && ./sizeoflong; echo $$? ; rm -f sizeoflong;)
2541ifneq ($(SIZEOFLONG ) ,4)
26- $(warning Cannot compile in 32 bit mode, switching to native mode)
42+ $(warning Cannot compile in 32 bit mode (g++-multilib is missing?) , switching to native mode)
2743else
2844N32 = 32
2945M32 = -m32
@@ -153,16 +169,18 @@ DEBUG += -DDEBUG_ESP_SSL -DDEBUG_ESP_TLS_MEM -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP
153169endif
154170
155171FLAGS += $(DEBUG ) -Wall $(OPTZ ) -fno-common -g $(M32 )
156- FLAGS += -fstack-check -fstack- protector-all
172+ FLAGS += -fstack-protector-all
157173FLAGS += -DHTTPCLIENT_1_1_COMPATIBLE=0
158174FLAGS += -DLWIP_IPV6=0
159175FLAGS += -DHOST_MOCK=1
160176FLAGS += -DNONOSDK221=1
161177FLAGS += $(MKFLAGS )
162178FLAGS += -Wimplicit-fallthrough=2 # allow "// fall through" comments to stop spurious warnings
163- CXXFLAGS += -std=c++11 -fno-rtti $(FLAGS ) -funsigned-char
164- CFLAGS += -std=c99 $(FLAGS ) -funsigned-char
179+ FLAGS += $(USERCFLAGS )
180+ CXXFLAGS += -fno-rtti $(FLAGS ) -funsigned-char
181+ CFLAGS += $(FLAGS ) -funsigned-char
165182LDFLAGS += -coverage $(OPTZ ) -g $(M32 )
183+ LDFLAGS += $(USERLDFLAGS )
166184VALGRINDFLAGS += --leak-check=full --track-origins=yes --error-limit=no --show-leak-kinds=all --error-exitcode=999
167185CXXFLAGS += -Wno-error=format-security # cores/esp8266/Print.cpp:42:24: error: format not a string literal and no format arguments [-Werror=format-security] -- (os_printf_plus(not_the_best_way))
168186# CXXFLAGS += -Wno-format-security # cores/esp8266/Print.cpp:42:40: warning: format not a string literal and no format arguments [-Wformat-security] -- (os_printf_plus(not_the_best_way))
@@ -219,13 +237,14 @@ build-info: # show toolchain version
219237 $(CC ) -v
220238 @echo " CXX: " $(CXX )
221239 $(CXX ) -v
222- @echo " GCOV : " $(GCOV )
223- $( GCOV ) -v
240+ @echo " CFLAGS : " $(CFLAGS )
241+ @echo " CXXFLAGS: " $( CXXFLAGS )
224242 @echo " ----------------------------------"
225243
226244-include $(BINDIR ) /.*.d
227245.SUFFIXES :
228246
247+ .PRECIOUS : % .c$(E32 ) .o
229248% .c$(E32 ) .o : % .c
230249 $(VERBC ) $(CC ) $(PREINCLUDES ) $(CFLAGS ) $(INC_PATHS ) -MD -MF $(BINDIR ) /.$(notdir $< ) .d -c -o $@ $<
231250
@@ -235,7 +254,7 @@ build-info: # show toolchain version
235254
236255$(BINDIR ) /core.a : $(C_OBJECTS ) $(CPP_OBJECTS_CORE )
237256 ar -rcu $@ $^
238- ranlib -c $@
257+ ranlib $@
239258
240259$(OUTPUT_BINARY ) : $(CPP_OBJECTS_TESTS ) $(BINDIR ) /core.a
241260 $(VERBLD ) $(CXX ) $(DEFSYM_FS ) $(LDFLAGS ) $^ -o $@
@@ -313,18 +332,19 @@ ssl: # download source and build BearSSL
313332 cd ../../tools/sdk/ssl && make native$(N32 )
314333
315334ULIBPATHS = $(shell echo $(ULIBDIRS ) | sed 's,:, ,g')
316- USERLIBDIRS = $(shell test -z "$(ULIBPATHS ) " || for d in $(ULIBPATHS ) ; do for dd in $$d $$d/src; do test -d $$dd && { echo -I$$dd; echo "userlib: using directory '$$dd'" 1>&2; } done; done)
317- USERLIBSRCS = $(shell test -z "$(ULIBPATHS ) " || for d in $(ULIBPATHS ) ; do for ss in $$d/* .cpp $$d/src/* .cpp; do test -r $$ss && echo $$ss; done; done)
335+ USERLIBDIRS = $(shell test -z "$(ULIBPATHS ) " || for d in $(ULIBPATHS ) ; do for dd in $$d $$d/src $$d/src/libmad ; do test -d $$dd && { echo -I$$dd; echo "userlib: using directory '$$dd'" 1>&2; } done; done)
336+ USERLIBSRCS = $(shell test -z "$(ULIBPATHS ) " || for d in $(ULIBPATHS ) ; do for ss in $$d/* .cpp $$d/src/* .cpp $$d/src/libmad/ * .c ; do test -r $$ss && echo $$ss; done; done)
318337INC_PATHS += $(USERLIBDIRS )
319338INC_PATHS += -I$(INODIR ) /..
320- CPP_OBJECTS_CORE_EMU = $(CPP_SOURCES_CORE_EMU:.cpp=.cpp$(E32 ) .o ) $(USERLIBSRCS:.cpp=.cpp$(E32 ) .o )
339+ CPP_OBJECTS_CORE_EMU = $(CPP_SOURCES_CORE_EMU:.cpp=.cpp$(E32 ) .o ) $(USERLIBSRCS:.cpp=.cpp$(E32 ) .o ) $(USERCXXSOURCES:.cpp=.cpp$(E32 ) .o )
340+ C_OBJECTS_CORE_EMU = $(USERCSOURCES:.c=.c$(E32 ) .o )
321341
322- bin/fullcore.a : $(C_OBJECTS ) $(CPP_OBJECTS_CORE_EMU )
342+ bin/fullcore$( E32 ) .a : $(C_OBJECTS ) $(CPP_OBJECTS_CORE_EMU ) $( C_OBJECTS_CORE_EMU )
323343 $(VERBAR ) ar -rcu $@ $^
324- $(VERBAR ) ranlib -c $@
344+ $(VERBAR ) ranlib $@
325345
326- % : % .ino.cpp$(E32 ) .o bin/fullcore.a
327- $(VERBLD ) $(CXX ) $(LDFLAGS ) $< bin/fullcore.a $(LIBSSL ) -o $@
346+ % : % .ino.cpp$(E32 ) .o bin/fullcore$( E32 ) .a
347+ $(VERBLD ) $(CXX ) $(LDFLAGS ) $< bin/fullcore$( E32 ) .a $(LIBSSL ) -o $@
328348 @echo " ----> $@ <----"
329349
330350# ################################################
@@ -333,7 +353,12 @@ ifeq ($(INO),)
333353
334354% : % .ino
335355 @# recursive 'make' with paths
336- $(MAKE ) -f $(MAKEFILE ) MKFLAGS=-Wextra INODIR=$(dir $@ ) INO=$(notdir $@ ) $(BINDIR ) /$(notdir $@ ) /$(notdir $@ )
356+ $(MAKE ) -f $(MAKEFILE ) MKFLAGS=-Wextra INODIR=$(dir $@ ) INO=$(notdir $@ ) $(BINDIR ) /$(notdir $@ ) /$(notdir $@ ) \
357+ USERCFLAGS=" $( USERCFLAGS) " \
358+ USERCSOURCES=" $( USERCSOURCES) " \
359+ USERCXXSOURCES=" $( USERCXXSOURCES) " \
360+ USERLDFLAGS=" $( USERLDFLAGS) "
361+ test " $( R) " = noexec || $(BINDIR ) /$(notdir $@ ) /$(notdir $@ ) $(R )
337362 @# see below the new build rule with fixed output path outside from core location
338363
339364# ####################
@@ -376,4 +401,4 @@ help:
376401 @echo " "
377402 @sed -rne ' s,([^: \t]*):[^=#]*#[\t ]*(.*),\1 - \2,p' $(MAKEFILE )
378403 @echo " "
379-
404+
0 commit comments