From b76fd842f0299a1b5a937cb3f16bc11ccb723bb8 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 20 Apr 2014 22:10:27 +0300 Subject: [PATCH 1/7] unix mem_info(): Dump GC info only if it's enabled. --- unix/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/unix/main.c b/unix/main.c index 940fe48c14..e4536f381c 100644 --- a/unix/main.c +++ b/unix/main.c @@ -250,7 +250,9 @@ int usage(char **argv) { mp_obj_t mem_info(void) { printf("mem: total=%d, current=%d, peak=%d\n", m_get_total_bytes_allocated(), m_get_current_bytes_allocated(), m_get_peak_bytes_allocated()); +#if MICROPY_ENABLE_GC gc_dump_info(); +#endif return mp_const_none; } From 41809a1ceda52ec072a0e9a6da1650d4d1f5dfc3 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 20 Apr 2014 22:14:58 +0300 Subject: [PATCH 2/7] nlrx86.S: Another ifdef for win32 symbol underscoring issues. --- py/nlrx86.S | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/py/nlrx86.S b/py/nlrx86.S index 003de5095f..145bdb9da0 100644 --- a/py/nlrx86.S +++ b/py/nlrx86.S @@ -61,7 +61,11 @@ nlr_jump: #endif mov nlr_top, %edx # load nlr_top test %edx, %edx # check for nlr_top being NULL +#ifdef _WIN32 + je _nlr_jump_fail # fail if nlr_top is NULL +#else je nlr_jump_fail # fail if nlr_top is NULL +#endif mov 4(%esp), %eax # load return value mov %eax, 4(%edx) # store return value mov (%edx), %eax # load prev nlr_top From 353b0289f34abaff8cd6d5e4cbb02851eb80f118 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 20 Apr 2014 22:15:35 +0300 Subject: [PATCH 3/7] py: Add win32-specific header for alloca(). --- py/builtinimport.c | 4 ++++ py/objfun.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/py/builtinimport.c b/py/builtinimport.c index 262ee04a53..4a2f6510c3 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -3,6 +3,10 @@ #include #include #include +#ifdef __MINGW32__ +// For alloca() +#include +#endif #include "nlr.h" #include "misc.h" diff --git a/py/objfun.c b/py/objfun.c index c7144f3078..940b64a66e 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -2,6 +2,10 @@ #include #include #include +#ifdef __MINGW32__ +// For alloca() +#include +#endif #include "nlr.h" #include "misc.h" From 1f2ca1c1f9946fa28269526b4f1e16a316cf4b07 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 20 Apr 2014 22:16:29 +0300 Subject: [PATCH 4/7] unix file: mingw32 has STDIN_FILENO and friends in stdio.h . TODO: Never "optimize" includes any more! --- unix/file.c | 1 + 1 file changed, 1 insertion(+) diff --git a/unix/file.c b/unix/file.c index a0a865a263..5bda34013f 100644 --- a/unix/file.c +++ b/unix/file.c @@ -1,3 +1,4 @@ +#include #include #include #include From a196d08dfc600615e7b3ce3f774ec4de3f0c0b19 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 20 Apr 2014 22:19:14 +0300 Subject: [PATCH 5/7] unix windows: mingw32 doesn't have realpath(), use _fullpath() instead. --- unix/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/unix/main.c b/unix/main.c index e4536f381c..4c86edeae5 100644 --- a/unix/main.c +++ b/unix/main.c @@ -394,7 +394,11 @@ int main(int argc, char **argv) { return usage(argv); } } else { +#ifdef __MINGW32__ + char *basedir = _fullpath(NULL, argv[a], _MAX_PATH); +#else char *basedir = realpath(argv[a], NULL); +#endif if (basedir == NULL) { fprintf(stderr, "%s: can't open file '%s': [Errno %d] ", argv[0], argv[1], errno); perror(""); From 7f7c7aa76a34adbdb36a82c5a5c8b93805faee0b Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 20 Apr 2014 22:20:48 +0300 Subject: [PATCH 6/7] windows: Unbreak mingw32 build (cross-compiling under Linux). --- windows/Makefile | 23 +++++++++++++++-------- windows/mpconfigport.h | 4 ++-- windows/mpconfigport.mk | 13 +++++++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 windows/mpconfigport.mk diff --git a/windows/Makefile b/windows/Makefile index 651de7c7f1..2f5418886f 100644 --- a/windows/Makefile +++ b/windows/Makefile @@ -1,4 +1,5 @@ include ../py/mkenv.mk +-include mpconfigport.mk # define main target PROG = micropython.exe @@ -14,14 +15,15 @@ INC += -I$(PY_SRC) INC += -I$(BUILD) # compiler settings -CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 -DUNIX -LDFLAGS = -lm +CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) +LDFLAGS = $(LDFLAGS_MOD) -lm # Debugging/Optimization ifdef DEBUG -CFLAGS += -O0 -g +CFLAGS += -g +COPT = -O0 else -CFLAGS += -Os #-DNDEBUG +COPT = -Os #-DNDEBUG endif # source files @@ -30,11 +32,16 @@ SRC_C = \ unix/file.c \ OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) -LIB = -lreadline -LIB += -lws2_32 -LIB += -lmman + +ifeq ($(MICROPY_USE_READLINE),1) +CFLAGS_MOD += -DMICROPY_USE_READLINE=1 +LDFLAGS_MOD += -lreadline # the following is needed for BSD -#LIB += -ltermcap +#LDFLAGS_MOD += -ltermcap +endif + +LIB += -lws2_32 +#LIB += -lmman include ../py/mkrules.mk diff --git a/windows/mpconfigport.h b/windows/mpconfigport.h index 74fe749e1e..993fef9d59 100644 --- a/windows/mpconfigport.h +++ b/windows/mpconfigport.h @@ -2,10 +2,10 @@ // Linking with GNU readline causes binary to be licensed under GPL #ifndef MICROPY_USE_READLINE -#define MICROPY_USE_READLINE (1) +#define MICROPY_USE_READLINE (0) #endif -#define MICROPY_EMIT_X64 (1) +#define MICROPY_EMIT_X64 (0) #define MICROPY_EMIT_THUMB (0) #define MICROPY_EMIT_INLINE_THUMB (0) #define MICROPY_MEM_STATS (1) diff --git a/windows/mpconfigport.mk b/windows/mpconfigport.mk new file mode 100644 index 0000000000..458f23dd1e --- /dev/null +++ b/windows/mpconfigport.mk @@ -0,0 +1,13 @@ +# Enable/disable modules and 3rd-party libs to be included in interpreter + +# Build 32-bit binaries on a 64-bit host +MICROPY_FORCE_32BIT = 0 + +# Linking with GNU readline causes binary to be licensed under GPL +MICROPY_USE_READLINE = 0 + +# Subset of CPython time module +MICROPY_MOD_TIME = 1 + +# ffi module requires libffi (libffi-dev Debian package) +MICROPY_MOD_FFI = 0 From 521de04ce2dc7048afbdb2445979a203512b13e2 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 20 Apr 2014 22:35:11 +0300 Subject: [PATCH 7/7] windows: Add README with basic cross-compile instructions. --- windows/README | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 windows/README diff --git a/windows/README b/windows/README new file mode 100644 index 0000000000..615ada2012 --- /dev/null +++ b/windows/README @@ -0,0 +1,10 @@ +This is experimental, community-supported Windows port of MicroPython. +It is based on Unix port, and expected to remain so. + +To cross-compile under Debian/Ubuntu Linux system: + +sudo apt-get install mingw32 mingw32-binutils mingw32-runtime +make CC=i586-mingw32msvc-gcc + +The port requires additional testing, debugging, and patches. Please +consider to contribute.