1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-20 10:24:18 +03:00

emulation-on-host makefile update, allowing to pass more options (#7552)

This commit is contained in:
david gauchard
2020-08-26 15:40:54 +02:00
committed by GitHub
parent 83535a01d2
commit e53aa87160
2 changed files with 47 additions and 16 deletions

View File

@ -6,10 +6,26 @@ LIBRARIES_PATH := ../../libraries
FORCE32 ?= 1 FORCE32 ?= 1
OPTZ ?= -Os OPTZ ?= -Os
V ?= 0 V ?= 0
R ?= noexec
DEFSYM_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 DEFSYM_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
MAKEFILE = $(word 1, $(MAKEFILE_LIST)) MAKEFILE = $(word 1, $(MAKEFILE_LIST))
CXX = $(shell for i in g++-10 g++-9 g++-8 g++; do which $$i > /dev/null && { echo $$i; break; } done)
CC = $(shell for i in gcc-10 gcc-9 gcc-8 gcc; do which $$i > /dev/null && { echo $$i; break; } done)
GCOV = $(shell for i in gcov-10 gcov-9 gcov-8 gcov; do which $$i > /dev/null && { echo $$i; break; } done)
$(warning using $(CXX))
ifeq ($(CXX),g++)
CXXFLAGS += -std=gnu++11
else
CXXFLAGS += -std=gnu++17
endif
ifeq ($(CC),gcc)
CFLAGS += -std=gnu11
else
CFLAGS += -std=gnu17
endif
# I wasn't able to build with clang when -coverage flag is enabled, forcing GCC on OS X # I wasn't able to build with clang when -coverage flag is enabled, forcing GCC on OS X
ifeq ($(shell uname -s),Darwin) ifeq ($(shell uname -s),Darwin)
CC ?= gcc CC ?= gcc
@ -23,7 +39,7 @@ GENHTML ?= genhtml
ifeq ($(FORCE32),1) ifeq ($(FORCE32),1)
SIZEOFLONG = $(shell echo 'int main(){return sizeof(long);}'|$(CXX) -m32 -x c++ - -o sizeoflong 2>/dev/null && ./sizeoflong; echo $$?; rm -f sizeoflong;) SIZEOFLONG = $(shell echo 'int main(){return sizeof(long);}'|$(CXX) -m32 -x c++ - -o sizeoflong 2>/dev/null && ./sizeoflong; echo $$?; rm -f sizeoflong;)
ifneq ($(SIZEOFLONG),4) ifneq ($(SIZEOFLONG),4)
$(warning Cannot compile in 32 bit mode, switching to native mode) $(warning Cannot compile in 32 bit mode (g++-multilib is missing?), switching to native mode)
else else
N32 = 32 N32 = 32
M32 = -m32 M32 = -m32
@ -160,9 +176,11 @@ FLAGS += -DHOST_MOCK=1
FLAGS += -DNONOSDK221=1 FLAGS += -DNONOSDK221=1
FLAGS += $(MKFLAGS) FLAGS += $(MKFLAGS)
FLAGS += -Wimplicit-fallthrough=2 # allow "// fall through" comments to stop spurious warnings FLAGS += -Wimplicit-fallthrough=2 # allow "// fall through" comments to stop spurious warnings
CXXFLAGS += -std=c++11 -fno-rtti $(FLAGS) -funsigned-char FLAGS += $(USERCFLAGS)
CFLAGS += -std=c99 $(FLAGS) -funsigned-char CXXFLAGS += -fno-rtti $(FLAGS) -funsigned-char
CFLAGS += $(FLAGS) -funsigned-char
LDFLAGS += -coverage $(OPTZ) -g $(M32) LDFLAGS += -coverage $(OPTZ) -g $(M32)
LDFLAGS += $(USERLDFLAGS)
VALGRINDFLAGS += --leak-check=full --track-origins=yes --error-limit=no --show-leak-kinds=all --error-exitcode=999 VALGRINDFLAGS += --leak-check=full --track-origins=yes --error-limit=no --show-leak-kinds=all --error-exitcode=999
CXXFLAGS += -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)) CXXFLAGS += -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))
#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)) #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
$(CC) -v $(CC) -v
@echo "CXX: " $(CXX) @echo "CXX: " $(CXX)
$(CXX) -v $(CXX) -v
@echo "GCOV: " $(GCOV) @echo "CFLAGS: " $(CFLAGS)
$(GCOV) -v @echo "CXXFLAGS: " $(CXXFLAGS)
@echo "----------------------------------" @echo "----------------------------------"
-include $(BINDIR)/.*.d -include $(BINDIR)/.*.d
.SUFFIXES: .SUFFIXES:
.PRECIOUS: %.c$(E32).o
%.c$(E32).o: %.c %.c$(E32).o: %.c
$(VERBC) $(CC) $(PREINCLUDES) $(CFLAGS) $(INC_PATHS) -MD -MF $(BINDIR)/.$(notdir $<).d -c -o $@ $< $(VERBC) $(CC) $(PREINCLUDES) $(CFLAGS) $(INC_PATHS) -MD -MF $(BINDIR)/.$(notdir $<).d -c -o $@ $<
@ -235,7 +254,7 @@ build-info: # show toolchain version
$(BINDIR)/core.a: $(C_OBJECTS) $(CPP_OBJECTS_CORE) $(BINDIR)/core.a: $(C_OBJECTS) $(CPP_OBJECTS_CORE)
ar -rcu $@ $^ ar -rcu $@ $^
ranlib -c $@ ranlib $@
$(OUTPUT_BINARY): $(CPP_OBJECTS_TESTS) $(BINDIR)/core.a $(OUTPUT_BINARY): $(CPP_OBJECTS_TESTS) $(BINDIR)/core.a
$(VERBLD) $(CXX) $(DEFSYM_FS) $(LDFLAGS) $^ -o $@ $(VERBLD) $(CXX) $(DEFSYM_FS) $(LDFLAGS) $^ -o $@
@ -313,18 +332,19 @@ ssl: # download source and build BearSSL
cd ../../tools/sdk/ssl && make native$(N32) cd ../../tools/sdk/ssl && make native$(N32)
ULIBPATHS = $(shell echo $(ULIBDIRS) | sed 's,:, ,g') ULIBPATHS = $(shell echo $(ULIBDIRS) | sed 's,:, ,g')
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) 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)
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) 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)
INC_PATHS += $(USERLIBDIRS) INC_PATHS += $(USERLIBDIRS)
INC_PATHS += -I$(INODIR)/.. INC_PATHS += -I$(INODIR)/..
CPP_OBJECTS_CORE_EMU = $(CPP_SOURCES_CORE_EMU:.cpp=.cpp$(E32).o) $(USERLIBSRCS:.cpp=.cpp$(E32).o) CPP_OBJECTS_CORE_EMU = $(CPP_SOURCES_CORE_EMU:.cpp=.cpp$(E32).o) $(USERLIBSRCS:.cpp=.cpp$(E32).o) $(USERCXXSOURCES:.cpp=.cpp$(E32).o)
C_OBJECTS_CORE_EMU = $(USERCSOURCES:.c=.c$(E32).o)
bin/fullcore.a: $(C_OBJECTS) $(CPP_OBJECTS_CORE_EMU) bin/fullcore$(E32).a: $(C_OBJECTS) $(CPP_OBJECTS_CORE_EMU) $(C_OBJECTS_CORE_EMU)
$(VERBAR) ar -rcu $@ $^ $(VERBAR) ar -rcu $@ $^
$(VERBAR) ranlib -c $@ $(VERBAR) ranlib $@
%: %.ino.cpp$(E32).o bin/fullcore.a %: %.ino.cpp$(E32).o bin/fullcore$(E32).a
$(VERBLD) $(CXX) $(LDFLAGS) $< bin/fullcore.a $(LIBSSL) -o $@ $(VERBLD) $(CXX) $(LDFLAGS) $< bin/fullcore$(E32).a $(LIBSSL) -o $@
@echo "----> $@ <----" @echo "----> $@ <----"
################################################# #################################################
@ -333,7 +353,12 @@ ifeq ($(INO),)
%: %.ino %: %.ino
@# recursive 'make' with paths @# recursive 'make' with paths
$(MAKE) -f $(MAKEFILE) MKFLAGS=-Wextra INODIR=$(dir $@) INO=$(notdir $@) $(BINDIR)/$(notdir $@)/$(notdir $@) $(MAKE) -f $(MAKEFILE) MKFLAGS=-Wextra INODIR=$(dir $@) INO=$(notdir $@) $(BINDIR)/$(notdir $@)/$(notdir $@) \
USERCFLAGS="$(USERCFLAGS)" \
USERCSOURCES="$(USERCSOURCES)" \
USERCXXSOURCES="$(USERCXXSOURCES)" \
USERLDFLAGS="$(USERLDFLAGS)"
test "$(R)" = noexec || $(BINDIR)/$(notdir $@)/$(notdir $@) $(R)
@# see below the new build rule with fixed output path outside from core location @# see below the new build rule with fixed output path outside from core location
##################### #####################

