Skip to content

Commit 2d1f865

Browse files
committed
Merge branch 'relocatable-build-dir' of github.com:lurch/micropython into lurch-relocatable-build-dir
2 parents eeffbb6 + 70a7d7a commit 2d1f865

11 files changed

Lines changed: 64 additions & 26 deletions

File tree

bare-arm/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ include ../py/py.mk
88

99
CROSS_COMPILE = arm-none-eabi-
1010

11+
INC = -I.
12+
INC += -I$(PY_SRC)
13+
INC += -I$(BUILD)/includes
14+
1115
CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion
12-
CFLAGS = -I. -I$(PY_SRC) -Wall -Werror -ansi -std=gnu99 $(CFLAGS_CORTEX_M4) $(COPT)
16+
CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 $(CFLAGS_CORTEX_M4) $(COPT)
1317

1418
#Debugging/Optimization
1519
ifeq ($(DEBUG), 1)

py/mkrules.mk

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,16 @@ $(BUILD)/%.pp: %.c
5959
# object directories (but only for existance), and the object directories
6060
# will be created if they don't exist.
6161
OBJ_DIRS = $(sort $(dir $(OBJ)))
62-
$(OBJ): $(PY_BUILD)/qstrdefs.generated.h | $(OBJ_DIRS)
62+
$(OBJ): $(HEADER_PY_BUILD)/qstrdefs.generated.h | $(OBJ_DIRS)
6363
$(OBJ_DIRS):
6464
$(MKDIR) -p $@
6565

66+
$(HEADER_BUILD):
67+
$(MKDIR) -p $@
68+
69+
$(HEADER_PY_BUILD):
70+
$(MKDIR) -p $@
71+
6672
ifneq ($(PROG),)
6773
# Build a standalone executable (unix and unix-cpy do this)
6874

py/py.mk

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# where py object files go (they have a name prefix to prevent filename clashes)
22
PY_BUILD = $(BUILD)/py
33

4-
# file containing qstr defs for the core Python bit
4+
# where autogenerated header files go
5+
HEADER_BUILD = $(BUILD)/includes/build
6+
7+
# where autogenerated py header files go
8+
HEADER_PY_BUILD = $(HEADER_BUILD)/py
59

10+
# file containing qstr defs for the core Python bit
611
PY_QSTR_DEFS = $(PY_SRC)/qstrdefs.h
712

813
# py object files
@@ -100,26 +105,25 @@ PY_O = $(addprefix $(PY_BUILD)/, $(PY_O_BASENAME))
100105
FORCE:
101106
.PHONY: FORCE
102107

103-
$(PY_BUILD)/py-version.h: FORCE
108+
$(HEADER_PY_BUILD)/py-version.h: FORCE
104109
$(Q)$(PY_SRC)/py-version.sh > $@.tmp
105110
$(Q)if [ -f "$@" ] && cmp -s $@ $@.tmp; then rm $@.tmp; else echo "Generating $@"; mv $@.tmp $@; fi
106111

107112
# qstr data
108113

109-
# Adding an order only dependency on $(PY_BUILD) causes $(PY_BUILD) to get
114+
# Adding an order only dependency on $(HEADER_PY_BUILD) causes $(HEADER_PY_BUILD) to get
110115
# created before we run the script to generate the .h
111-
$(PY_BUILD)/qstrdefs.generated.h: | $(PY_BUILD)/
112-
$(PY_BUILD)/qstrdefs.generated.h: $(PY_QSTR_DEFS) $(QSTR_DEFS) $(PY_SRC)/makeqstrdata.py mpconfigport.h $(PY_SRC)/mpconfig.h
116+
$(HEADER_PY_BUILD)/qstrdefs.generated.h: $(PY_QSTR_DEFS) $(QSTR_DEFS) $(PY_SRC)/makeqstrdata.py mpconfigport.h $(PY_SRC)/mpconfig.h | $(HEADER_PY_BUILD)
113117
$(ECHO) "makeqstrdata $(PY_QSTR_DEFS) $(QSTR_DEFS)"
114-
$(CPP) $(CFLAGS) $(PY_QSTR_DEFS) -o $(PY_BUILD)/qstrdefs.preprocessed.h
115-
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py $(PY_BUILD)/qstrdefs.preprocessed.h $(QSTR_DEFS) > $@
118+
$(CPP) $(CFLAGS) $(PY_QSTR_DEFS) -o $(HEADER_PY_BUILD)/qstrdefs.preprocessed.h
119+
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py $(HEADER_PY_BUILD)/qstrdefs.preprocessed.h $(QSTR_DEFS) > $@
116120

