Skip to content

Commit 136f675

Browse files
committed
Factor and simplify Makefile's and mpconfig.
1 parent 880ce2d commit 136f675

11 files changed

Lines changed: 276 additions & 257 deletions

File tree

py/mpconfig.h

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,72 @@
44

55
#include <mpconfigport.h>
66

7-
#ifndef INT_FMT
8-
// printf format spec to use for machine_int_t and friends
9-
#ifdef __LP64__
10-
// Archs where machine_int_t == long, long != int
11-
#define UINT_FMT "%lu"
12-
#define INT_FMT "%ld"
13-
#else
14-
// Archs where machine_int_t == int
15-
#define UINT_FMT "%u"
16-
#define INT_FMT "%d"
7+
// Any options not explicitly set in mpconfigport.h will get default
8+
// values below.
9+
10+
/*****************************************************************************/
11+
/* Micro Python emitters */
12+
13+
// Whether to emit CPython byte codes (for debugging/testing)
14+
// Enabling this overrides all other emitters
15+
#ifndef MICROPY_EMIT_CPYTHON
16+
#define MICROPY_EMIT_CPYTHON (0)
17+
#endif
18+
19+
// Whether to emit x64 native code
20+
#ifndef MICROPY_EMIT_X64
21+
#define MICROPY_EMIT_X64 (0)
1722
#endif
18-
#endif //INT_FMT
1923

24+
// Whether to emit thumb native code
25+
#ifndef MICROPY_EMIT_THUMB
26+
#define MICROPY_EMIT_THUMB (0)
27+
#endif
2028

21-
// Any options not explicitly set in mpconfigport.h will get default
22-
// values below.
29+
// Whether to enable the thumb inline assembler
30+
#ifndef MICROPY_EMIT_INLINE_THUMB
31+
#define MICROPY_EMIT_INLINE_THUMB (0)
32+
#endif
33+
34+
/*****************************************************************************/
35+
/* Internal debugging stuff */
2336

2437
// Whether to collect memory allocation stats
2538
#ifndef MICROPY_MEM_STATS
26-
#define MICROPY_MEM_STATS (1)
39+
#define MICROPY_MEM_STATS (0)
40+
#endif
41+
42+
/*****************************************************************************/
43+
/* Fine control over Python features */
44+
45+
// Whether to include REPL helper function
46+
#ifndef MICROPY_ENABLE_REPL_HELPERS
47+
#define MICROPY_ENABLE_REPL_HELPERS (0)
48+
#endif
49+
50+
// Whether to support float and complex types
51+
#ifndef MICROPY_ENABLE_FLOAT
52+
#define MICROPY_ENABLE_FLOAT (0)
2753
#endif
2854

2955
// Whether to support slice object and correspondingly
3056
// slice subscript operators
3157
#ifndef MICROPY_ENABLE_SLICE
3258
#define MICROPY_ENABLE_SLICE (1)
3359
#endif
60+
61+
/*****************************************************************************/
62+
/* Miscellaneous settings */
63+
64+
// printf format spec to use for machine_int_t and friends
65+
#ifndef INT_FMT
66+
#ifdef __LP64__
67+
// Archs where machine_int_t == long, long != int
68+
#define UINT_FMT "%lu"
69+
#define INT_FMT "%ld"
70+
#else
71+
// Archs where machine_int_t == int
72+
#define UINT_FMT "%u"
73+
#define INT_FMT "%d"
74+
#endif
75+
#endif //INT_FMT

