2014-02-01 18:06:55 +00:00
|
|
|
-include mpconfigport.mk
|
2016-01-02 21:56:03 +00:00
|
|
|
include ../py/mkenv.mk
|
2014-01-24 09:05:30 +00:00
|
|
|
|
2014-01-07 14:54:15 +00:00
|
|
|
# define main target
|
2014-01-20 00:02:39 +00:00
|
|
|
PROG = micropython
|
2014-01-07 14:54:15 +00:00
|
|
|
|
2014-01-21 21:40:13 +00:00
|
|
|
# qstr definitions (must come before including py.mk)
|
|
|
|
QSTR_DEFS = qstrdefsport.h
|
|
|
|
|
2014-06-20 17:25:54 +01:00
|
|
|
# OS name, for simple autoconfig
|
|
|
|
UNAME_S := $(shell uname -s)
|
|
|
|
|
2014-01-07 14:54:15 +00:00
|
|
|
# include py core make definitions
|
|
|
|
include ../py/py.mk
|
2013-10-12 14:30:21 +01:00
|
|
|
|
2015-10-19 16:22:16 +01:00
|
|
|
INC += -I.
|
2014-12-27 14:11:49 +00:00
|
|
|
INC += -I..
|
2014-04-17 18:03:27 +01:00
|
|
|
INC += -I$(BUILD)
|
2014-04-16 22:10:33 +01:00
|
|
|
|
2014-01-07 14:54:15 +00:00
|
|
|
# compiler settings
|
2015-01-22 14:10:11 +00:00
|
|
|
CWARN = -Wall -Werror
|
2015-03-22 22:41:45 +00:00
|
|
|
CWARN += -Wpointer-arith -Wuninitialized
|
2014-06-20 17:27:51 +01:00
|
|
|
CFLAGS = $(INC) $(CWARN) -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA)
|
2014-02-14 22:37:37 +00:00
|
|
|
|
2014-06-20 17:19:06 +01:00
|
|
|
# Debugging/Optimization
|
|
|
|
ifdef DEBUG
|
|
|
|
CFLAGS += -g
|
|
|
|
COPT = -O0
|
|
|
|
else
|
|
|
|
COPT = -Os #-DNDEBUG
|
|
|
|
endif
|
|
|
|
|
2014-09-23 14:42:18 +01:00
|
|
|
# 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
|
2014-09-22 20:16:14 +01:00
|
|
|
ifeq ($(UNAME_S),Darwin)
|
|
|
|
CC = clang
|
2015-01-08 09:32:45 +00:00
|
|
|
# Use clang syntax for map file
|
|
|
|
LDFLAGS_ARCH = -Wl,-map,$@.map
|
2014-09-23 04:00:42 +01:00
|
|
|
else
|
2014-09-23 14:42:18 +01:00
|
|
|
# Use gcc syntax for map file
|
|
|
|
LDFLAGS_ARCH = -Wl,-Map=$@.map,--cref
|
2014-09-22 20:16:14 +01:00
|
|
|
endif
|
2014-09-23 14:42:18 +01:00
|
|
|
LDFLAGS = $(LDFLAGS_MOD) $(LDFLAGS_ARCH) -lm $(LDFLAGS_EXTRA)
|
2014-02-01 18:06:55 +00:00
|
|
|
|
2014-04-16 01:46:01 +01:00
|
|
|
ifeq ($(MICROPY_FORCE_32BIT),1)
|
2014-10-11 18:29:51 +01:00
|
|
|
# Note: you may need to install i386 versions of dependency packages,
|
|
|
|
# starting with linux-libc-dev:i386
|
2014-05-24 23:03:12 +01:00
|
|
|
ifeq ($(MICROPY_PY_FFI),1)
|
2014-04-16 01:46:01 +01:00
|
|
|
ifeq ($(UNAME_S),Linux)
|
|
|
|
CFLAGS_MOD += -I/usr/include/i686-linux-gnu
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2014-02-27 16:10:40 +00:00
|
|
|
ifeq ($(MICROPY_USE_READLINE),1)
|
2015-05-24 22:36:31 +01:00
|
|
|
INC += -I../lib/mp-readline
|
2014-02-27 16:10:40 +00:00
|
|
|
CFLAGS_MOD += -DMICROPY_USE_READLINE=1
|
2015-05-24 22:36:31 +01:00
|
|
|
LIB_SRC_C_EXTRA += mp-readline/readline.c
|
|
|
|
endif
|
|
|
|
ifeq ($(MICROPY_USE_READLINE),2)
|
|
|
|
CFLAGS_MOD += -DMICROPY_USE_READLINE=2
|
2014-02-27 16:10:40 +00:00
|
|
|
LDFLAGS_MOD += -lreadline
|
|
|
|
# the following is needed for BSD
|
|
|
|
#LDFLAGS_MOD += -ltermcap
|
|
|
|
endif
|
2014-05-24 23:03:12 +01:00
|
|
|
ifeq ($(MICROPY_PY_TIME),1)
|
|
|
|
CFLAGS_MOD += -DMICROPY_PY_TIME=1
|
2014-04-04 18:32:26 +01:00
|
|
|
SRC_MOD += modtime.c
|
2014-02-01 22:57:06 +00:00
|
|
|
endif
|
2014-08-19 08:23:14 +01:00
|
|
|
ifeq ($(MICROPY_PY_TERMIOS),1)
|
|
|
|
CFLAGS_MOD += -DMICROPY_PY_TERMIOS=1
|
|
|
|
SRC_MOD += modtermios.c
|
|
|
|
endif
|
2015-01-11 17:28:27 +00:00
|
|
|
ifeq ($(MICROPY_PY_SOCKET),1)
|
|
|
|
CFLAGS_MOD += -DMICROPY_PY_SOCKET=1
|
|
|
|
SRC_MOD += modsocket.c
|
|
|
|
endif
|
2015-08-30 08:57:38 +01:00
|
|
|
|
2014-05-24 23:03:12 +01:00
|
|
|
ifeq ($(MICROPY_PY_FFI),1)
|
2015-08-30 08:57:38 +01:00
|
|
|
|
|
|
|
ifeq ($(MICROPY_STANDALONE),1)
|
2015-10-17 22:20:24 +01:00
|
|
|
LIBFFI_CFLAGS_MOD := -I$(shell ls -1d ../lib/libffi/build_dir/out/lib/libffi-*/include)
|
2015-08-30 08:57:38 +01:00
|
|
|
ifeq ($(MICROPY_FORCE_32BIT),1)
|
2015-10-17 22:20:24 +01:00
|
|
|
LIBFFI_LDFLAGS_MOD = ../lib/libffi/build_dir/out/lib32/libffi.a
|
2015-08-30 08:57:38 +01:00
|
|
|
else
|
2015-10-17 22:20:24 +01:00
|
|
|
LIBFFI_LDFLAGS_MOD = ../lib/libffi/build_dir/out/lib/libffi.a
|
2015-08-30 08:57:38 +01:00
|
|
|
endif
|
|
|
|
else
|
2014-04-20 09:30:46 +01:00
|
|
|
LIBFFI_CFLAGS_MOD := $(shell pkg-config --cflags libffi)
|
2015-08-30 08:57:38 +01:00
|
|
|
LIBFFI_LDFLAGS_MOD := $(shell pkg-config --libs libffi)
|
|
|
|
endif
|
|
|
|
|
2014-06-07 08:16:42 +01:00
|
|
|
ifeq ($(UNAME_S),Linux)
|
2015-08-30 08:57:38 +01:00
|
|
|
LIBFFI_LDFLAGS_MOD += -ldl
|
2014-06-07 08:16:42 +01:00
|
|
|
endif
|
2015-08-30 08:57:38 +01:00
|
|
|
|
|
|
|
CFLAGS_MOD += $(LIBFFI_CFLAGS_MOD) -DMICROPY_PY_FFI=1
|
2014-06-07 08:16:42 +01:00
|
|
|
LDFLAGS_MOD += $(LIBFFI_LDFLAGS_MOD)
|
2014-04-04 18:32:26 +01:00
|
|
|
SRC_MOD += modffi.c
|
2014-02-01 18:06:55 +00:00
|
|
|
endif
|
|
|
|
|
2015-09-11 15:57:47 +01:00
|
|
|
ifeq ($(MICROPY_PY_JNI),1)
|
|
|
|
# Path for 64-bit OpenJDK, should be adjusted for other JDKs
|
|
|
|
CFLAGS_MOD += -I/usr/lib/jvm/java-7-openjdk-amd64/include -DMICROPY_PY_JNI=1
|
|
|
|
SRC_MOD += modjni.c
|
|
|
|
endif
|
2013-10-12 14:30:21 +01:00
|
|
|
|
2014-01-07 14:54:15 +00:00
|
|
|
# source files
|
2013-10-12 14:30:21 +01:00
|
|
|
SRC_C = \
|
|
|
|
main.c \
|
2014-02-10 22:44:37 +00:00
|
|
|
gccollect.c \
|
2015-05-24 20:00:50 +01:00
|
|
|
unix_mphal.c \
|
2014-05-07 15:15:00 +01:00
|
|
|
input.c \
|
2014-01-08 00:52:20 +00:00
|
|
|
file.c \
|
2015-12-12 22:15:33 +00:00
|
|
|
modmachine.c \
|
2014-05-14 20:08:45 +01:00
|
|
|
modos.c \
|
2015-11-16 22:35:29 +00:00
|
|
|
moduselect.c \
|
2014-09-03 22:47:23 +01:00
|
|
|
alloc.c \
|
2015-05-08 00:19:56 +01:00
|
|
|
coverage.c \
|
2014-02-01 18:06:55 +00:00
|
|
|
$(SRC_MOD)
|
2013-10-12 14:30:21 +01:00
|
|
|
|
2015-06-01 23:32:07 +01:00
|
|
|
# Include builtin package manager in the standard build (and coverage)
|
|
|
|
ifeq ($(PROG),micropython)
|
|
|
|
SRC_C += $(BUILD)/_frozen_upip.c
|
|
|
|
else ifeq ($(PROG),micropython_coverage)
|
|
|
|
SRC_C += $(BUILD)/_frozen_upip.c
|
2016-01-15 11:12:08 +00:00
|
|
|
else ifeq ($(PROG), micropython_nanbox)
|
|
|
|
SRC_C += $(BUILD)/_frozen_upip.c
|
2015-12-15 10:25:00 +00:00
|
|
|
else ifeq ($(PROG), micropython_freedos)
|
|
|
|
SRC_C += $(BUILD)/_frozen_upip.c
|
2015-06-01 23:32:07 +01:00
|
|
|
endif
|
|
|
|
|
2015-05-24 22:36:31 +01:00
|
|
|
LIB_SRC_C = $(addprefix lib/,\
|
|
|
|
$(LIB_SRC_C_EXTRA) \
|
2015-11-21 22:44:22 +00:00
|
|
|
utils/printf.c \
|
2015-05-24 22:36:31 +01:00
|
|
|
)
|
2014-09-22 20:16:14 +01:00
|
|
|
|
2015-05-24 22:36:31 +01:00
|
|
|
OBJ = $(PY_O)
|
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
|
|
|
|
OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
|
2013-10-12 14:30:21 +01:00
|
|
|
|
2014-01-24 09:05:30 +00:00
|
|
|
include ../py/mkrules.mk
|
2013-12-29 18:01:01 +00:00
|
|
|
|
2014-04-16 20:38:16 +01:00
|
|
|
.PHONY: test
|
|
|
|
|
|
|
|
test: $(PROG) ../tests/run-tests
|
|
|
|
$(eval DIRNAME=$(notdir $(CURDIR)))
|
2014-04-17 01:26:25 +01:00
|
|
|
cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests
|
2014-08-11 18:47:00 +01:00
|
|
|
|
|
|
|
# install micropython in /usr/local/bin
|
|
|
|
TARGET = micropython
|
|
|
|
PREFIX = $(DESTDIR)/usr/local
|
|
|
|
BINDIR = $(PREFIX)/bin
|
2014-08-26 16:03:57 +01:00
|
|
|
PIPSRC = ../tools/pip-micropython
|
|
|
|
PIPTARGET = pip-micropython
|
2014-08-11 18:47:00 +01:00
|
|
|
|
|
|
|
install: micropython
|
|
|
|
install -D $(TARGET) $(BINDIR)/$(TARGET)
|
2014-08-26 16:03:57 +01:00
|
|
|
install -D $(PIPSRC) $(BINDIR)/$(PIPTARGET)
|
2014-08-11 18:47:00 +01:00
|
|
|
|
|
|
|
# uninstall micropython
|
|
|
|
uninstall:
|
|
|
|
-rm $(BINDIR)/$(TARGET)
|
2014-08-26 16:03:57 +01:00
|
|
|
-rm $(BINDIR)/$(PIPTARGET)
|
2014-11-01 14:01:21 +00:00
|
|
|
|
|
|
|
# build synthetically fast interpreter for benchmarking
|
|
|
|
fast:
|
2015-01-11 17:28:27 +00:00
|
|
|
$(MAKE) COPT="-O2 -DNDEBUG -fno-crossjumping" CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_fast.h>"' BUILD=build-fast PROG=micropython_fast
|
|
|
|
|
|
|
|
# build a minimal interpreter
|
|
|
|
minimal:
|
2015-05-30 11:12:02 +01:00
|
|
|
$(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 MICROPY_USE_READLINE=0
|
2015-01-29 14:54:38 +00:00
|
|
|
|
2016-01-15 11:12:08 +00:00
|
|
|
# build interpreter with nan-boxing as object model
|
|
|
|
nanbox:
|
|
|
|
$(MAKE) \
|
|
|
|
CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_nanbox.h>"' \
|
|
|
|
BUILD=build-nanbox \
|
|
|
|
PROG=micropython_nanbox \
|
|
|
|
MICROPY_FORCE_32BIT=1 \
|
|
|
|
|
2015-12-15 10:25:00 +00:00
|
|
|
freedos:
|
|
|
|
$(MAKE) \
|
|
|
|
CC=i586-pc-msdosdjgpp-gcc \
|
|
|
|
CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_freedos.h>" -DMICROPY_NLR_SETJMP -Dtgamma=gamma -DMICROPY_EMIT_X86=0 -DMICROPY_NO_ALLOCA=1 -DMICROPY_PY_USELECT=0' \
|
|
|
|
BUILD=build-freedos \
|
|
|
|
PROG=micropython_freedos \
|
|
|
|
MICROPY_PY_SOCKET=0 \
|
|
|
|
MICROPY_PY_FFI=0 \
|
|
|
|
MICROPY_PY_JNI=0
|
|
|
|
|
2015-01-29 14:54:38 +00:00
|
|
|
# build an interpreter for coverage testing and do the testing
|
|
|
|
coverage:
|
2016-01-22 16:19:32 +00:00
|
|
|
$(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 -DMICROPY_PY_URANDOM_EXTRA_FUNCS' LDFLAGS_EXTRA='-fprofile-arcs -ftest-coverage' BUILD=build-coverage PROG=micropython_coverage
|
2015-03-01 13:37:27 +00:00
|
|
|
|
|
|
|
coverage_test: coverage
|
2015-01-29 14:54:38 +00:00
|
|
|
$(eval DIRNAME=$(notdir $(CURDIR)))
|
|
|
|
cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests
|
2015-05-08 00:19:56 +01:00
|
|
|
cd ../tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests --emit native
|
2015-01-29 14:54:38 +00:00
|
|
|
gcov -o build-coverage/py ../py/*.c
|
2015-05-08 00:19:56 +01:00
|
|
|
gcov -o build-coverage/extmod ../extmod/*.c
|
2015-06-01 23:32:07 +01:00
|
|
|
|
2015-06-03 17:11:00 +01:00
|
|
|
$(BUILD)/_frozen_upip.c: $(BUILD)/frozen_upip/upip.py
|
|
|
|
../tools/make-frozen.py $(dir $^) > $@
|
2015-06-01 23:32:07 +01:00
|
|
|
|
|
|
|
# Select latest upip version available
|
|
|
|
UPIP_TARBALL := $(shell ls -1 -v ../tools/micropython-upip-*.tar.gz | tail -n1)
|
|
|
|
|
2015-06-03 17:11:00 +01:00
|
|
|
$(BUILD)/frozen_upip/upip.py: $(UPIP_TARBALL)
|
2015-06-01 23:32:07 +01:00
|
|
|
$(ECHO) "MISC Preparing upip as frozen module"
|
2015-06-03 17:11:00 +01:00
|
|
|
$(Q)rm -rf $(BUILD)/micropython-upip-*
|
2015-06-02 23:55:54 +01:00
|
|
|
$(Q)tar -C $(BUILD) -xz -f $^
|
2015-06-03 17:11:00 +01:00
|
|
|
$(Q)rm -rf $(dir $@)
|
|
|
|
$(Q)mkdir -p $(dir $@)
|
|
|
|
$(Q)cp $(BUILD)/micropython-upip-*/upip*.py $(dir $@)
|
2015-08-30 08:57:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Value of configure's --host= option (required for cross-compilation).
|
|
|
|
# Deduce it from CROSS_COMPILE by default, but can be overriden.
|
|
|
|
ifneq ($(CROSS_COMPILE),)
|
|
|
|
CROSS_COMPILE_HOST = --host=$(patsubst %-,%,$(CROSS_COMPILE))
|
|
|
|
else
|
|
|
|
CROSS_COMPILE_HOST =
|
|
|
|
endif
|
|
|
|
|
2015-09-19 15:12:02 +01:00
|
|
|
deplibs: libffi axtls
|
2015-08-30 08:57:38 +01:00
|
|
|
|
2015-10-19 18:28:06 +01:00
|
|
|
# install-exec-recursive & install-data-am targets are used to avoid building
|
|
|
|
# docs and depending on makeinfo
|
2015-08-30 08:57:38 +01:00
|
|
|
libffi:
|
|
|
|
cd ../lib/libffi; git clean -d -x -f
|
|
|
|
cd ../lib/libffi; ./autogen.sh
|
2015-10-17 22:20:24 +01:00
|
|
|
mkdir -p ../lib/libffi/build_dir; cd ../lib/libffi/build_dir; \
|
2015-10-19 18:28:06 +01:00
|
|
|
../configure $(CROSS_COMPILE_HOST) --prefix=$$PWD/out CC="$(CC)" CXX="$(CXX)" LD="$(LD)"; \
|
|
|
|
make install-exec-recursive; make -C include install-data-am
|
2015-09-19 15:12:02 +01:00
|
|
|
|
|
|
|
axtls:
|
|
|
|
cd ../lib/axtls; cp config/upyconfig config/.config
|
|
|
|
cd ../lib/axtls; make oldconfig -B
|
|
|
|
cd ../lib/axtls; make clean
|
|
|
|
cd ../lib/axtls; make all CC="$(CC)" LD="$(LD)"
|