117121
# We don't know which source files actually need the generated.h (since
118122
# it is #included from str.h). The compiler generated dependencies will cause
119123
# the right .o's to get recompiled if the generated.h file changes. Adding
120124
# an order-only dependendency to all of the .o's will cause the generated .h
121125
# to get built before we try to compile any of them.
122-
$(PY_O): | $(PY_BUILD)/qstrdefs.generated.h $(PY_BUILD)/py-version.h
126+
$(PY_O): | $(HEADER_PY_BUILD)/qstrdefs.generated.h $(HEADER_PY_BUILD)/py-version.h
123127

124128
# emitters
125129

py/qstr.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ const static qstr_pool_t const_pool = {
6060
(const byte*) "\0\0\0\0", // invalid/no qstr has empty data
6161
(const byte*) "\0\0\0\0", // empty qstr
6262
#define Q(id, str) str,
63-
// TODO having 'build/' here is a bit of a hack, should take config variable from Makefile
6463
#include "build/py/qstrdefs.generated.h"
6564
#undef Q
6665
},

py/qstr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ enum {
88
MP_QSTR_NULL = 0, // indicates invalid/no qstr
99
MP_QSTR_ = 1, // the empty qstr
1010
#define Q(id, str) MP_QSTR_##id,
11-
// TODO having 'build/py.' here is a bit of a hack, should take config variable from Makefile
1211
#include "build/py/qstrdefs.generated.h"
1312
#undef Q
1413
MP_QSTR_number_of,

stm/Makefile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@ DFU=../tools/dfu.py
1717

1818
CROSS_COMPILE = arm-none-eabi-
1919

20+
INC = -I.
21+
INC += -I$(PY_SRC)
22+
INC += -I$(BUILD)/includes
23+
INC += -I$(CMSIS_DIR)
24+
INC += -I$(STMPERIPH_DIR)
25+
INC += -I$(STMUSB_DIR)
26+
INC += -I$(STMUSBD_DIR)
27+
INC += -I$(STMUSBH_DIR)
28+
INC += -I$(FATFS_DIR)
29+
#INC += -I$(CC3K_DIR)
30+
2031
CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion
21-
CFLAGS = -I. -I$(PY_SRC) -I$(CMSIS_DIR) -I$(STMPERIPH_DIR) -I$(STMUSB_DIR) -Wall -Werror -ansi -std=gnu99 $(CFLAGS_CORTEX_M4) $(COPT)
22-
CFLAGS += -I$(STMUSBD_DIR)
23-
CFLAGS += -I$(STMUSBH_DIR)
24-
CFLAGS += -I$(FATFS_DIR)
25-
#CFLAGS += -I$(CC3K_DIR)
32+
CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 $(CFLAGS_CORTEX_M4) $(COPT)
2633

2734
BOARD ?= PYBOARD4
2835
ifeq ($(wildcard boards/$(BOARD)/.),)

stmhal/Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ CROSS_COMPILE = arm-none-eabi-
1818

1919
INC = -I.
2020
INC += -I$(PY_SRC)
21+
INC += -I$(BUILD)/includes
2122
INC += -I$(CMSIS_DIR)/inc
2223
INC += -I$(CMSIS_DIR)/devinc
2324
INC += -I$(HAL_DIR)/inc
@@ -208,28 +209,28 @@ BOARD_PINS = boards/$(BOARD)/pins.csv
208209
AF_FILE = boards/stm32f4xx-af.csv
209210
PREFIX_FILE = boards/stm32f4xx-prefix.c
210211
GEN_PINS_SRC = $(BUILD)/pins_$(BOARD).c
211-
GEN_PINS_HDR = $(BUILD)/pins.h
212+
GEN_PINS_HDR = $(HEADER_BUILD)/pins.h
212213

213214
INSERT_USB_IDS = ../tools/insert-usb-ids.py
214215
FILE2H = ../tools/file2h.py
215216

216217
USB_IDS_FILE = usbd_desc_cdc_msc.c
217218
CDCINF_TEMPLATE = pybcdc.inf_template
218-
GEN_CDCINF_FILE = $(BUILD)/pybcdc.inf
219-
GEN_CDCINF_HEADER = $(BUILD)/pybcdc_inf.h
219+
GEN_CDCINF_FILE = $(HEADER_BUILD)/pybcdc.inf
220+
GEN_CDCINF_HEADER = $(HEADER_BUILD)/pybcdc_inf.h
220221

221222
# Making OBJ use an order-only depenedency on the generated pins.h file
222223
# has the side effect of making the pins.h file before we actually compile
223224
# any of the objects. The normal dependency generation will deal with the
224225
# case when pins.h is modified. But when it doesn't exist, we don't know
225226
# which source files might need it.
226-
$(OBJ): | $(BUILD)/pins.h
227+
$(OBJ): | $(HEADER_BUILD)/pins.h
227228

228229
$(BUILD)/main.o: $(GEN_CDCINF_HEADER)
229230

230231
# Use a pattern rule here so that make will only call make-pins.py once to make
231232
# both pins_$(BOARD).c and pins.h
232-
$(BUILD)/%_$(BOARD).c $(BUILD)/%.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE)
233+
$(BUILD)/%_$(BOARD).c $(HEADER_BUILD)/%.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE)
233234
$(ECHO) "Create $@"
234235
$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) > $(GEN_PINS_SRC)
235236

