generated from BrianPugh/python-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
195 lines (155 loc) · 5.94 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
.PHONY: clean test collect-data venv
ifdef MPY_DIR
# Native machine code in .mpy files
# User can define architecture in call like "make ARCH=armv6m"
# Options:
# * x86
# * x64
# * armv6m
# * armv7m
# * armv7emsp
# * armv7emdp
# * xtensa
# * xtensawin
ARCH ?= x64
MOD = tamp
TAMP_COMPRESSOR ?= 1 # Include Tamp compressor in build
TAMP_DECOMPRESSOR ?= 1 # Include Tamp decompressor in build
CFLAGS += -Itamp/_c_src -DTAMP_COMPRESSOR=${TAMP_COMPRESSOR} -DTAMP_DECOMPRESSOR=${TAMP_DECOMPRESSOR}
ifneq ($(CC),clang)
CFLAGS += -fno-tree-loop-distribute-patterns
endif
SRC = tamp/_c_src/tamp/common.c mpy_bindings/bindings.c mpy_bindings/bindings_common.py
ifeq ($(strip $(TAMP_COMPRESSOR)),1)
SRC += mpy_bindings/bindings_compressor.py tamp/_c_src/tamp/compressor.c
endif
ifeq ($(strip $(TAMP_DECOMPRESSOR)),1)
SRC += mpy_bindings/bindings_decompressor.py tamp/_c_src/tamp/decompressor.c
endif
MPY_CROSS_FLAGS = -s $(subst compressor,c,$(subst decompressor,d,$(subst bindings,m,$(notdir $<))))
include $(MPY_DIR)/py/dynruntime.mk
endif
venv:
@. .venv/bin/activate
clean-cython:
@rm -rf tamp/*.so
@rm -rf tamp/_c_compressor.c
@rm -rf tamp/_c_decompressor.c
@rm -rf tamp/_c_common.c
clean: clean-cython
@rm -rf build
@rm -rf dist
build/enwik8:
if [ ! -f build/enwik8 ]; then \
mkdir -p build; \
cd build; \
curl -O https://mattmahoney.net/dc/enwik8.zip; \
unzip -q enwik8.zip; \
rm enwik8.zip; \
cd ..; \
fi
download-enwik8: build/enwik8
build/silesia:
if [ ! -f build/silesia ]; then \
mkdir -p build; \
cd build; \
curl -O http://mattmahoney.net/dc/silesia.zip; \
mkdir silesia; \
unzip -q silesia.zip -d silesia; \
rm silesia.zip; \
cd ..; \
fi
download-silesia: build/silesia
build/enwik8-100kb: download-enwik8
@head -c 100000 build/enwik8 > build/enwik8-100kb
build/enwik8-100kb.tamp: build/enwik8-100kb
@poetry run tamp compress build/enwik8-100kb -o build/enwik8-100kb.tamp
test: venv
@poetry run python build.py build_ext --inplace && python -m pytest
@poetry run belay run micropython -m unittest tests/*.py
@echo "All Tests Passed!"
collect-data: venv download-enwik8
@python tools/collect-data.py 8
@python tools/collect-data.py 9
@python tools/collect-data.py 10
on-device-compression-benchmark: venv build/enwik8-100kb build/enwik8-100kb.tamp
@port=$$(python -c "import os, belay; print(belay.UsbSpecifier.parse_raw(os.environ['BELAY_DEVICE']).to_port())"); \
echo "Using port: $$port"; \
mpremote connect port:$$port rm :enwik8-100kb.tamp || true; \
belay sync '$(BELAY_DEVICE)' build/enwik8-100kb; \
belay install '$(BELAY_DEVICE)' --with=dev --run tools/on-device-compression-benchmark.py; \
mpremote connect port:$$port cp :enwik8-100kb.tamp build/on-device-enwik8-100kb.tamp; \
cmp build/enwik8-100kb.tamp build/on-device-enwik8-100kb.tamp; \
echo "Success!"
on-device-decompression-benchmark: venv build/enwik8-100kb.tamp
@port=$$(python -c "import os, belay; print(belay.UsbSpecifier.parse_raw(os.environ['BELAY_DEVICE']).to_port())"); \
echo "Using port: $$port"; \
mpremote connect port:$$port rm :enwik8-100kb-decompressed || true; \
belay sync '$(BELAY_DEVICE)' build/enwik8-100kb.tamp; \
belay install '$(BELAY_DEVICE)' --with=dev --run tools/on-device-decompression-benchmark.py; \
mpremote connect port:$$port cp :enwik8-100kb-decompressed build/on-device-enwik8-100kb-decompressed; \
cmp build/enwik8-100kb build/on-device-enwik8-100kb-decompressed; \
echo "Success!"
mpy-size:
@mpy-cross -O3 -march=armv6m tamp/__init__.py; \
size_init=$$(cat tamp/__init__.mpy | wc -c); \
mpy-cross -O3 -march=armv6m tamp/compressor_viper.py; \
size_co_viper=$$(cat tamp/compressor_viper.mpy | wc -c); \
mpy-cross -O3 -march=armv6m tamp/decompressor_viper.py; \
size_de_viper=$$(cat tamp/decompressor_viper.mpy | wc -c); \
total_viper=$$((size_init + size_co_viper)); \
total_de_viper=$$((size_init + size_de_viper)); \
total_all=$$((size_init + size_co_viper + size_de_viper)); \
printf '__init__.py\t\t\t\t\t\t%s\n' $$size_init; \
printf 'compressor_viper.py\t\t\t\t\t%s\n' $$size_co_viper; \
printf 'decompressor_viper.py\t\t\t\t\t%s\n' $$size_de_viper; \
printf '__init__ + compressor_viper\t\t\t\t%s\n' $$total_viper; \
printf '__init__ + decompressor_viper\t\t\t\t%s\n' $$total_de_viper; \
printf '__init__ + compressor_viper + decompressor_viper\t%s\n' $$total_all
mpy-compression-benchmark:
@time belay run micropython -X heapsize=300M tools/micropython-compression-benchmark.py
CTEST_CC = gcc
CTEST_CFLAGS = -Ictests/Unity/src -Itamp/_c_src
CTEST_LDFLAGS = -Lctests/unity
CTEST_LIBS = -lunity
mkdir-build:
mkdir -p build
mkdir -p build/ctests
mkdir -p build/unity
TAMP_OBJS = \
build/common.o \
build/compressor.o \
build/decompressor.o
CTEST_OBJS = \
build/unity/unity.o \
build/ctests/test_decompressor.o
build/%.o: tamp/_c_src/tamp/%.c mkdir-build
$(CTEST_CC) $(CTEST_CFLAGS) -c $< -o $@
build/unity/%.o:: ctests/Unity/src/%.c ctests/Unity/src/%.h
$(CTEST_CC) $(CTEST_CFLAGS) -c $< -o $@
build/ctests/%.o: ctests/%.c
$(CTEST_CC) $(CTEST_CFLAGS) -c $< -o $@
build/test_runner: $(TAMP_OBJS) $(CTEST_OBJS)
$(CTEST_CC) $(CTEST_CFLAGS) $(CTEST_LDFLAGS) -o $@ $^ $(LIBS)
c-test: build/test_runner
./build/test_runner
#############
# C Library #
#############
# This section is primarily to build a library to check for implementation size.
BUILDDIR = build
SRCDIR = tamp/_c_src
LIB_CFLAGS = -Os -Wall -I$(SRCDIR) -ffunction-sections -fdata-sections -m32
SRCS = tamp/_c_src/tamp/common.c tamp/_c_src/tamp/compressor.c tamp/_c_src/tamp/decompressor.c
HEADERS = tamp/_c_src/tamp/decompressor.h tamp/_c_src/tamp/compressor.h tamp/_c_src/tamp/common.h
# Define the object files
OBJS = $(patsubst $(SRCDIR)/%.c,$(BUILDDIR)/%.o,$(SRCS))
# Rule to create the target
build/tamp.a: $(OBJS)
$(AR) rcs $@ $^
tamp-c-library: build/tamp.a
.PHONY: tamp-c-library
# Rule to create object files
$(BUILDDIR)/%.o: $(SRCDIR)/%.c $(HEADERS)
@mkdir -p $(dir $@)
$(CC) $(LIB_CFLAGS) -c $< -o $@