py/py.mk

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# default settings; can be overriden in main Makefile
2+
3+
ifndef PY_SRC
4+
PY_SRC = ../py
5+
endif
6+
7+
ifndef BUILD
8+
BUILD = build
9+
endif
10+
11+
# to create the build directory
12+
13+
$(BUILD):
14+
mkdir -p $@
15+
16+
# where py object files go (they have a name prefix to prevent filename clashes)
17+
18+
PY_BUILD = $(BUILD)/py.
19+
20+
# py object files
21+
22+
PY_O_BASENAME = \
23+
nlrx86.o \
24+
nlrx64.o \
25+
nlrthumb.o \
26+
malloc.o \
27+
qstr.o \
28+
vstr.o \
29+
unicode.o \
30+
lexer.o \
31+
lexerunix.o \
32+
parse.o \
33+
scope.o \
34+
compile.o \
35+
emitcommon.o \
36+
emitpass1.o \
37+
emitcpy.o \
38+
emitbc.o \
39+
asmx64.o \
40+
emitnx64.o \
41+
asmthumb.o \
42+
emitnthumb.o \
43+
emitinlinethumb.o \
44+
runtime.o \
45+
map.o \
46+
obj.o \
47+
objbool.o \
48+
objboundmeth.o \
49+
objcell.o \
50+
objclass.o \
51+
objclosure.o \
52+
objcomplex.o \
53+
objdict.o \
54+
objexcept.o \
55+
objfloat.o \
56+
objfun.o \
57+
objgenerator.o \
58+
objinstance.o \
59+
objint.o \
60+
objlist.o \
61+
objmodule.o \
62+
objnone.o \
63+
objrange.o \
64+
objset.o \
65+
objslice.o \
66+
objstr.o \
67+
objtuple.o \
68+
objtype.o \
69+
builtin.o \
70+
builtinimport.o \
71+
vm.o \
72+
showbc.o \
73+
repl.o \
74+
75+
# prepend the build destination prefix to the py object files
76+
77+
PY_O = $(addprefix $(PY_BUILD), $(PY_O_BASENAME))
78+
79+
$(PY_BUILD)emitnx64.o: $(PY_SRC)/emitnative.c $(PY_SRC)/emit.h mpconfigport.h
80+
$(CC) $(CFLAGS) -DN_X64 -c -o $@ $<
81+
82+
$(PY_BUILD)emitnthumb.o: $(PY_SRC)/emitnative.c $(PY_SRC)/emit.h mpconfigport.h
83+
$(CC) $(CFLAGS) -DN_THUMB -c -o $@ $<
84+
85+
$(PY_BUILD)%.o: $(PY_SRC)/%.S
86+
$(CC) $(CFLAGS) -c -o $@ $<
87+
88+
$(PY_BUILD)%.o: $(PY_SRC)/%.c mpconfigport.h
89+
$(CC) $(CFLAGS) -c -o $@ $<
90+
91+
# optimising vm for speed, adds only a small amount to code size but makes a huge difference to speed (20% faster)
92+
$(PY_BUILD)vm.o: $(PY_SRC)/vm.c
93+
$(CC) $(CFLAGS) -O3 -c -o $@ $<
94+
95+
# header dependencies
96+
97+
$(PY_BUILD)parse.o: $(PY_SRC)/grammar.h
98+
$(PY_BUILD)compile.o: $(PY_SRC)/grammar.h
99+
$(PY_BUILD)/emitcpy.o: $(PY_SRC)/emit.h
100+
$(PY_BUILD)emitbc.o: $(PY_SRC)/emit.h

py/repl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "misc.h"
2+
#include "mpconfig.h"
23
#include "repl.h"
34