View File

@ -45,7 +45,7 @@ Optional 'V=1' enables makefile verbosity
Optional 'D=1' enables core debug (same as IDE's tools menu) Optional 'D=1' enables core debug (same as IDE's tools menu)
Optional 'OPTZ=-O2' will update gcc -O option (default is -Os, D=1 implies -O0) Optional 'OPTZ=-O2' will update gcc -O option (default is -Os, D=1 implies -O0)
Optional 'FORCE32=0' will use native/default gcc (default is FORCE32=1 unless gcc-multilib is not detected) Optional 'FORCE32=0' will use native/default gcc (default is FORCE32=1 unless gcc-multilib is not detected)
Optional 'R="<options>"' (ex: R="-b -v") runs the executable with given options after build
Non exhaustive list of working examples: Non exhaustive list of working examples:
make D=1 ../../libraries/ESP8266WiFi/examples/udp/udp make D=1 ../../libraries/ESP8266WiFi/examples/udp/udp
@ -64,7 +64,7 @@ Compile other sketches:
or: or:
ULIBDIRS=/path/to/your/arduino/libraries/lib1:/path/to/another/place/lib2 make D=1 /path/to/your/sketchdir/sketch/sketch ULIBDIRS=/path/to/your/arduino/libraries/lib1:/path/to/another/place/lib2 make D=1 /path/to/your/sketchdir/sketch/sketch
or (preferred): or:
export ULIBDIRS=/path/to/your/arduino/libraries/lib1:/path/to/another/place/lib2 export ULIBDIRS=/path/to/your/arduino/libraries/lib1:/path/to/another/place/lib2
export D=1 export D=1
export OPTZ=-O2 export OPTZ=-O2
@ -72,6 +72,12 @@ Compile other sketches:
make /path/to/your/sketchdir/sketch/sketch make /path/to/your/sketchdir/sketch/sketch
./bin/sketch/sketch ./bin/sketch/sketch
Additional flags:
make USERCFLAGS="-I some/where -I some/where/else" \
USERCSOURCES="some/where/file1.c some/where/file2.c ..." \
USERCXXSOURCES="some/where/file3.cpp some/where/file4.cpp ..." \
USERLDFLAGS="-L some/where/around" \
...
Executable location is always in bin/. Once a sketch is compiled, just run it: Executable location is always in bin/. Once a sketch is compiled, just run it:
bin/sketch/sketch bin/sketch/sketch