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/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 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" 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 diff --git a/unix/main.c b/unix/main.c index 940fe48c14..4c86edeae5 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; } @@ -392,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(""); 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/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. 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