unix: Add build variants, analogous to boards on bare-metal.
Invoking "make" will still build the standard "micropython" executable, but other variants are now build using, eg, "make VARIANT=minimal". This follows how bare-metal ports specify a particular board, and allows running any make target (eg clean, test) with any variant. Convenience targets (eg "make coverage") are provided to retain the old behaviour, at least for now. See issue #3043.
This commit is contained in:
parent
7d2ccd027f
commit
bd2fff6687
@ -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="<mpconfigport_fast.h>"' BUILD=build-fast PROG=micropython_fast FROZEN_MANIFEST=
|
||||
$(MAKE) VARIANT=fast
|
||||
|
||||
# build a minimal interpreter
|
||||
minimal:
|
||||
$(MAKE) COPT="-Os -DNDEBUG" CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_minimal.h>"' \
|
||||
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="<mpconfigport_nanbox.h>"' \
|
||||
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="<mpconfigport_freedos.h>" -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="<mpconfigport_coverage.h>" \
|
||||
-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.
|
||||
|
@ -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 <stdio.h>
|
||||
#endif
|
||||
|
||||
#endif // MICROPY_UNIX_MINIMAL
|
||||
|
@ -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 <mpconfigport.h>
|
||||
|
||||
#define MICROPY_OPT_MATH_FACTORIAL (1)
|
||||
#define MICROPY_FLOAT_HIGH_QUALITY_HASH (1)
|
||||
#define MICROPY_ENABLE_SCHEDULER (1)
|
17
ports/unix/variants/coverage/mpconfigvariant.mk
Normal file
17
ports/unix/variants/coverage/mpconfigvariant.mk
Normal file
@ -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
|
@ -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 <mpconfigport.h>
|
||||
#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"
|
7
ports/unix/variants/fast/mpconfigvariant.mk
Normal file
7
ports/unix/variants/fast/mpconfigvariant.mk
Normal file
@ -0,0 +1,7 @@
|
||||
# build synthetically fast interpreter for benchmarking
|
||||
|
||||
COPT = "-O2 -DNDEBUG -fno-crossjumping"
|
||||
|
||||
PROG = micropython_fast
|
||||
|
||||
FROZEN_MANIFEST =
|
@ -26,15 +26,15 @@
|
||||
|
||||
// options to control how MicroPython is built
|
||||
|
||||
#include <mpconfigport.h>
|
||||
#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"
|
20
ports/unix/variants/freedos/mpconfigvariant.mk
Normal file
20
ports/unix/variants/freedos/mpconfigvariant.mk
Normal file
@ -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
|
@ -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)
|
14
ports/unix/variants/minimal/mpconfigvariant.mk
Normal file
14
ports/unix/variants/minimal/mpconfigvariant.mk
Normal file
@ -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
|
@ -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 <mpconfigport.h>
|
4
ports/unix/variants/nanbox/mpconfigvariant.mk
Normal file
4
ports/unix/variants/nanbox/mpconfigvariant.mk
Normal file
@ -0,0 +1,4 @@
|
||||
# build interpreter with nan-boxing as object model (object repr D)
|
||||
PROG = micropython_nanbox
|
||||
|
||||
MICROPY_FORCE_32BIT = 1
|
26
ports/unix/variants/standard/mpconfigvariant.h
Normal file
26
ports/unix/variants/standard/mpconfigvariant.h
Normal file
@ -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.
|
||||
*/
|
||||
|
16
ports/unix/variants/standard/mpconfigvariant.mk
Normal file
16
ports/unix/variants/standard/mpconfigvariant.mk
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user