2016-06-15 23:27:21 +01:00
|
|
|
MPTOP = ../..
|
|
|
|
-include mpconfigport.mk
|
|
|
|
include $(MPTOP)/py/mkenv.mk
|
|
|
|
|
|
|
|
all: lib
|
|
|
|
|
|
|
|
# OS name, for simple autoconfig
|
|
|
|
UNAME_S := $(shell uname -s)
|
|
|
|
|
|
|
|
# include py core make definitions
|
|
|
|
include $(MPTOP)/py/py.mk
|
|
|
|
|
|
|
|
INC += -I.
|
|
|
|
INC += -I..
|
|
|
|
INC += -I$(MPTOP)
|
2018-02-21 23:46:19 +00:00
|
|
|
INC += -I$(MPTOP)/ports/unix
|
2016-06-15 23:27:21 +01:00
|
|
|
INC += -I$(BUILD)
|
|
|
|
|
|
|
|
# compiler settings
|
|
|
|
CWARN = -Wall -Werror
|
|
|
|
CWARN += -Wpointer-arith -Wuninitialized
|
2017-03-05 12:28:27 +00:00
|
|
|
CFLAGS = $(INC) $(CWARN) -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA)
|
2016-06-15 23:27:21 +01:00
|
|
|
|
2021-02-24 08:33:26 +00:00
|
|
|
# Some systems (eg MacOS) need -fno-common so that mp_state_ctx is placed in the BSS.
|
|
|
|
CFLAGS += -fno-common
|
|
|
|
|
2016-06-15 23:27:21 +01:00
|
|
|
# Debugging/Optimization
|
|
|
|
ifdef DEBUG
|
|
|
|
CFLAGS += -g
|
|
|
|
COPT = -O0
|
|
|
|
else
|
|
|
|
COPT = -Os #-DNDEBUG
|
|
|
|
# _FORTIFY_SOURCE is a feature in gcc/glibc which is intended to provide extra
|
|
|
|
# security for detecting buffer overflows. Some distros (Ubuntu at the very least)
|
|
|
|
# have it enabled by default.
|
|
|
|
#
|
|
|
|
# gcc already optimizes some printf calls to call puts and/or putchar. When
|
|
|
|
# _FORTIFY_SOURCE is enabled and compiling with -O1 or greater, then some
|
|
|
|
# printf calls will also be optimized to call __printf_chk (in glibc). Any
|
|
|
|
# printfs which get redirected to __printf_chk are then no longer synchronized
|
|
|
|
# with printfs that go through mp_printf.
|
|
|
|
#
|
|
|
|
# In MicroPython, we don't want to use the runtime library's printf but rather
|
|
|
|
# go through mp_printf, so that stdout is properly tied into streams, etc.
|
|
|
|
# This means that we either need to turn off _FORTIFY_SOURCE or provide our
|
|
|
|
# own implementation of __printf_chk. We've chosen to turn off _FORTIFY_SOURCE.
|
|
|
|
# It should also be noted that the use of printf in MicroPython is typically
|
|
|
|
# quite limited anyways (primarily for debug and some error reporting, etc
|
|
|
|
# in the unix version).
|
|
|
|
#
|
|
|
|
# Information about _FORTIFY_SOURCE seems to be rather scarce. The best I could
|
|
|
|
# find was this: https://securityblog.redhat.com/2014/03/26/fortify-and-you/
|
|
|
|
# Original patchset was introduced by
|
|
|
|
# https://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html .
|
|
|
|
#
|
|
|
|
# Turning off _FORTIFY_SOURCE is only required when compiling with -O1 or greater
|
|
|
|
CFLAGS += -U _FORTIFY_SOURCE
|
|
|
|
endif
|
|
|
|
|
|
|
|
# On OSX, 'gcc' is a symlink to clang unless a real gcc is installed.
|
2017-06-30 08:22:17 +01:00
|
|
|
# The unix port of MicroPython on OSX must be compiled with clang,
|
2016-06-15 23:27:21 +01:00
|
|
|
# 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
|
|
|
|
ifeq ($(UNAME_S),Darwin)
|
|
|
|
CC = clang
|
|
|
|
# Use clang syntax for map file
|
|
|
|
LDFLAGS_ARCH = -Wl,-map,$@.map
|
|
|
|
else
|
|
|
|
# Use gcc syntax for map file
|
|
|
|
LDFLAGS_ARCH = -Wl,-Map=$@.map,--cref
|
|
|
|
endif
|
|
|
|
LDFLAGS = $(LDFLAGS_MOD) $(LDFLAGS_ARCH) -lm $(LDFLAGS_EXTRA)
|
|
|
|
|
|
|
|
ifeq ($(MICROPY_FORCE_32BIT),1)
|
|
|
|
# Note: you may need to install i386 versions of dependency packages,
|
|
|
|
# starting with linux-libc-dev:i386
|
|
|
|
ifeq ($(MICROPY_PY_FFI),1)
|
|
|
|
ifeq ($(UNAME_S),Linux)
|
|
|
|
CFLAGS_MOD += -I/usr/include/i686-linux-gnu
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(MICROPY_USE_READLINE),1)
|
2021-07-09 05:19:15 +01:00
|
|
|
INC += -I$(MPTOP)/shared/readline
|
2016-06-15 23:27:21 +01:00
|
|
|
CFLAGS_MOD += -DMICROPY_USE_READLINE=1
|
2021-07-09 05:19:15 +01:00
|
|
|
SHARED_SRC_C_EXTRA += readline/readline.c
|
2016-06-15 23:27:21 +01:00
|
|
|
endif
|
|
|
|
ifeq ($(MICROPY_USE_READLINE),2)
|
|
|
|
CFLAGS_MOD += -DMICROPY_USE_READLINE=2
|
|
|
|
LDFLAGS_MOD += -lreadline
|
|
|
|
# the following is needed for BSD
|
|
|
|
#LDFLAGS_MOD += -ltermcap
|
|
|
|
endif
|
|
|
|
ifeq ($(MICROPY_PY_TIME),1)
|
|
|
|
CFLAGS_MOD += -DMICROPY_PY_TIME=1
|
|
|
|
SRC_MOD += modtime.c
|
|
|
|
endif
|
|
|
|
ifeq ($(MICROPY_PY_TERMIOS),1)
|
|
|
|
CFLAGS_MOD += -DMICROPY_PY_TERMIOS=1
|
|
|
|
SRC_MOD += modtermios.c
|
|
|
|
endif
|
|
|
|
ifeq ($(MICROPY_PY_SOCKET),1)
|
|
|
|
CFLAGS_MOD += -DMICROPY_PY_SOCKET=1
|
|
|
|
SRC_MOD += modsocket.c
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(MICROPY_PY_FFI),1)
|
|
|
|
|
|
|
|
ifeq ($(MICROPY_STANDALONE),1)
|
2018-02-21 23:46:19 +00:00
|
|
|
LIBFFI_CFLAGS_MOD := -I$(shell ls -1d $(MPTOP)/lib/libffi/build_dir/out/lib/libffi-*/include)
|
2016-06-15 23:27:21 +01:00
|
|
|
ifeq ($(MICROPY_FORCE_32BIT),1)
|
2018-02-21 23:46:19 +00:00
|
|
|
LIBFFI_LDFLAGS_MOD = $(MPTOP)/lib/libffi/build_dir/out/lib32/libffi.a
|
2016-06-15 23:27:21 +01:00
|
|
|
else
|
2018-02-21 23:46:19 +00:00
|
|
|
LIBFFI_LDFLAGS_MOD = $(MPTOP)/lib/libffi/build_dir/out/lib/libffi.a
|
2016-06-15 23:27:21 +01:00
|
|
|
endif
|
|
|
|
else
|
|
|
|
LIBFFI_CFLAGS_MOD := $(shell pkg-config --cflags libffi)
|
|
|
|
LIBFFI_LDFLAGS_MOD := $(shell pkg-config --libs libffi)
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(UNAME_S),Linux)
|
|
|
|
LIBFFI_LDFLAGS_MOD += -ldl
|
|
|
|
endif
|
|
|
|
|
|
|
|
CFLAGS_MOD += $(LIBFFI_CFLAGS_MOD) -DMICROPY_PY_FFI=1
|
|
|
|
LDFLAGS_MOD += $(LIBFFI_LDFLAGS_MOD)
|
|
|
|
SRC_MOD += modffi.c
|
|
|
|
endif
|
|
|
|
|
|
|
|
MAIN_C = main.c
|
|
|
|
|
|
|
|
# source files
|
2018-02-23 02:15:01 +00:00
|
|
|
SRC_C = $(addprefix ports/unix/,\
|
2016-06-15 23:27:21 +01:00
|
|
|
$(MAIN_C) \
|
|
|
|
gccollect.c \
|
|
|
|
unix_mphal.c \
|
|
|
|
input.c \
|
|
|
|
modmachine.c \
|
|
|
|
modos.c \
|
|
|
|
moduselect.c \
|
|
|
|
alloc.c \
|
|
|
|
coverage.c \
|
|
|
|
fatfs_port.c \
|
|
|
|
$(SRC_MOD) \
|
|
|
|
)
|
|
|
|
|
2021-07-09 05:19:15 +01:00
|
|
|
SHARED_SRC_C = $(addprefix shared/,\
|
|
|
|
libc/printf.c \
|
|
|
|
runtime/gchelper_generic.c \
|
2016-06-15 23:27:21 +01:00
|
|
|
timeutils/timeutils.c \
|
2021-07-09 05:19:15 +01:00
|
|
|
$(SHARED_SRC_C_EXTRA) \
|
2016-06-15 23:27:21 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
OBJ = $(PY_O)
|
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
|
2021-07-09 05:19:15 +01:00
|
|
|
OBJ += $(addprefix $(BUILD)/, $(SHARED_SRC_C:.c=.o))
|
2016-06-15 23:27:21 +01:00
|
|
|
|
|
|
|
# List of sources for qstr extraction
|
2021-07-09 05:19:15 +01:00
|
|
|
SRC_QSTR += $(SRC_C) $(SHARED_SRC_C)
|
2016-06-15 23:27:21 +01:00
|
|
|
# Append any auto-generated sources that are needed by sources listed in
|
|
|
|
# SRC_QSTR
|
|
|
|
SRC_QSTR_AUTO_DEPS +=
|
|
|
|
|
|
|
|
include $(MPTOP)/py/mkrules.mk
|
|
|
|
|
|
|
|
# Value of configure's --host= option (required for cross-compilation).
|
2017-05-29 08:08:14 +01:00
|
|
|
# Deduce it from CROSS_COMPILE by default, but can be overridden.
|
2016-06-15 23:27:21 +01:00
|
|
|
ifneq ($(CROSS_COMPILE),)
|
|
|
|
CROSS_COMPILE_HOST = --host=$(patsubst %-,%,$(CROSS_COMPILE))
|
|
|
|
else
|
|
|
|
CROSS_COMPILE_HOST =
|
|
|
|
endif
|
|
|
|
|
|
|
|
deplibs: libffi axtls
|
|
|
|
|
|
|
|
# install-exec-recursive & install-data-am targets are used to avoid building
|
|
|
|
# docs and depending on makeinfo
|
|
|
|
libffi:
|
2018-02-21 23:46:19 +00:00
|
|
|
cd $(MPTOP)/lib/libffi; git clean -d -x -f
|
|
|
|
cd $(MPTOP)/lib/libffi; ./autogen.sh
|
|
|
|
mkdir -p $(MPTOP)/lib/libffi/build_dir; cd $(MPTOP)/lib/libffi/build_dir; \
|
2016-06-15 23:27:21 +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
|
|
|
|
|
2018-02-21 23:46:19 +00:00
|
|
|
axtls: $(MPTOP)/lib/axtls/README
|
|
|
|
cd $(MPTOP)/lib/axtls; cp config/upyconfig config/.config
|
|
|
|
cd $(MPTOP)/lib/axtls; make oldconfig -B
|
|
|
|
cd $(MPTOP)/lib/axtls; make clean
|
|
|
|
cd $(MPTOP)/lib/axtls; make all CC="$(CC)" LD="$(LD)"
|
2016-06-15 23:27:21 +01:00
|
|
|
|
2018-02-21 23:46:19 +00:00
|
|
|
$(MPTOP)/lib/axtls/README:
|
2016-06-15 23:27:21 +01:00
|
|
|
@echo "You cloned without --recursive, fetching submodules for you."
|
2018-02-21 23:46:19 +00:00
|
|
|
(cd $(MPTOP); git submodule update --init --recursive)
|