Skip to content

Commit c7bc146

Browse files
committed
makefile: sketch object and cpp file moved to bin/ directories
easier to clean, and IDE don't like them
1 parent 8bf7b01 commit c7bc146

File tree

2 files changed

+52
-41
lines changed

2 files changed

+52
-41
lines changed

tests/host/Makefile

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ CORE_PATH := ../../cores/esp8266
55
FORCE32 ?= 1
66
OPTZ ?= -Os
77

8+
MAKEFILE = $(word 1, $(MAKEFILE_LIST))
9+
810
# I wasn't able to build with clang when -coverage flag is enabled, forcing GCC on OS X
911
ifeq ($(shell uname -s),Darwin)
1012
CC ?= gcc
@@ -167,6 +169,7 @@ build-info: # show toolchain version
167169
%.c.o: %.c
168170
$(CC) $(PREINCLUDES) $(CFLAGS) $(INC_PATHS) -MD -MF $(BINDIR)/.$(notdir $<).d -c -o $@ $<
169171

172+
.PRECIOUS: %.cpp.o
170173
%.cpp.o: %.cpp
171174
$(CXX) $(PREINCLUDES) $(CXXFLAGS) $(INC_PATHS) -MD -MF $(BINDIR)/.$(notdir $<).d -c -o $@ $<
172175

@@ -231,10 +234,6 @@ CPP_SOURCES_CORE_EMU = \
231234
$(ARDUINO_LIBS) \
232235

233236

234-
ULIBPATHS = $(shell echo $(ULIBDIRS) | sed 's,:, ,g')
235-
USERLIBDIRS = $(shell test -z "$(ULIBPATHS)" || for d in $(ULIBPATHS); do for dd in $$d/* $$d/*/src; do test -d $$dd && echo -I$$dd || echo "WARNING: '$$dd' is not a directory" 1>&2; done; done)
236-
INC_PATHS += $(USERLIBDIRS)
237-
238237
LIBSSLFILE = ../../tools/sdk/ssl/bearssl/build$(N32)/libbearssl.a
239238
ifeq (,$(wildcard $(LIBSSLFILE)))
240239
LIBSSL =
@@ -244,31 +243,60 @@ endif
244243
ssl: # download source and build BearSSL
245244
cd ../../tools/sdk/ssl && make native$(N32)
246245

247-
CPP_OBJECTS_CORE_EMU = $(CPP_SOURCES_CORE_EMU:.cpp=.cpp.o) $(USERLIB:.cpp=.cpp.o)
246+
ULIBPATHS = $(shell echo $(ULIBDIRS) | sed 's,:, ,g')
247+
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)
248+
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)
249+
INC_PATHS += $(USERLIBDIRS)
250+
CPP_OBJECTS_CORE_EMU = $(CPP_SOURCES_CORE_EMU:.cpp=.cpp.o) $(USERLIBSRCS:.cpp=.cpp.o)
248251

249252
bin/fullcore.a: $(C_OBJECTS) $(CPP_OBJECTS_CORE_EMU)
250253
ar -rcu $@ $^
251254
ranlib -c $@
252255

