From a9058bf2944db20f5e2377a6a38c37a46d3d6aa0 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 30 Aug 2015 10:57:38 +0300 Subject: [PATCH] unix: Allow to build libffi from source and link against it. Linking against local libffi (and other libs in future) is triggered by "make MICROPY_STANDALONE=1". Before that, dependent libs should be built with "make deplibs". --- unix/Makefile | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/unix/Makefile b/unix/Makefile index a061170831..edc800b633 100644 --- a/unix/Makefile +++ b/unix/Makefile @@ -77,13 +77,26 @@ ifeq ($(MICROPY_PY_SOCKET),1) CFLAGS_MOD += -DMICROPY_PY_SOCKET=1 SRC_MOD += modsocket.c endif + ifeq ($(MICROPY_PY_FFI),1) -LIBFFI_LDFLAGS_MOD := $(shell pkg-config --libs libffi) + +ifeq ($(MICROPY_STANDALONE),1) +LIBFFI_CFLAGS_MOD := -I$(shell ls -1d ../lib/libffi/out/lib/libffi-*/include) + ifeq ($(MICROPY_FORCE_32BIT),1) + LIBFFI_LDFLAGS_MOD = ../lib/libffi/out/lib32/libffi.a + else + LIBFFI_LDFLAGS_MOD = ../lib/libffi/out/lib/libffi.a + endif +else LIBFFI_CFLAGS_MOD := $(shell pkg-config --cflags libffi) -CFLAGS_MOD += $(LIBFFI_CFLAGS_MOD) -DMICROPY_PY_FFI=1 -ifeq ($(UNAME_S),Linux) -LDFLAGS_MOD += -ldl +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 @@ -172,3 +185,19 @@ $(BUILD)/frozen_upip/upip.py: $(UPIP_TARBALL) $(Q)rm -rf $(dir $@) $(Q)mkdir -p $(dir $@) $(Q)cp $(BUILD)/micropython-upip-*/upip*.py $(dir $@) + + +# 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 + +deplibs: libffi + +libffi: + cd ../lib/libffi; git clean -d -x -f + cd ../lib/libffi; ./autogen.sh + cd ../lib/libffi; ./configure $(CROSS_COMPILE_HOST) --prefix=$$PWD/out CC="$(CC)" CXX="$(CXX)" LD="$(LD)"; make install