py.mk 8.18 KB
Newer Older
1
# where py object files go (they have a name prefix to prevent filename clashes)
2
PY_BUILD = $(BUILD)/py
3

4
# where autogenerated header files go
5
HEADER_BUILD = $(BUILD)/genhdr
6

7
# file containing qstr defs for the core Python bit
8
9
PY_QSTR_DEFS = $(PY_SRC)/qstrdefs.h

10
11
12
# If qstr autogeneration is not disabled we specify the output header
# for all collected qstrings.
ifneq ($(QSTR_AUTOGEN_DISABLE),1)
13
QSTR_DEFS_COLLECTED = $(HEADER_BUILD)/qstrdefs.collected.h
14
endif
15

16
17
18
# some code is performance bottleneck and compiled with other optimization options
CSUPEROPT = -O3

19
INC += -I../lib
20
21
INC += -I../lib/netutils

22
23
24
# this sets the config file for FatFs
CFLAGS_MOD += -DFFCONF_H=\"lib/oofatfs/ffconf.h\"

25
ifeq ($(MICROPY_PY_USSL),1)
26
27
28
CFLAGS_MOD += -DMICROPY_PY_USSL=1
ifeq ($(MICROPY_SSL_AXTLS),1)
CFLAGS_MOD += -DMICROPY_SSL_AXTLS=1 -I../lib/axtls/ssl -I../lib/axtls/crypto -I../lib/axtls/config
29
LDFLAGS_MOD += -Lbuild -laxtls
30
31
32
33
34
else ifeq ($(MICROPY_SSL_MBEDTLS),1)
# Can be overriden by ports which have "builtin" mbedTLS
MICROPY_SSL_MBEDTLS_INCLUDE ?= ../lib/mbedtls/include
CFLAGS_MOD += -DMICROPY_SSL_MBEDTLS=1 -I$(MICROPY_SSL_MBEDTLS_INCLUDE)
LDFLAGS_MOD += -L../lib/mbedtls/library -lmbedx509 -lmbedtls -lmbedcrypto
35
endif
36
endif
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifeq ($(MICROPY_PY_LWIP),1)
#CFLAGS_MOD += -DMICROPY_PY_LWIP=1 -I../lib/lwip/src/include -I../lib/lwip/src/include/ipv4 -I../extmod/lwip-include
#endif

ifeq ($(MICROPY_PY_LWIP),1)
LWIP_DIR = lib/lwip/src
INC += -I../lib/lwip/src/include -I../lib/lwip/src/include/ipv4 -I../extmod/lwip-include
CFLAGS_MOD += -DMICROPY_PY_LWIP=1
SRC_MOD += extmod/modlwip.c lib/netutils/netutils.c
SRC_MOD += $(addprefix $(LWIP_DIR)/,\
	core/def.c \
	core/dns.c \
	core/init.c \
	core/mem.c \
	core/memp.c \
	core/netif.c \
	core/pbuf.c \
	core/raw.c \
	core/stats.c \
	core/sys.c \
	core/tcp.c \
	core/tcp_in.c \
	core/tcp_out.c \
	core/timers.c \
	core/udp.c \
	core/ipv4/autoip.c \
	core/ipv4/icmp.c \
	core/ipv4/igmp.c \
	core/ipv4/inet.c \
	core/ipv4/inet_chksum.c \
	core/ipv4/ip_addr.c \
	core/ipv4/ip.c \
	core/ipv4/ip_frag.c \
	)
ifeq ($(MICROPY_PY_LWIP_SLIP),1)
CFLAGS_MOD += -DMICROPY_PY_LWIP_SLIP=1
SRC_MOD += $(LWIP_DIR)/netif/slipif.c
endif
endif

78
79
ifeq ($(MICROPY_PY_BTREE),1)
BTREE_DIR = lib/berkeley-db-1.xx
80
CFLAGS_MOD += -D__DBINTERFACE_PRIVATE=1 -Dmpool_error=printf -Dabort=abort_ -Dvirt_fd_t=mp_obj_t "-DVIRT_FD_T_HEADER=<py/obj.h>"
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
INC += -I../$(BTREE_DIR)/PORT/include
SRC_MOD += extmod/modbtree.c
SRC_MOD += $(addprefix $(BTREE_DIR)/,\
btree/bt_close.c \
btree/bt_conv.c \
btree/bt_debug.c \
btree/bt_delete.c \
btree/bt_get.c \
btree/bt_open.c \
btree/bt_overflow.c \
btree/bt_page.c \
btree/bt_put.c \
btree/bt_search.c \
btree/bt_seq.c \
btree/bt_split.c \
btree/bt_utils.c \
mpool/mpool.c \
	)