253-
.PRECIOUS: %.cpp.o
254256
%: %.ino.cpp.o bin/fullcore.a
255257
$(CXX) $(LDFLAGS) $< bin/fullcore.a $(LIBSSL) -o $@
256-
test -r $@ && ln -sf ../$@ $(BINDIR) || ln -sf $@ $(BINDIR)
257-
258-
#.PRECIOUS: %.ino.cpp
259-
%.ino.cpp: %.ino
260-
@s=$<; \
261-
n=$${s##*/}; \
262-
(cd $${s%/*}; \
263-
echo "#include \"$$n\""; \
264-
for i in *.ino; do \
265-
test "$$i" = "$$n" || echo "#include \"$$i\""; \
266-
done; \
267-
) > $@
258+
@echo "----> $@ <----"
259+
260+
#################################################
261+
# are we in primary make call ?
262+
ifeq ($(INO),)
263+
264+
%: %.ino
265+
@# recursive 'make' with paths
266+
$(MAKE) -f $(MAKEFILE) INODIR=$(dir $@) INO=$(notdir $@) $(BINDIR)/$(notdir $@)/$(notdir $@)
267+
@# see below the new build rule with fixed output path outside from core location
268+
269+
#####################
270+
# recursive call on ino targer
271+
else
272+
273+
$(BINDIR)/$(INO)/$(INO).ino.cpp:
274+
@# arduino builder would come around here (.ino -> .ino.cpp)
275+
@mkdir -p $(BINDIR)/$(INO); \
276+
( \
277+
echo "#include \"$(INODIR)/$(INO).ino\""; \
278+
for i in $(INODIR)/*.ino; do \
279+
test "$$i" = $(INODIR)/$(INO).ino || echo "#include \"$$i\""; \
280+
done; \
281+
) > $(BINDIR)/$(INO)/$(INO).ino.cpp
282+
283+
endif # recursive
284+
#####################
285+
286+
#################################################
287+
# (debug)
288+
289+
# https://lists.gnu.org/archive/html/help-make/2002-11/msg00062.html
290+
# Bad gmake, never *ever* try to get a file out of source control by yourself.
291+
#%: %,v
292+
#%: RCS/%,v
293+
#%: RCS/%
294+
#%: s.%
295+
#%: SCCS/s.%
296+
297+
#Makefile: ;
268298

269299
#################################################
270-
# Makefile.inc.ino generation
271-
-include $(BINDIR)/Makefile.inc.ino
272300

273301
.PHONY: list
274302
list: # show core example list
@@ -281,26 +309,9 @@ list: # show core example list
281309
done; \
282310
done; \
283311

284-
$(BINDIR)/Makefile.inc.ino:
285-
@all=""; \
286-
for dir in ../../libraries/*/examples; do \
287-
exampledir=$${dir%/*}; \
288-
exampledirname=$${exampledir##*/}; \
289-
for subdir in $$dir/*; do \
290-
exname=$${subdir##*/}; \
291-
all="$$all $$subdir/$$exname"; \
292-
done; \
293-
done; \
294-
echo "examples: $$all" > $@
295-
296-
examples: $(BINDIR)/Makefile.inc.ino # build all core examples
297-
$(MAKE) $@
298-
299312
#################################################
300313
# help
301314

302-
MAKEFILE = $(word 1, $(MAKEFILE_LIST))
303-
304315
.PHONY: help
305316
help:
306317
@cat README.txt

tests/host/README.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ instead.
2222
How to compile a sketch
2323
-----------------------
2424

25-
All results are stored or linked from ./bin/ .
25+
All results are stored in ./bin/ .
2626

2727
Show the core example list:
2828
make list
@@ -50,11 +50,11 @@ Compile other sketches:
5050
- call 'make path-to-the-sketch-file' to build (without its '.ino' extension):
5151
- CAVEAT: functions must be declared *before* being called (arduino builder is not around)
5252

53-
make D=1 ULIBDIRS=/path/to/your/arduino/libraries:/path/to/another/one /path/to/your/sketchdir/sketch/sketch
53+
make D=1 ULIBDIRS=/path/to/your/arduino/libraries/lib1:/path/to/another/place/lib2 /path/to/your/sketchdir/sketch/sketch
5454
or
55-
ULIBDIRS=/path/to/your/arduino/libraries:/path/to/another/one make D=1 /path/to/your/sketchdir/sketch/sketch
55+
ULIBDIRS=/path/to/your/arduino/libraries/lib1:/path/to/another/place/lib2 make D=1 /path/to/your/sketchdir/sketch/sketch
5656
or
57-
export ULIBDIRS=/path/to/your/arduino/libraries:/path/to/another/one
57+
export ULIBDIRS=/path/to/your/arduino/libraries/lib1:/path/to/another/place/lib2
5858
make D=1 /path/to/your/sketchdir/sketch/sketch
5959

6060

0 commit comments

Comments
 (0)