-
Notifications
You must be signed in to change notification settings - Fork 48
/
Makefile
184 lines (162 loc) · 6.71 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
DIR = $(shell pwd)
MAJOR_VERSION = $(shell git describe --abbrev=0 --tags)
MINOR_VERSION = $(shell git rev-list ${MAJOR_VERSION}.. --count)
VERSION = ${MAJOR_VERSION}.${MINOR_VERSION}
.DEFAULT_GOAL := bin/ferret
.PHONY: clean repl test-compiler test deb deb-repo clojars docs release docker-build docker-bash docker-release docker-test
.DELETE_ON_ERROR:
CPPWARNINGS = -pedantic -Werror -Wall -Wextra \
-Wconversion -Wpointer-arith -Wmissing-braces \
-Woverloaded-virtual -Wuninitialized -Winit-self \
-Wsign-conversion -ggdb
CPPFLAGS = -std=c++11 -fno-rtti ${CPPWARNINGS} -pthread -I src/runtime/
CPP_SANITIZE_FLAGS += -fsanitize=undefined,address,leak
CPPCHECK_CONF = -DFERRET_STD_LIB
define static_check
cppcheck --quiet\
${CPPCHECK_CONF} \
--language=c++ --std=c++11 --template=gcc --enable=all\
--inline-suppr\
--suppress=preprocessorErrorDirective:$1 \
--suppress=unusedFunction:$1\
--suppress=missingIncludeSystem:$1\
--suppress=unmatchedSuppression:$1\
--error-exitcode=1 $1 2> "$1.cppcheck"
endef
clean:
@echo [clean]
@rm -rf resources/ src/ test/ project.clj bin/ docs/ release/ core*
# tangle compiler
project.clj: ferret.org
@echo [tangle] ferret.org
@emacs --batch -nw -Q --eval \
"(progn \
(require 'org) \
(require 'ob) \
(setq org-babel-use-quick-and-dirty-noweb-expansion t) \
(setq org-confirm-babel-evaluate nil) \
(when (locate-library \"ob-sh\") \
(org-babel-do-load-languages \
'org-babel-load-languages '((sh . t)))) \
(when (locate-library \"ob-shell\") \
(org-babel-do-load-languages \
'org-babel-load-languages '((shell . t)))) \
(find-file \"ferret.org\") \
(org-babel-tangle))" 2>&1 >/dev/null | grep 'Tangle'
# run low level unit tests and generate bin/ferret
bin/ferret: export LEIN_SILENT = true
bin/ferret: project.clj
@echo [build] bin/ferret
@mkdir -p bin/
@lein uberjar
@cat resources/jar-sh-header bin/target/ferret.jar > bin/ferret
@chmod +x bin/ferret
@mv bin/target/ferret.jar bin/ferret.jar
# tell make how to compile Ferret lisp to C++
%.cpp: %.clj
@echo [compile] $<
@bin/ferret --silent -i $<
%.cppcheck: %.cpp
@echo [static-check] $<
@$(call static_check,$<)
# each compiler/framework to be tested get an extensiton.
# i.e all cpp files compiled with g++ will have .gcc extension
%.gcc: %.cpp %.cppcheck
@echo [gcc] $<
@g++ $(CPPFLAGS) $(CPP_SANITIZE_FLAGS) -x c++ $< -o $@
@echo [run] $@
@$@ 1 2
%.clang: %.cpp %.cppcheck
@echo [clang] $<
@clang++ $(CPPFLAGS) -x c++ $< -o $@
@echo [run] $@
@valgrind --quiet --leak-check=full --error-exitcode=1 --track-origins=yes $@ 1 2
%.cxx: %.cpp %.cppcheck
@echo [compile] $<
@$(CXX) $(CPPFLAGS) -x c++ $< -o $@
@echo [run] $@
@valgrind --quiet --leak-check=full --error-exitcode=1 --track-origins=yes ./$@ 1 2
%.ino: CPPCHECK_CONF=-DFERRET_HARDWARE_ARDUINO
%.ino: %.cpp %.cppcheck
@mv $< $@
arduino --verify --board arduino:avr:uno $@
# list of unit tests to run againts the current build
NATIVE_TESTS = test/runtime/fixed_real.cpp \
test/runtime/matrix.cpp \
test/runtime/bitset.cpp \
test/runtime/memory_pool.cpp \
test/runtime/array.cpp
CORE_TESTS = test/core/allocator_api.clj \
test/core/seqable.clj \
test/core/seqable_lazy.clj \
test/core/objects.clj \
test/core/core.clj \
test/core/fixed_num.clj \
test/core/math.clj \
test/core/concurrency.clj \
test/core/timing.clj \
test/core/control.clj \
test/core/module.clj \
test/core/module_unit_test.clj \
test/core/module_import_empty_aux_a.clj \
test/core/module_import_empty_aux_b.clj \
test/core/io/file.clj \
test/core/io/serial.clj \
test/core/net/multicast.clj
ARDUINO_TESTS = test/arduino/blink/blink.clj \
test/arduino/blink-multi/blink-multi.clj \
test/arduino/bounce_pin/bounce_pin.clj \
test/arduino/interrupt/interrupt.clj
# assign tests to compilers
CLANG_OBJS = $(NATIVE_TESTS:.cpp=.clang) $(CORE_TESTS:.clj=.clang)
GCC_OBJS = $(NATIVE_TESTS:.cpp=.gcc) $(CORE_TESTS:.clj=.gcc)
INO_OBJS = $(ARDUINO_TESTS:.clj=.ino)
test-compiler: project.clj
lein test
test: bin/ferret test-compiler $(GCC_OBJS) $(CLANG_OBJS) $(INO_OBJS)
# rules for preparing a release
deb: bin/ferret
mkdir -p deb/usr/bin
cp bin/ferret deb/usr/bin/
mkdir -p deb/DEBIAN
cp resources/deb-package-conf deb/DEBIAN/control
echo "Version: ${VERSION}" >> deb/DEBIAN/control
dpkg -b deb ferret-lisp.deb
rm -rf deb
mv ferret-lisp.deb bin/
deb-repo: deb
mkdir -p bin/debian-repo/conf/
cp resources/deb-repo-conf bin/debian-repo/conf/distributions
reprepro -b bin/debian-repo/ includedeb ferret-lisp bin/ferret-lisp.deb
clojars:
lein deploy
docs: project.clj
wget https://s3.amazonaws.com/ferret-lang.org/build-artifacts/clojure-mode-extra-font-locking.el
emacs -nw -Q --batch -l resources/tangle-docs
mkdir -p docs/
mv ferret-manual.html docs/
rm clojure-mode-extra-font-locking.el
release: clean test deb-repo docs clojars
mkdir -p release/builds/
mv bin/ferret* release/builds/
cp release/builds/ferret.jar release/builds/ferret-`git rev-parse --short HEAD`.jar
mv bin/debian-repo release/
mv docs/ferret-manual.html release/index.html
rm -rf bin/ docs/
# rules for managing the docker files used by the CI
DOCKER_RUN = docker run --rm -i \
-e LEIN_JVM_OPTS='-Dhttps.protocols=TLSv1.2' \
-e LEIN_USERNAME='${LEIN_USERNAME}' \
-e LEIN_PASSWORD='${LEIN_PASSWORD}' \
-t -v "${DIR}":/ferret/ -w /ferret/ nakkaya/ferret-build
docker-build: project.clj
cd resources/ferret-build/ && \
docker build -t nakkaya/ferret-build:latest -t nakkaya/ferret-build:${VERSION} .
docker push nakkaya/ferret-build:${VERSION}
docker push nakkaya/ferret-build:latest
env:
${DOCKER_RUN} /bin/bash
docker-release:
${DOCKER_RUN} /bin/bash -c 'make release'
docker-test:
${DOCKER_RUN} /bin/bash -c 'make test'