Makefile 3.27 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$(PY_SRC)
19
INC += -I$(BUILD)
20

21
# compiler settings
22
CWARN = -Wall -Wpointer-arith -Werror
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 and set osx specific flags
LDFLAGS_ARCH = -Wl,-order_file,$(BUILD)/order.def -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
ifeq ($(MICROPY_PY_FFI),1)
74
75
LIBFFI_LDFLAGS_MOD := $(shell pkg-config --libs libffi)
LIBFFI_CFLAGS_MOD := $(shell pkg-config --cflags libffi)
76
CFLAGS_MOD += $(LIBFFI_CFLAGS_MOD) -DMICROPY_PY_FFI=1
77
78
79
80
ifeq ($(UNAME_S),Linux)
LDFLAGS_MOD += -ldl
endif
LDFLAGS_MOD += $(LIBFFI_LDFLAGS_MOD)
81
SRC_MOD += modffi.c
82
83
endif

84

85
# source files
86
87
SRC_C = \
	main.c \
88
	gccollect.c \
Dave Hylands's avatar
Dave Hylands committed
89
	input.c \
90
	file.c \
91
	modsocket.c \
92
	modos.c \
93
	alloc.c \
94
	$(SRC_MOD)
95

96
ifeq ($(UNAME_S),Darwin)
97
# Must be the last file in list of sources
98
SRC_C += seg_helpers.c
99
100
101
102
103
104
105

# making seg_helpers.c rely on order.def will force order.def to be created
seg_helpers.c: $(BUILD)/order.def

# create order.def in build directory
$(BUILD)/order.def:
	$(Q)echo "seg_helpers.o: ___bss_start" > $@
106
endif
blmorris's avatar
blmorris committed
107

108
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
109

110
include ../py/mkrules.mk
111

112
113
114
115
.PHONY: test

test: $(PROG) ../tests/run-tests
	$(eval DIRNAME=$(notdir $(CURDIR)))
116
	cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests
Sebastian Plamauer's avatar
Sebastian Plamauer committed
117
118
119
120
121

# install micropython in /usr/local/bin
TARGET = micropython
PREFIX = $(DESTDIR)/usr/local
BINDIR = $(PREFIX)/bin
122
123
PIPSRC = ../tools/pip-micropython
PIPTARGET = pip-micropython
Sebastian Plamauer's avatar
Sebastian Plamauer committed
124
125
126

install: micropython
	install -D $(TARGET) $(BINDIR)/$(TARGET)
127
	install -D $(PIPSRC) $(BINDIR)/$(PIPTARGET)
Sebastian Plamauer's avatar
Sebastian Plamauer committed
128
129
130
131

# uninstall micropython
uninstall:
	-rm $(BINDIR)/$(TARGET)
132
	-rm $(BINDIR)/$(PIPTARGET)
133
134
135
136
137

# build synthetically fast interpreter for benchmarking
fast:
	@echo Make sure to run make -B
	$(MAKE) COPT="-O2 -DNDEBUG" CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_fast.h>"' BUILD=build-fast