diff --git a/ports/unix/Makefile b/ports/unix/Makefile index 2fa1373e73..567b1d5c22 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -1,16 +1,29 @@ --include mpconfigport.mk +# Select the variant to build for. +VARIANT ?= standard + +# If the build directory is not given, make it reflect the variant name. +BUILD ?= build-$(VARIANT) + +VARIANT_DIR ?= variants/$(VARIANT) +ifeq ($(wildcard $(VARIANT_DIR)/.),) +$(error Invalid VARIANT specified: $(VARIANT_DIR)) +endif + include ../../py/mkenv.mk +-include mpconfigport.mk +include $(VARIANT_DIR)/mpconfigvariant.mk # use FROZEN_MANIFEST for new projects, others are legacy FROZEN_MANIFEST ?= manifest.py FROZEN_DIR = FROZEN_MPY_DIR = -# define main target -PROG = micropython +# This should be configured by the mpconfigvariant.mk +PROG ?= micropython # qstr definitions (must come before including py.mk) QSTR_DEFS = qstrdefsport.h +QSTR_GLOBAL_DEPENDENCIES = $(VARIANT_DIR)/mpconfigvariant.h # OS name, for simple autoconfig UNAME_S := $(shell uname -s) @@ -27,7 +40,7 @@ INC += -I$(BUILD) # compiler settings CWARN = -Wall -Werror CWARN += -Wpointer-arith -Wuninitialized -CFLAGS = $(INC) $(CWARN) -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA) +CFLAGS = $(INC) $(CWARN) -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) -I$(VARIANT_DIR) $(CFLAGS_EXTRA) # Debugging/Optimization ifdef DEBUG @@ -156,7 +169,8 @@ SRC_C = \ alloc.c \ coverage.c \ fatfs_port.c \ - $(SRC_MOD) + $(SRC_MOD) \ + $(wildcard $(VARIANT_DIR)/*.c) LIB_SRC_C = $(addprefix lib/,\ $(LIB_SRC_C_EXTRA) \ @@ -188,83 +202,42 @@ endif include $(TOP)/py/mkrules.mk -.PHONY: test +.PHONY: test test_full test: $(PROG) $(TOP)/tests/run-tests $(eval DIRNAME=ports/$(notdir $(CURDIR))) cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests -# install micropython in /usr/local/bin -TARGET = micropython -PREFIX = $(DESTDIR)/usr/local -BINDIR = $(PREFIX)/bin +test_full: $(PROG) $(TOP)/tests/run-tests + $(eval DIRNAME=ports/$(notdir $(CURDIR))) + cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests + cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests -d thread + cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests --emit native + cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests --via-mpy -d basics float micropython + cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests --via-mpy --emit native -d basics float micropython + cat $(TOP)/tests/basics/0prelim.py | ./$(PROG) | grep -q 'abc' -install: micropython - install -d $(BINDIR) - install $(TARGET) $(BINDIR)/$(TARGET) +test_gcov: test_full + gcov -o $(BUILD)/py $(TOP)/py/*.c + gcov -o $(BUILD)/extmod $(TOP)/extmod/*.c -# uninstall micropython -uninstall: - -rm $(BINDIR)/$(TARGET) - -# build synthetically fast interpreter for benchmarking +# Maintain historical targets from pre-variant configurations. fast: - $(MAKE) COPT="-O2 -DNDEBUG -fno-crossjumping" CFLAGS_EXTRA='-DMP_CONFIGFILE=""' BUILD=build-fast PROG=micropython_fast FROZEN_MANIFEST= + $(MAKE) VARIANT=fast -# build a minimal interpreter minimal: - $(MAKE) COPT="-Os -DNDEBUG" CFLAGS_EXTRA='-DMP_CONFIGFILE=""' \ - BUILD=build-minimal PROG=micropython_minimal FROZEN_MANIFEST= \ - MICROPY_PY_BTREE=0 MICROPY_PY_FFI=0 MICROPY_PY_SOCKET=0 MICROPY_PY_THREAD=0 \ - MICROPY_PY_TERMIOS=0 MICROPY_PY_USSL=0 \ - MICROPY_USE_READLINE=0 + $(MAKE) VARIANT=minimal -# build interpreter with nan-boxing as object model nanbox: - $(MAKE) \ - CFLAGS_EXTRA='-DMP_CONFIGFILE=""' \ - BUILD=build-nanbox \ - PROG=micropython_nanbox \ - MICROPY_FORCE_32BIT=1 + $(MAKE) VARIANT=nanbox freedos: - $(MAKE) \ - CC=i586-pc-msdosdjgpp-gcc \ - STRIP=i586-pc-msdosdjgpp-strip \ - SIZE=i586-pc-msdosdjgpp-size \ - CFLAGS_EXTRA='-DMP_CONFIGFILE="" -DMICROPY_NLR_SETJMP -Dtgamma=gamma -DMICROPY_EMIT_X86=0 -DMICROPY_NO_ALLOCA=1 -DMICROPY_PY_USELECT_POSIX=0' \ - BUILD=build-freedos \ - PROG=micropython_freedos \ - MICROPY_PY_SOCKET=0 \ - MICROPY_PY_FFI=0 \ - MICROPY_PY_JNI=0 \ - MICROPY_PY_BTREE=0 \ - MICROPY_PY_THREAD=0 \ - MICROPY_PY_USSL=0 + $(MAKE) VARIANT=freedos -# build an interpreter for coverage testing and do the testing coverage: - $(MAKE) \ - COPT="-O0" CFLAGS_EXTRA='$(CFLAGS_EXTRA) -DMP_CONFIGFILE="" \ - -fprofile-arcs -ftest-coverage \ - -Wdouble-promotion -Wformat -Wmissing-declarations -Wmissing-prototypes -Wsign-compare \ - -Wold-style-definition -Wpointer-arith -Wshadow -Wuninitialized -Wunused-parameter \ - -DMICROPY_UNIX_COVERAGE' \ - LDFLAGS_EXTRA='-fprofile-arcs -ftest-coverage' \ - MICROPY_VFS_FAT=1 MICROPY_VFS_LFS1=1 MICROPY_VFS_LFS2=1 \ - FROZEN_MANIFEST=manifest_coverage.py \ - BUILD=build-coverage PROG=micropython_coverage - -coverage_test: coverage - $(eval DIRNAME=ports/$(notdir $(CURDIR))) - cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests - cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests -d thread - cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests --emit native - cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests --via-mpy -d basics float micropython - cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/micropython_coverage ./run-tests --via-mpy --emit native -d basics float micropython - cat $(TOP)/tests/basics/0prelim.py | ./micropython_coverage | grep -q 'abc' - gcov -o build-coverage/py $(TOP)/py/*.c - gcov -o build-coverage/extmod $(TOP)/extmod/*.c + $(MAKE) VARIANT=coverage +coverage_test: + $(MAKE) VARIANT=coverage test_gcov # Value of configure's --host= option (required for cross-compilation). # Deduce it from CROSS_COMPILE by default, but can be overridden. diff --git a/ports/unix/mpconfigport.h b/ports/unix/mpconfigport.h index d633726a16..f435c3ff3c 100644 --- a/ports/unix/mpconfigport.h +++ b/ports/unix/mpconfigport.h @@ -24,7 +24,15 @@ * THE SOFTWARE. */ -// options to control how MicroPython is built +// Options to control how MicroPython is built for this port, +// overriding defaults in py/mpconfig.h. + +// Variant-specific definitions. +#include "mpconfigvariant.h" + +// The minimal variant's config covers everything. +// If we're building the minimal variant, ignore the rest of this file. +#ifndef MICROPY_UNIX_MINIMAL #define MICROPY_ALLOC_PATH_MAX (PATH_MAX) #define MICROPY_PERSISTENT_CODE_LOAD (1) @@ -64,7 +72,9 @@ #define MICROPY_ENABLE_SOURCE_LINE (1) #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) +#ifndef MICROPY_STREAMS_NON_BLOCK #define MICROPY_STREAMS_NON_BLOCK (1) +#endif #define MICROPY_STREAMS_POSIX_API (1) #define MICROPY_OPT_COMPUTED_GOTO (1) #ifndef MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE @@ -97,11 +107,13 @@ #define MICROPY_PERSISTENT_CODE_SAVE (1) #define MICROPY_COMP_CONST (0) #endif +#ifndef MICROPY_PY_SYS_PLATFORM #if defined(__APPLE__) && defined(__MACH__) #define MICROPY_PY_SYS_PLATFORM "darwin" #else #define MICROPY_PY_SYS_PLATFORM "linux" #endif +#endif #define MICROPY_PY_SYS_MAXSIZE (1) #define MICROPY_PY_SYS_STDFILES (1) #define MICROPY_PY_SYS_EXC_INFO (1) @@ -331,3 +343,5 @@ void mp_unix_mark_exec(void); // For debugging purposes, make printf() available to any source file. #include #endif + +#endif // MICROPY_UNIX_MINIMAL diff --git a/ports/unix/mpconfigport_coverage.h b/ports/unix/variants/coverage/mpconfigvariant.h similarity index 94% rename from ports/unix/mpconfigport_coverage.h rename to ports/unix/variants/coverage/mpconfigvariant.h index 8a0bf3be48..f383a83700 100644 --- a/ports/unix/mpconfigport_coverage.h +++ b/ports/unix/variants/coverage/mpconfigvariant.h @@ -24,14 +24,12 @@ * THE SOFTWARE. */ -// Default unix config while intended to be comprehensive, may still not enable -// all the features, this config should enable more (testable) options. +// This config enables almost all possible features such that it can be used +// for coverage testing. #define MICROPY_VFS (1) #define MICROPY_PY_UOS_VFS (1) -#include - #define MICROPY_OPT_MATH_FACTORIAL (1) #define MICROPY_FLOAT_HIGH_QUALITY_HASH (1) #define MICROPY_ENABLE_SCHEDULER (1) diff --git a/ports/unix/variants/coverage/mpconfigvariant.mk b/ports/unix/variants/coverage/mpconfigvariant.mk new file mode 100644 index 0000000000..e55b22eb92 --- /dev/null +++ b/ports/unix/variants/coverage/mpconfigvariant.mk @@ -0,0 +1,17 @@ +PROG ?= micropython_coverage + +COPT = -O0 + +CFLAGS_EXTRA += \ + -fprofile-arcs -ftest-coverage \ + -Wdouble-promotion -Wformat -Wmissing-declarations -Wmissing-prototypes -Wsign-compare \ + -Wold-style-definition -Wpointer-arith -Wshadow -Wuninitialized -Wunused-parameter \ + -DMICROPY_UNIX_COVERAGE + +LDFLAGS_EXTRA += -fprofile-arcs -ftest-coverage + +FROZEN_MANIFEST = manifest_coverage.py + +MICROPY_VFS_FAT = 1 +MICROPY_VFS_LFS1 = 1 +MICROPY_VFS_LFS2 = 1 diff --git a/ports/unix/mpconfigport_fast.h b/ports/unix/variants/fast/mpconfigvariant.h similarity index 97% rename from ports/unix/mpconfigport_fast.h rename to ports/unix/variants/fast/mpconfigvariant.h index 193567a294..6d73275fde 100644 --- a/ports/unix/mpconfigport_fast.h +++ b/ports/unix/variants/fast/mpconfigvariant.h @@ -28,8 +28,9 @@ // synthetic benchmarking, at the expense of features supported and memory // usage. This config is not intended to be used in production. -#include #define MICROPY_PY___FILE__ (0) // 91 is a magic number proposed by @dpgeorge, which make pystone run ~ at tie // with CPython 3.4. #define MICROPY_MODULE_DICT_SIZE (91) + +#include "variants/DEV/mpconfigvariant.h" diff --git a/ports/unix/variants/fast/mpconfigvariant.mk b/ports/unix/variants/fast/mpconfigvariant.mk new file mode 100644 index 0000000000..60c1d525d3 --- /dev/null +++ b/ports/unix/variants/fast/mpconfigvariant.mk @@ -0,0 +1,7 @@ +# build synthetically fast interpreter for benchmarking + +COPT = "-O2 -DNDEBUG -fno-crossjumping" + +PROG = micropython_fast + +FROZEN_MANIFEST = diff --git a/ports/unix/mpconfigport_freedos.h b/ports/unix/variants/freedos/mpconfigvariant.h similarity index 94% rename from ports/unix/mpconfigport_freedos.h rename to ports/unix/variants/freedos/mpconfigvariant.h index 09c85ab1e3..338b34492d 100644 --- a/ports/unix/mpconfigport_freedos.h +++ b/ports/unix/variants/freedos/mpconfigvariant.h @@ -26,15 +26,15 @@ // options to control how MicroPython is built -#include +#define MICROPY_PY_USELECT_POSIX (0) -#undef MICROPY_STREAMS_NON_BLOCK #define MICROPY_STREAMS_NON_BLOCK (0) -#undef MICROPY_PY_SYS_PLATFORM #define MICROPY_PY_SYS_PLATFORM "freedos" // djgpp dirent struct does not have d_ino field #undef _DIRENT_HAVE_D_INO #define MICROPY_USE_INTERNAL_ERRNO (1) + +#include "variants/DEV/mpconfigvariant.h" diff --git a/ports/unix/variants/freedos/mpconfigvariant.mk b/ports/unix/variants/freedos/mpconfigvariant.mk new file mode 100644 index 0000000000..f1d0ac21b0 --- /dev/null +++ b/ports/unix/variants/freedos/mpconfigvariant.mk @@ -0,0 +1,20 @@ +CC = i586-pc-msdosdjgpp-gcc + +STRIP = i586-pc-msdosdjgpp-strip + +SIZE = i586-pc-msdosdjgpp-size + +CFLAGS_EXTRA = \ + -DMICROPY_NLR_SETJMP \ + -Dtgamma=gamma \ + -DMICROPY_EMIT_X86=0 \ + -DMICROPY_NO_ALLOCA=1 \ + +PROG = micropython_freedos + +MICROPY_PY_SOCKET = 0 +MICROPY_PY_FFI = 0 +MICROPY_PY_JNI = 0 +MICROPY_PY_BTREE = 0 +MICROPY_PY_THREAD = 0 +MICROPY_PY_USSL = 0 diff --git a/ports/unix/mpconfigport_minimal.h b/ports/unix/variants/minimal/mpconfigvariant.h similarity index 98% rename from ports/unix/mpconfigport_minimal.h rename to ports/unix/variants/minimal/mpconfigvariant.h index c49819e742..e961ff4b24 100644 --- a/ports/unix/mpconfigport_minimal.h +++ b/ports/unix/variants/minimal/mpconfigvariant.h @@ -26,6 +26,9 @@ // options to control how MicroPython is built +// Prevent the rest of the default mpconfigport.h being used. +#define MICROPY_UNIX_MINIMAL (1) + #define MICROPY_ALLOC_QSTR_CHUNK_INIT (64) #define MICROPY_ALLOC_PARSE_RULE_INIT (8) #define MICROPY_ALLOC_PARSE_RULE_INC (8) diff --git a/ports/unix/variants/minimal/mpconfigvariant.mk b/ports/unix/variants/minimal/mpconfigvariant.mk new file mode 100644 index 0000000000..19f8ad64a3 --- /dev/null +++ b/ports/unix/variants/minimal/mpconfigvariant.mk @@ -0,0 +1,14 @@ +# build a minimal interpreter +COPT = -Os -DNDEBUG + +PROG = micropython_minimal + +FROZEN_MANIFEST = + +MICROPY_PY_BTREE = 0 +MICROPY_PY_FFI = 0 +MICROPY_PY_SOCKET = 0 +MICROPY_PY_THREAD = 0 +MICROPY_PY_TERMIOS = 0 +MICROPY_PY_USSL = 0 +MICROPY_USE_READLINE = 0 diff --git a/ports/unix/mpconfigport_nanbox.h b/ports/unix/variants/nanbox/mpconfigvariant.h similarity index 90% rename from ports/unix/mpconfigport_nanbox.h rename to ports/unix/variants/nanbox/mpconfigvariant.h index 7da2cf7b80..f827158fb7 100644 --- a/ports/unix/mpconfigport_nanbox.h +++ b/ports/unix/variants/nanbox/mpconfigvariant.h @@ -24,6 +24,10 @@ * THE SOFTWARE. */ +// This config is mostly used to ensure that the nan-boxing object model +// continues to build (i.e. catches usage of mp_obj_t that don't work with +// this representation). + // select nan-boxing object model #define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_D) @@ -39,5 +43,3 @@ typedef int64_t mp_int_t; typedef uint64_t mp_uint_t; #define UINT_FMT "%llu" #define INT_FMT "%lld" - -#include diff --git a/ports/unix/variants/nanbox/mpconfigvariant.mk b/ports/unix/variants/nanbox/mpconfigvariant.mk new file mode 100644 index 0000000000..b7b485b512 --- /dev/null +++ b/ports/unix/variants/nanbox/mpconfigvariant.mk @@ -0,0 +1,4 @@ +# build interpreter with nan-boxing as object model (object repr D) +PROG = micropython_nanbox + +MICROPY_FORCE_32BIT = 1 diff --git a/ports/unix/variants/standard/mpconfigvariant.h b/ports/unix/variants/standard/mpconfigvariant.h new file mode 100644 index 0000000000..79b8fe2a3b --- /dev/null +++ b/ports/unix/variants/standard/mpconfigvariant.h @@ -0,0 +1,26 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 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. + */ + diff --git a/ports/unix/variants/standard/mpconfigvariant.mk b/ports/unix/variants/standard/mpconfigvariant.mk new file mode 100644 index 0000000000..28fad7be77 --- /dev/null +++ b/ports/unix/variants/standard/mpconfigvariant.mk @@ -0,0 +1,16 @@ +# This is the default variant when you `make` the Unix port. + +PROG ?= micropython + +# install micropython in /usr/local/bin +TARGET = micropython +PREFIX = $(DESTDIR)/usr/local +BINDIR = $(PREFIX)/bin + +install: micropython + install -d $(BINDIR) + install $(TARGET) $(BINDIR)/$(TARGET) + +# uninstall micropython +uninstall: + -rm $(BINDIR)/$(TARGET)