Makefile 3.98 KB
Newer Older
1
include ../py/mkenv.mk
2
-include mpconfigport.mk
3

4
# define main target
5
PROG = micropython
6

7
8
9
# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h

10
11
12
# OS name, for simple autoconfig
UNAME_S := $(shell uname -s)

13
14
# include py core make definitions
include ../py/py.mk
15

16
INC =  -I.
17
INC +=  -I..
18
INC += -I$(BUILD)
19

20
# compiler settings
21
CWARN = -Wall -Werror
22
CWARN += -Wpointer-arith -Wuninitialized
23
CFLAGS = $(INC) $(CWARN) -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA)
24

25
26
27
28
29
30
31
32
# Debugging/Optimization
ifdef DEBUG
CFLAGS += -g
COPT = -O0
else
COPT = -Os #-DNDEBUG
endif

33
34
35
36
# On OSX, 'gcc' is a symlink to clang unless a real gcc is installed.
# The unix port of micropython on OSX must be compiled with clang,
# while cross-compile ports require gcc, so we test here for OSX and 
# if necessary override the value of 'CC' set in py/mkenv.mk
blmorris's avatar
blmorris committed
37
38
ifeq ($(UNAME_S),Darwin)
CC = clang
39
40
# Use clang syntax for map file
LDFLAGS_ARCH = -Wl,-map,$@.map
41
else
42
43
# Use gcc syntax for map file
LDFLAGS_ARCH = -Wl,-Map=$@.map,--cref
blmorris's avatar
blmorris committed
44
endif
45
LDFLAGS = $(LDFLAGS_MOD) $(LDFLAGS_ARCH) -lm $(LDFLAGS_EXTRA)
46

47
ifeq ($(MICROPY_FORCE_32BIT),1)
48
49
# Note: you may need to install i386 versions of dependency packages,
# starting with linux-libc-dev:i386
50
51
CFLAGS += -m32
LDFLAGS += -m32
52
ifeq ($(MICROPY_PY_FFI),1)
53
54
55
56
57
58
ifeq ($(UNAME_S),Linux)
CFLAGS_MOD += -I/usr/include/i686-linux-gnu
endif
endif
endif

59
60
61
62
63
64
ifeq ($(MICROPY_USE_READLINE),1)
CFLAGS_MOD += -DMICROPY_USE_READLINE=1
LDFLAGS_MOD += -lreadline
# the following is needed for BSD
#LDFLAGS_MOD += -ltermcap
endif
65
66
ifeq ($(MICROPY_PY_TIME),1)
CFLAGS_MOD += -DMICROPY_PY_TIME=1
67
SRC_MOD += modtime.c
68
endif
69
70
71
72
ifeq ($(MICROPY_PY_TERMIOS),1)
CFLAGS_MOD += -DMICROPY_PY_TERMIOS=1
SRC_MOD += modtermios.c
endif
73
74
75
76
ifeq ($(MICROPY_PY_SOCKET),1)
CFLAGS_MOD += -DMICROPY_PY_SOCKET=1
SRC_MOD += modsocket.c
endif
77
ifeq ($(MICROPY_PY_FFI),1)
78
79
LIBFFI_LDFLAGS_MOD := $(shell pkg-config --libs libffi)
LIBFFI_CFLAGS_MOD := $(shell pkg-config --cflags libffi)
80
CFLAGS_MOD += $(LIBFFI_CFLAGS_MOD) -DMICROPY_PY_FFI=1
81
82
83
84
ifeq ($(UNAME_S),Linux)
LDFLAGS_MOD += -ldl
endif
LDFLAGS_MOD += $(LIBFFI_LDFLAGS_MOD)
85
SRC_MOD += modffi.c
86
87
endif

88

89
# source files
90
91
SRC_C = \
	main.c \
92
	gccollect.c \
Dave Hylands's avatar
Dave Hylands committed
93
	input.c \
94
	file.c \
95
	modos.c \
96
	alloc.c \
97
	coverage.c \
98
	$(SRC_MOD)
99

blmorris's avatar
blmorris committed
100

101
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
102

103
include ../py/mkrules.mk
104

105
106
107
108
.PHONY: test

test: $(PROG) ../tests/run-tests
	$(eval DIRNAME=$(notdir $(CURDIR)))
109
	cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests
Sebastian Plamauer's avatar
Sebastian Plamauer committed
110
111
112
113
114

# install micropython in /usr/local/bin
TARGET = micropython
PREFIX = $(DESTDIR)/usr/local
BINDIR = $(PREFIX)/bin
115
116
PIPSRC = ../tools/pip-micropython
PIPTARGET = pip-micropython
Sebastian Plamauer's avatar
Sebastian Plamauer committed
117
118
119

install: micropython
	install -D $(TARGET) $(BINDIR)/$(TARGET)
120
	install -D $(PIPSRC) $(BINDIR)/$(PIPTARGET)
Sebastian Plamauer's avatar
Sebastian Plamauer committed
121
122
123
124

# uninstall micropython
uninstall:
	-rm $(BINDIR)/$(TARGET)
125
	-rm $(BINDIR)/$(PIPTARGET)
126
127
128

# build synthetically fast interpreter for benchmarking
fast:
129
130
131
132
133
	$(MAKE) COPT="-O2 -DNDEBUG -fno-crossjumping" CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_fast.h>"' BUILD=build-fast PROG=micropython_fast

# build a minimal interpreter
minimal:
	$(MAKE) COPT="-Os -DNDEBUG" CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_minimal.h>"' BUILD=build-minimal PROG=micropython_minimal MICROPY_PY_TIME=0 MICROPY_PY_TERMIOS=0 MICROPY_PY_SOCKET=0 MICROPY_PY_FFI=0
134
135
136

# build an interpreter for coverage testing and do the testing
coverage:
137
	$(MAKE) COPT="-O0" CFLAGS_EXTRA='-fprofile-arcs -ftest-coverage -Wdouble-promotion -Wformat -Wmissing-declarations -Wmissing-prototypes -Wold-style-definition -Wpointer-arith -Wshadow -Wsign-compare -Wuninitialized -Wunused-parameter -DMICROPY_UNIX_COVERAGE' LDFLAGS_EXTRA='-fprofile-arcs -ftest-coverage' BUILD=build-coverage PROG=micropython_coverage
138
139

coverage_test: coverage
140
141
	$(eval DIRNAME=$(notdir $(CURDIR)))
	cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests
142
	cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests --emit native
143
	gcov -o build-coverage/py ../py/*.c
144
	gcov -o build-coverage/extmod ../extmod/*.c