CFLAGS_MOD += -DMICROPY_PY_BTREE=1
100
101
# we need to suppress certain warnings to get berkeley-db to compile cleanly
$(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter
102
103
endif

104
105
# py object files
PY_O_BASENAME = \
106
	mpstate.o \
107
108
109
	nlrx86.o \
	nlrx64.o \
	nlrthumb.o \
110
	nlrxtensa.o \
111
	nlrsetjmp.o \
112
	malloc.o \
113
	gc.o \
114
115
	qstr.o \
	vstr.o \
116
	mpprint.o \
117
	unicode.o \
118
	mpz.o \
119
	reader.o \
120
121
122
123
124
125
	lexer.o \
	parse.o \
	scope.o \
	compile.o \
	emitcommon.o \
	emitbc.o \
126
	asmbase.o \
127
128
	asmx64.o \
	emitnx64.o \
129
130
	asmx86.o \
	emitnx86.o \
131
132
133
	asmthumb.o \
	emitnthumb.o \
	emitinlinethumb.o \
Fabian Vogt's avatar
Fabian Vogt committed
134
135
	asmarm.o \
	emitnarm.o \
136
137
	asmxtensa.o \
	emitnxtensa.o \
138
	emitinlinextensa.o \
139
	formatfloat.o \
140
	parsenumbase.o \
141
	parsenum.o \
142
	emitglue.o \
143
	persistentcode.o \
144
	runtime.o \
145
	runtime_utils.o \
146
	nativeglue.o \
147
	stackctrl.o \
148
	argcheck.o \
149
	warning.o \
150
151
	map.o \
	obj.o \
152
	objarray.o \
153
	objattrtuple.o \
154
155
156
157
158
159
	objbool.o \
	objboundmeth.o \
	objcell.o \
	objclosure.o \
	objcomplex.o \
	objdict.o \
John R. Lenton's avatar
John R. Lenton committed
160
	objenumerate.o \
161
	objexcept.o \
John R. Lenton's avatar
John R. Lenton committed
162
	objfilter.o \
163
164
165
	objfloat.o \
	objfun.o \
	objgenerator.o \
166
	objgetitemiter.o \
167
	objint.o \
168
	objint_longlong.o \
169
	objint_mpz.o \
170
	objlist.o \
John R. Lenton's avatar
John R. Lenton committed
171
	objmap.o \
172
	objmodule.o \
Damien George's avatar
Damien George committed
173
	objobject.o \
174
	objpolyiter.o \
175
	objproperty.o \
176
	objnone.o \
177
	objnamedtuple.o \
178
	objrange.o \
179
	objreversed.o \
180
	objset.o \
181
	objsingleton.o \
182
183
	objslice.o \
	objstr.o \
184
	objstrunicode.o \
185
	objstringio.o \
186
187
	objtuple.o \
	objtype.o \
188
	objzip.o \
189
	opmethods.o \
190
	sequence.o \
191
	stream.o \
192
	binary.o \
193
	builtinimport.o \
Damien George's avatar
Damien George committed
194
	builtinevex.o \
195
	builtinhelp.o \
196
	modarray.o \
197
	modbuiltins.o \
198
	modcollections.o \
199
	modgc.o \
Paul Sokolovsky's avatar
Paul Sokolovsky committed
200
	modio.o \
201
	modmath.o \
202
	modcmath.o \
203
	modmicropython.o \
204
	modstruct.o \
205
	modsys.o \
206
	moduerrno.o \
207
	modthread.o \
208
	vm.o \
209
	bc.o \
210
211
	showbc.o \
	repl.o \
212
	smallint.o \
213
	frozenmod.o \
214
	../extmod/moductypes.o \
215
	../extmod/modujson.o \
216
	../extmod/modure.o \
217
	../extmod/moduzlib.o \
Damien George's avatar
Damien George committed
218
	../extmod/moduheapq.o \
219
	../extmod/modutimeq.o \
220
	../extmod/moduhashlib.o \
221
	../extmod/modubinascii.o \
222
	../extmod/virtpin.o \
223
	../extmod/machine_mem.o \
224
	../extmod/machine_pinbase.o \
225
	../extmod/machine_signal.o \
226
	../extmod/machine_pulse.o \
227
	../extmod/machine_i2c.o \
228
	../extmod/machine_spi.o \
229
	../extmod/modussl_axtls.o \
230
	../extmod/modussl_mbedtls.o \
231
	../extmod/modurandom.o \
232
	../extmod/moduselect.o \
233
	../extmod/modwebsocket.o \
234
	../extmod/modwebrepl.o \
235
	../extmod/modframebuf.o \
236
	../extmod/fsusermount.o \
237
238
	../extmod/vfs.o \
	../extmod/vfs_reader.o \
Paul Sokolovsky's avatar
Paul Sokolovsky committed
239
	../extmod/vfs_fat.o \
240
	../extmod/vfs_fat_ffconf.o \
241
	../extmod/vfs_fat_diskio.o \
242
	../extmod/vfs_fat_file.o \
243
	../extmod/vfs_fat_reader.o \
244
	../extmod/vfs_fat_misc.o \
245
	../extmod/utime_mphal.o \
246
	../extmod/uos_dupterm.o \
247
	../lib/embed/abort_.o \
248
	../lib/utils/printf.o \
249
250

# prepend the build destination prefix to the py object files
251
PY_O = $(addprefix $(PY_BUILD)/, $(PY_O_BASENAME))
252

253
# object file for frozen files
254
255
256
257
ifneq ($(FROZEN_DIR),)
PY_O += $(BUILD)/$(BUILD)/frozen.o
endif

258
259
260
261
262
# object file for frozen bytecode (frozen .mpy files)
ifneq ($(FROZEN_MPY_DIR),)
PY_O += $(BUILD)/$(BUILD)/frozen_mpy.o
endif

263
# Sources that may contain qstrings
264
SRC_QSTR_IGNORE = nlr% emitnx86% emitnx64% emitnthumb% emitnarm% emitnxtensa%
265
266
SRC_QSTR = $(SRC_MOD) $(addprefix py/,$(filter-out $(SRC_QSTR_IGNORE),$(PY_O_BASENAME:.o=.c)) emitnative.c)

267
268
269
270
# Anything that depends on FORCE will be considered out-of-date
FORCE:
.PHONY: FORCE

271
272
$(HEADER_BUILD)/mpversion.h: FORCE | $(HEADER_BUILD)
	$(Q)$(PYTHON) $(PY_SRC)/makeversionhdr.py $@
273

274
275
276
277
# mpconfigport.mk is optional, but changes to it may drastically change
# overall config, so they need to be caught
MPCONFIGPORT_MK = $(wildcard mpconfigport.mk)

278
# qstr data
279
# Adding an order only dependency on $(HEADER_BUILD) causes $(HEADER_BUILD) to get
280
# created before we run the script to generate the .h
281
282
# Note: we need to protect the qstr names from the preprocessor, so we wrap
# the lines in "" and then unwrap after the preprocessor is finished.
283
$(HEADER_BUILD)/qstrdefs.generated.h: $(PY_QSTR_DEFS) $(QSTR_DEFS) $(QSTR_DEFS_COLLECTED) $(PY_SRC)/makeqstrdata.py mpconfigport.h $(MPCONFIGPORT_MK) $(PY_SRC)/mpconfig.h | $(HEADER_BUILD)
284
	$(ECHO) "GEN $@"
285
	$(Q)cat $(PY_QSTR_DEFS) $(QSTR_DEFS) $(QSTR_DEFS_COLLECTED) | $(SED) 's/^Q(.*)/"&"/' | $(CPP) $(CFLAGS) - | $(SED) 's/^"\(Q(.*)\)"/\1/' > $(HEADER_BUILD)/qstrdefs.preprocessed.h
286
	$(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@
287

288
# emitters
289

290
291
292
$(PY_BUILD)/emitnx64.o: CFLAGS += -DN_X64
$(PY_BUILD)/emitnx64.o: py/emitnative.c
	$(call compile_c)
293

294
295
296
297
$(PY_BUILD)/emitnx86.o: CFLAGS += -DN_X86
$(PY_BUILD)/emitnx86.o: py/emitnative.c
	$(call compile_c)

298
299
300
$(PY_BUILD)/emitnthumb.o: CFLAGS += -DN_THUMB
$(PY_BUILD)/emitnthumb.o: py/emitnative.c
	$(call compile_c)
301

Fabian Vogt's avatar
Fabian Vogt committed
302
303
304
305
$(PY_BUILD)/emitnarm.o: CFLAGS += -DN_ARM
$(PY_BUILD)/emitnarm.o: py/emitnative.c
	$(call compile_c)

306
307
308
309
$(PY_BUILD)/emitnxtensa.o: CFLAGS += -DN_XTENSA
$(PY_BUILD)/emitnxtensa.o: py/emitnative.c
	$(call compile_c)

310
# optimising gc for speed; 5ms down to 4ms on pybv2
311
$(PY_BUILD)/gc.o: CFLAGS += $(CSUPEROPT)
312

313
# optimising vm for speed, adds only a small amount to code size but makes a huge difference to speed (20% faster)
314
$(PY_BUILD)/vm.o: CFLAGS += $(CSUPEROPT)
315
316
317
318
319
320
321
322
# Optimizing vm.o for modern deeply pipelined CPUs with branch predictors
# may require disabling tail jump optimization. This will make sure that
# each opcode has its own dispatching jump which will improve branch
# branch predictor efficiency.
# http://article.gmane.org/gmane.comp.lang.lua.general/75426
# http://hg.python.org/cpython/file/b127046831e2/Python/ceval.c#l828
# http://www.emulators.com/docs/nx25_nostradamus.htm
#-fno-crossjumping