summaryrefslogtreecommitdiff
path: root/mpy-cross
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2020-01-25 14:04:11 -0600
committerJeff Epler <jepler@gmail.com>2020-01-25 14:04:11 -0600
commitebf0fe0a8cfc93546699879b13a87071ea942ce3 (patch)
tree6c5be9f2558d449b5b5736386eb6e4028c69e683 /mpy-cross
parentc2fd30364e5e1f93cf634e6e2af0613d3bd4b0be (diff)
mpy-cross: Make it easier to build mpy-cross static targets
Diffstat (limited to 'mpy-cross')
-rw-r--r--mpy-cross/.gitignore4
-rw-r--r--mpy-cross/Makefile82
-rw-r--r--mpy-cross/Makefile.static5
-rw-r--r--mpy-cross/Makefile.static-mingw6
-rw-r--r--mpy-cross/fmode.c49
-rw-r--r--mpy-cross/fmode.h37
-rw-r--r--mpy-cross/main.c2
-rw-r--r--mpy-cross/mpy-cross.mk81
8 files changed, 183 insertions, 83 deletions
diff --git a/mpy-cross/.gitignore b/mpy-cross/.gitignore
index 82a0a7efa..f0024841d 100644
--- a/mpy-cross/.gitignore
+++ b/mpy-cross/.gitignore
@@ -1 +1,3 @@
-mpy-cross
+mpy-cross{,.exe}
+mpy-cross.static{,.exe}
+build-*
diff --git a/mpy-cross/Makefile b/mpy-cross/Makefile
index 42dbace98..072304faa 100644
--- a/mpy-cross/Makefile
+++ b/mpy-cross/Makefile
@@ -11,84 +11,4 @@ override undefine BUILD
override undefine PROG
endif
-include ../py/mkenv.mk
-
-# define main target
-
-ifeq ($(OS),Windows_NT)
-# Detect a MINGW32 build, and change the name of the final executable.
-PROG = mpy-cross.exe
-else
-PROG = mpy-cross
-endif
-
-# qstr definitions (must come before including py.mk)
-QSTR_DEFS = qstrdefsport.h
-
-# OS name, for simple autoconfig
-UNAME_S := $(shell uname -s)
-
-# include py core make definitions
-include $(TOP)/py/py.mk
-
-INC += -I.
-INC += -I$(TOP)
-INC += -I$(BUILD)
-
-# compiler settings
-CWARN = -Wall -Werror
-CWARN += -Wpointer-arith -Wuninitialized
-CFLAGS = $(INC) $(CWARN) -std=gnu99 $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA)
-CFLAGS += -fdata-sections -ffunction-sections -fno-asynchronous-unwind-tables
-
-# Build a static executable.
-# Useful for Windows builds, etc., that must run on multiple operating system versions.
-ifdef STATIC_BUILD
-CFLAGS += -static -static-libgcc -static-libstdc++
-endif
-
-
-# Debugging/Optimization
-ifdef DEBUG
-CFLAGS += -g
-COPT = -O0
-else
-COPT = -Os #-DNDEBUG
-endif
-
-# 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
-ifeq ($(UNAME_S),Darwin)
-CC = clang
-# Use clang syntax for map file
-LDFLAGS_ARCH = -Wl,-map,$@.map -Wl,-dead_strip
-else
-# Use gcc syntax for map file
-LDFLAGS_ARCH = -Wl,-Map=$@.map,--cref -Wl,--gc-sections
-endif
-LDFLAGS = $(LDFLAGS_MOD) $(LDFLAGS_ARCH) -lm $(LDFLAGS_EXTRA)
-
-ifdef STATIC_BUILD
-LDFLAGS += -static -static-libgcc -static-libstdc++
-endif
-
-# source files
-SRC_C = \
- main.c \
- gccollect.c \
- supervisor/stub/safe_mode.c \
- supervisor/stub/stack.c \
- supervisor/shared/translate.c
-
-# Add fmode when compiling with mingw gcc
-COMPILER_TARGET := $(shell $(CC) -dumpmachine)
-ifneq (,$(findstring mingw,$(COMPILER_TARGET)))
- SRC_C += ports/windows/fmode.c
-endif
-
-OBJ = $(PY_O)
-OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
-
-include $(TOP)/py/mkrules.mk
+include mpy-cross.mk
diff --git a/mpy-cross/Makefile.static b/mpy-cross/Makefile.static
new file mode 100644
index 000000000..ca0925f75
--- /dev/null
+++ b/mpy-cross/Makefile.static
@@ -0,0 +1,5 @@
+PROG=mpy-cross.static
+BUILD=build-static
+STATIC_BUILD=1
+
+include mpy-cross.mk
diff --git a/mpy-cross/Makefile.static-mingw b/mpy-cross/Makefile.static-mingw
new file mode 100644
index 000000000..a176e80e6
--- /dev/null
+++ b/mpy-cross/Makefile.static-mingw
@@ -0,0 +1,6 @@
+PROG=mpy-cross.static.exe
+CROSS_COMPILE = x86_64-w64-mingw32-
+BUILD=build-static-mingw
+STATIC_BUILD=1
+
+include mpy-cross.mk
diff --git a/mpy-cross/fmode.c b/mpy-cross/fmode.c
new file mode 100644
index 000000000..33ba24ed1
--- /dev/null
+++ b/mpy-cross/fmode.c
@@ -0,0 +1,49 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2013-2016 Damien P. George
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "fmode.h"
+#include "py/mpconfig.h"
+#include <fcntl.h>
+#include <stdlib.h>
+
+// Workaround for setting file translation mode: we must distinguish toolsets
+// since mingw has no _set_fmode, and altering msvc's _fmode directly has no effect
+STATIC int set_fmode_impl(int mode) {
+#ifndef _MSC_VER
+ _fmode = mode;
+ return 0;
+#else
+ return _set_fmode(mode);
+#endif
+}
+
+void set_fmode_binary(void) {
+ set_fmode_impl(O_BINARY);
+}
+
+void set_fmode_text(void) {
+ set_fmode_impl(O_TEXT);
+}
diff --git a/mpy-cross/fmode.h b/mpy-cross/fmode.h
new file mode 100644
index 000000000..c661c84d0
--- /dev/null
+++ b/mpy-cross/fmode.h
@@ -0,0 +1,37 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2013-2016 Damien P. George
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef MICROPY_INCLUDED_WINDOWS_FMODE_H
+#define MICROPY_INCLUDED_WINDOWS_FMODE_H
+
+// Treat files opened by open() as binary. No line ending translation is done.
+void set_fmode_binary(void);
+
+// Treat files opened by open() as text.
+// When reading from the file \r\n will be converted to \n.
+// When writing to the file \n will be converted into \r\n.
+void set_fmode_text(void);
+
+#endif // MICROPY_INCLUDED_WINDOWS_FMODE_H
diff --git a/mpy-cross/main.c b/mpy-cross/main.c
index d819f74f1..280f59522 100644
--- a/mpy-cross/main.c
+++ b/mpy-cross/main.c
@@ -35,7 +35,7 @@
#include "py/gc.h"
#include "py/stackctrl.h"
#ifdef _WIN32
-#include "ports/windows/fmode.h"
+#include "fmode.h"
#endif
// Command line options, with their defaults
diff --git a/mpy-cross/mpy-cross.mk b/mpy-cross/mpy-cross.mk
new file mode 100644
index 000000000..de96305cb
--- /dev/null
+++ b/mpy-cross/mpy-cross.mk
@@ -0,0 +1,81 @@
+include ../py/mkenv.mk
+
+# define main target
+
+ifeq ($(OS),Windows_NT)
+# Detect a MINGW32 build, and change the name of the final executable.
+PROG ?= mpy-cross.exe
+else
+PROG ?= mpy-cross
+endif
+
+# qstr definitions (must come before including py.mk)
+QSTR_DEFS = qstrdefsport.h
+
+# OS name, for simple autoconfig
+UNAME_S := $(shell uname -s)
+
+# include py core make definitions
+include $(TOP)/py/py.mk
+
+INC += -I.
+INC += -I$(TOP)
+INC += -I$(BUILD)
+
+# compiler settings
+CWARN = -Wall -Werror
+CWARN += -Wpointer-arith -Wuninitialized
+CFLAGS = $(INC) $(CWARN) -std=gnu99 $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA)
+CFLAGS += -fdata-sections -ffunction-sections -fno-asynchronous-unwind-tables
+
+# Build a static executable.
+# Useful for Windows builds, etc., that must run on multiple operating system versions.
+ifdef STATIC_BUILD
+CFLAGS += -static -static-libgcc -static-libstdc++
+endif
+
+
+# Debugging/Optimization
+ifdef DEBUG
+CFLAGS += -g
+COPT = -O0
+else
+COPT = -Os #-DNDEBUG
+endif
+
+# 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
+ifeq ($(UNAME_S),Darwin)
+CC = clang
+# Use clang syntax for map file
+LDFLAGS_ARCH = -Wl,-map,$@.map -Wl,-dead_strip
+else
+# Use gcc syntax for map file
+LDFLAGS_ARCH = -Wl,-Map=$@.map,--cref -Wl,--gc-sections
+endif
+LDFLAGS = $(LDFLAGS_MOD) $(LDFLAGS_ARCH) -lm $(LDFLAGS_EXTRA)
+
+ifdef STATIC_BUILD
+LDFLAGS += -static -static-libgcc -static-libstdc++
+endif
+
+# source files
+SRC_C = \
+ main.c \
+ gccollect.c \
+ supervisor/stub/safe_mode.c \
+ supervisor/stub/stack.c \
+ supervisor/shared/translate.c
+
+# Add fmode when compiling with mingw gcc
+COMPILER_TARGET := $(shell $(CC) -dumpmachine)
+ifneq (,$(findstring mingw,$(COMPILER_TARGET)))
+ SRC_C += fmode.c
+endif
+
+OBJ = $(PY_O)
+OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
+
+include $(TOP)/py/mkrules.mk