5+
#if MICROPY_ENABLE_REPL_HELPERS
6+
47
bool str_startswith_word(const char *str, const char *head) {
58
int i;
69
for (i = 0; str[i] && head[i]; i++) {
@@ -42,3 +45,5 @@ bool mp_repl_is_compound_stmt(const char *line) {
4245
}
4346
return n_paren > 0 || n_brack > 0 || n_brace > 0;
4447
}
48+
49+
#endif // MICROPY_ENABLE_REPL_HELPERS

py/repl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
#if MICROPY_ENABLE_REPL_HELPERS
12
bool mp_repl_is_compound_stmt(const char *line);
3+
#endif

stm/mpconfigport.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
// options to control how Micro Python is built
44

5-
#define MICROPY_ENABLE_FLOAT (1)
6-
#define MICROPY_EMIT_CPYTHON (0)
7-
#define MICROPY_EMIT_X64 (0)
85
#define MICROPY_EMIT_THUMB (1)
96
#define MICROPY_EMIT_INLINE_THUMB (1)
7+
#define MICROPY_ENABLE_REPL_HELPERS (1)
8+
#define MICROPY_ENABLE_FLOAT (1)
109

1110
// type definitions for the specific machine
1211

unix-cpy/Makefile

Lines changed: 18 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,37 @@
1-
PYSRC=../py
2-
BUILD=build
1+
# define main target
2+
PROG = cpy
3+
all: $(PROG)
4+
5+
# include py core make definitions
6+
include ../py/py.mk
37

8+
# program for deletion
9+
RM = /bin/rm
10+
11+
# compiler settings
412
CC = gcc
5-
CFLAGS = -I. -I$(PYSRC) -Wall -Werror -ansi -std=gnu99 -Os #-DNDEBUG
13+
CFLAGS = -I. -I$(PY_SRC) -Wall -Werror -ansi -std=gnu99 -Os #-DNDEBUG
614
LDFLAGS = -lm
715

16+
# source files
817
SRC_C = \
918
main.c \
1019

11-
PY_O = \
12-
nlrx86.o \
13-
nlrx64.o \
14-
malloc.o \
15-
qstr.o \
16-
vstr.o \
17-
unicode.o \
18-
lexer.o \
19-
lexerunix.o \
20-
parse.o \
21-
scope.o \
22-
compile.o \
23-
emitcommon.o \
24-
emitpass1.o \
25-
emitcpy.o \
26-
runtime.o \
27-
map.o \
28-
obj.o \
29-
objbool.o \
30-
objboundmeth.o \
31-
objcell.o \
32-
objclass.o \
33-
objclosure.o \
34-
objcomplex.o \
35-
objdict.o \
36-
objexcept.o \
37-
objfloat.o \
38-
objfun.o \
39-
objgenerator.o \
40-
objinstance.o \
41-
objint.o \
42-
objlist.o \
43-
objmodule.o \
44-
objnone.o \
45-
objrange.o \
46-
objset.o \
47-
objslice.o \
48-
objstr.o \
49-
objtuple.o \
50-
objtype.o \
51-
builtin.o \
52-
builtinimport.o \
53-
vm.o \
54-
showbc.o \
55-
repl.o \
56-
57-
OBJ = $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(PY_O))
20+
OBJ = $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) $(PY_O)
5821
LIB =
59-
PROG = cpy
6022

6123
$(PROG): $(BUILD) $(OBJ)
6224
$(CC) -o $@ $(OBJ) $(LIB) $(LDFLAGS)
63-
64-
$(BUILD):
65-
mkdir -p $@
25+
strip $(PROG)
26+
size $(PROG)
6627

6728
$(BUILD)/%.o: %.c
6829
$(CC) $(CFLAGS) -c -o $@ $<
6930

70-
$(BUILD)/%.o: $(PYSRC)/%.S
71-
$(CC) $(CFLAGS) -c -o $@ $<
72-
73-
$(BUILD)/%.o: $(PYSRC)/%.c mpconfigport.h
74-
$(CC) $(CFLAGS) -c -o $@ $<
75-
76-
$(BUILD)/emitnx64.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h
77-
$(CC) $(CFLAGS) -DN_X64 -c -o $@ $<
78-
79-
$(BUILD)/emitnthumb.o: $(PYSRC)/emitnative.c $(PYSRC)/emit.h
80-
$(CC) $(CFLAGS) -DN_THUMB -c -o $@ $<
81-
82-
# optimising vm for speed, adds only a small amount to code size but makes a huge difference to speed (20% faster)
83-
$(BUILD)/vm.o: $(PYSRC)/vm.c
84-
$(CC) $(CFLAGS) -O3 -c -o $@ $<
85-
8631
$(BUILD)/main.o: mpconfigport.h
87-
$(BUILD)/parse.o: $(PYSRC)/grammar.h
88-
$(BUILD)/compile.o: $(PYSRC)/grammar.h
89-
$(BUILD)/emitcpy.o: $(PYSRC)/emit.h
90-
$(BUILD)/emitbc.o: $(PYSRC)/emit.h
9132

9233
clean:
93-
/bin/rm -rf $(BUILD)
34+
$(RM) -f $(PROG)
35+
$(RM) -rf $(BUILD)
9436

95-
.PHONY: clean
37+
.PHONY: all clean

unix-cpy/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "obj.h"
1212
#include "compile.h"
1313
#include "runtime0.h"
14-
#include "runtime.h"
1514

1615
void do_file(const char *file) {
1716
mp_lexer_t *lex = mp_lexer_new_from_file(file);

unix-cpy/mpconfigport.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
#define MICROPY_ENABLE_FLOAT (1)
44
#define MICROPY_EMIT_CPYTHON (1)
5-
#define MICROPY_EMIT_X64 (0)
6-
#define MICROPY_EMIT_THUMB (0)
7-
#define MICROPY_EMIT_INLINE_THUMB (0)
85

96
// type definitions for the specific machine
107

0 commit comments

Comments
 (0)