teensy/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ CROSS_COMPILE = $(COMPILER_PATH)/arm-none-eabi-
1717

1818
CFLAGS_TEENSY = -DF_CPU=96000000 -DUSB_SERIAL -D__MK20DX256__
1919
CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -fsingle-precision-constant -Wdouble-promotion $(CFLAGS_TEENSY)
20-
CFLAGS = -I. -I$(PY_SRC) -I$(CORE_PATH) -Wall -ansi -std=gnu99 $(CFLAGS_CORTEX_M4)
20+
21+
INC = -I.
22+
INC += -I$(PY_SRC)
23+
INC += -I$(BUILD)/includes
24+
INC += -I$(CORE_PATH)
25+
26+
CFLAGS = $(INC) -Wall -ansi -std=gnu99 $(CFLAGS_CORTEX_M4)
2127
LDFLAGS = -nostdlib -T mk20dx256.ld
2228
LIBS = -L $(COMPILER_PATH)/../lib/gcc/arm-none-eabi/4.7.2/thumb2 -lgcc
2329

unix-cpy/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ PROG = cpy
66
# include py core make definitions
77
include ../py/py.mk
88

9+
INC = -I.
10+
INC += -I$(PY_SRC)
11+
INC += -I$(BUILD)/includes
12+
913
# compiler settings
10-
CFLAGS = -I. -I$(PY_SRC) -Wall -Werror -ansi -std=gnu99 -DUNIX
14+
CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 -DUNIX
1115
LDFLAGS = -lm
1216

1317
# Debugging/Optimization

unix/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ QSTR_DEFS = qstrdefsport.h
1010
# include py core make definitions
1111
include ../py/py.mk
1212

13+
INC = -I.
14+
INC += -I$(PY_SRC)
15+
INC += -I$(BUILD)/includes
16+
1317
# compiler settings
14-
CFLAGS = -I. -I$(PY_SRC) -Wall -Werror -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT)
18+
CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT)
1519

1620
UNAME_S := $(shell uname -s)
1721
ifeq ($(UNAME_S),Darwin)

0 commit comments

Comments
 (0)