-
Notifications
You must be signed in to change notification settings - Fork 126
/
Makefile
228 lines (180 loc) · 7.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
LUA ?= lua
LUA_VERSION ?= $(shell $(LUA) -e 'v=_VERSION:gsub("^Lua *","");print(v)')
DESTDIR ?=
PREFIX ?= /usr/local
BIN_DIR ?= $(PREFIX)/bin
LUA_LIB_DIR ?= $(PREFIX)/share/lua/$(LUA_VERSION)
MAN_DIR ?= $(PREFIX)/share
MAKEFLAGS += --no-print-directory
CORE_SRC=src/fennel.fnl src/fennel/parser.fnl src/fennel/specials.fnl \
src/fennel/utils.fnl src/fennel/compiler.fnl src/fennel/macros.fnl \
src/fennel/match.fnl
LIB_SRC=$(CORE_SRC) src/fennel/friend.fnl src/fennel/view.fnl src/fennel/repl.fnl
SRC=$(LIB_SRC) src/launcher.fnl src/fennel/binary.fnl
MAN_PANDOC = pandoc -f gfm -t man -s --lua-filter=build/manfilter.lua \
--metadata author="Fennel Maintainers" \
--variable footer="fennel $(shell ./fennel -e '(. (require :fennel) :version)')"
unexport NO_COLOR # this causes test failures
unexport FENNEL_PATH FENNEL_MACRO_PATH # ensure isolation
build: fennel fennel.lua
test: fennel.lua fennel test/faith.lua
@LUA_PATH=?.lua $(LUA) test/init.lua $(TESTS)
@echo
testall: export FNL_TESTALL=yes
testall: fennel test/faith.lua # recursive make considered not really a big deal
$(MAKE) test LUA=lua5.1
$(MAKE) test LUA=lua5.2
$(MAKE) test LUA=lua5.3
$(MAKE) test LUA=lua5.4
$(MAKE) test LUA=luajit
fuzz: fennel ; $(MAKE) test TESTS=test.fuzz
count: ; cloc $(CORE_SRC); cloc $(LIB_SRC) ; cloc $(SRC)
# install https://git.sr.ht/~technomancy/fnlfmt manually for this:
format: ; for f in $(SRC); do fnlfmt --fix $$f ; done
# All-in-one pure-lua script:
fennel: src/launcher.fnl $(SRC) bootstrap/view.lua
@echo "#!/usr/bin/env $(LUA)" > $@
@echo "-- SPDX-License-Identifier: MIT" >> $@
@echo "-- SPDX-FileCopyrightText: Calvin Rose and contributors" >> $@
FENNEL_PATH=src/?.fnl $(LUA) bootstrap/aot.lua $< --require-as-include >> $@
@chmod 755 $@
# Library file
fennel.lua: $(SRC) bootstrap/aot.lua bootstrap/view.lua
@echo "-- SPDX-License-Identifier: MIT" > $@
@echo "-- SPDX-FileCopyrightText: Calvin Rose and contributors" >> $@
FENNEL_PATH=src/?.fnl $(LUA) bootstrap/aot.lua $< --require-as-include >> $@
bootstrap/view.lua: src/fennel/view.fnl
FENNEL_PATH=src/?.fnl $(LUA) bootstrap/aot.lua $< > $@
test/faith.lua: test/faith.fnl
$(LUA) bootstrap/aot.lua $< > $@
check:
fennel-ls --check $(SRC)
ci: testall fuzz fennel
clean:
rm -f fennel.lua fennel fennel-bin fennel.exe \
*_binary.c luacov.* bootstrap/view.lua \
test/faith.lua build/manfilter.lua fennel-bin-luajit
$(MAKE) -C $(BIN_LUA_DIR) clean || true # this dir might not exist
$(MAKE) -C $(BIN_LUAJIT_DIR) clean || true # this dir might not exist
rm -f $(NATIVE_LUA_LIB) $(NATIVE_LUAJIT_LIB)
coverage: fennel
$(LUA) -lluacov test/init.lua
@echo "generated luacov.report.out"
## Binaries
BIN_LUA_DIR ?= lua
BIN_LUAJIT_DIR ?= luajit
NATIVE_LUA_LIB ?= $(BIN_LUA_DIR)/src/liblua.a
NATIVE_LUAJIT_LIB ?= $(BIN_LUAJIT_DIR)/src/libluajit.a
LUA_INCLUDE_DIR ?= $(BIN_LUA_DIR)/src
LUAJIT_INCLUDE_DIR ?= $(BIN_LUAJIT_DIR)/src
COMPILE_ARGS=FENNEL_PATH=src/?.fnl FENNEL_MACRO_PATH=src/?.fnl CC_OPTS=-static
LUAJIT_COMPILE_ARGS=FENNEL_PATH=src/?.fnl FENNEL_MACRO_PATH=src/?.fnl
$(LUA_INCLUDE_DIR): ; git submodule update --init
$(LUAJIT_INCLUDE_DIR): ; git submodule update --init
# Native binary for whatever platform you're currently on
fennel-bin: src/launcher.fnl $(BIN_LUA_DIR)/src/lua $(NATIVE_LUA_LIB) fennel
$(COMPILE_ARGS) $(BIN_LUA_DIR)/src/lua fennel \
--no-compiler-sandbox --compile-binary \
$< $@ $(NATIVE_LUA_LIB) $(LUA_INCLUDE_DIR)
fennel-bin-luajit: src/launcher.fnl $(NATIVE_LUAJIT_LIB) fennel
$(LUAJIT_COMPILE_ARGS) $(BIN_LUAJIT_DIR)/src/luajit fennel \
--no-compiler-sandbox --compile-binary \
$< $@ $(NATIVE_LUAJIT_LIB) $(LUAJIT_INCLUDE_DIR)
$(BIN_LUA_DIR)/src/lua: $(LUA_INCLUDE_DIR) ; make -C $(BIN_LUA_DIR)
$(NATIVE_LUA_LIB): $(LUA_INCLUDE_DIR) ; $(MAKE) -C $(BIN_LUA_DIR)/src liblua.a
$(NATIVE_LUAJIT_LIB): $(LUAJIT_INCLUDE_DIR)
$(MAKE) -C $(BIN_LUAJIT_DIR) BUILDMODE=static
# TODO: update setup.md to point to new filenames on next release
# to cross-compile, run: make fennel.exe CC=x86_64-w64-mingw32-gcc
fennel.exe: src/launcher.fnl fennel $(LUA_INCLUDE_DIR)/liblua-mingw.a
$(COMPILE_ARGS) ./fennel --no-compiler-sandbox \
--compile-binary $< fennel-bin \
$(LUA_INCLUDE_DIR)/liblua-mingw.a $(LUA_INCLUDE_DIR)
mv fennel-bin.exe $@
$(BIN_LUA_DIR)/src/liblua-mingw.a: $(LUA_INCLUDE_DIR)
$(MAKE) -C $(BIN_LUA_DIR)/src clean mingw CC=x86_64-w64-mingw32-gcc
mv $(BIN_LUA_DIR)/src/liblua.a $@
$(MAKE) -C $(BIN_LUA_DIR)/src clean
## Install-related tasks:
MAN_DOCS := man/man1/fennel.1 man/man3/fennel-api.3 man/man5/fennel-reference.5\
man/man7/fennel-tutorial.7
# The empty line in maninst is necessary for it to emit distinct commands
define maninst =
mkdir -p $(dir $(2)) && cp $(1) $(2)
endef
install: fennel fennel.lua
mkdir -p $(DESTDIR)$(BIN_DIR) && cp fennel $(DESTDIR)$(BIN_DIR)/
mkdir -p $(DESTDIR)$(LUA_LIB_DIR) && cp fennel.lua $(DESTDIR)$(LUA_LIB_DIR)/
$(foreach doc,$(MAN_DOCS),\
$(call maninst,$(doc),$(DESTDIR)$(MAN_DIR)/$(doc)))
uninstall:
rm $(DESTDIR)$(BIN_DIR)/fennel
rm $(DESTDIR)$(LUA_LIB_DIR)/fennel.lua
rm $(addprefix $(DESTDIR)$(MAN_DIR)/,$(MAN_DOCS))
build/manfilter.lua: build/manfilter.fnl fennel.lua fennel
./fennel --correlate --compile $< > $@
man: $(dir $(MAN_DOCS)) $(MAN_DOCS)
man/man%/: ; mkdir -p $@
man/man3/fennel-%.3: %.md build/manfilter.lua
$(MAN_PANDOC) $< -o $@
sed -i 's/\\f\[C\]/\\f[CR]/g' $@ # work around pandoc 2.x bug
man/man5/fennel-%.5: %.md build/manfilter.lua
$(MAN_PANDOC) $< -o $@
sed -i 's/\\f\[C\]/\\f[CR]/g' $@
man/man7/fennel-%.7: %.md build/manfilter.lua
$(MAN_PANDOC) $< -o $@
sed -i 's/\\f\[C\]/\\f[CR]/g' $@
## Release-related tasks:
SSH_KEY ?= ~/.ssh/id_ed25519.pub
test-builds: fennel test/faith.lua
./fennel --metadata --eval "(require :test.init)"
$(MAKE) install PREFIX=/tmp/opt
upload: fennel fennel.lua fennel-bin
$(MAKE) fennel.exe CC=x86_64-w64-mingw32-gcc
mkdir -p downloads/
mv fennel downloads/fennel-$(VERSION)
mv fennel.lua downloads/fennel-$(VERSION).lua
mv fennel-bin downloads/fennel-$(VERSION)-x86_64
mv fennel.exe downloads/fennel-$(VERSION)-windows.exe
gpg -ab downloads/fennel-$(VERSION)
gpg -ab downloads/fennel-$(VERSION).lua
gpg -ab downloads/fennel-$(VERSION)-x86_64
gpg -ab downloads/fennel-$(VERSION)-windows.exe
ssh-keygen -Y sign -f $(SSH_KEY) -n file downloads/fennel-$(VERSION)
ssh-keygen -Y sign -f $(SSH_KEY) -n file downloads/fennel-$(VERSION).lua
ssh-keygen -Y sign -f $(SSH_KEY) -n file downloads/fennel-$(VERSION)-x86_64
ssh-keygen -Y sign -f $(SSH_KEY) -n file downloads/fennel-$(VERSION)-windows.exe
rsync -rtAv downloads/fennel-$(VERSION)* \
[email protected]:fennel-lang.org/downloads/
release: guard-VERSION upload
git tag -v $(VERSION) # created by prerelease target
git push
git push --tags
@echo "* Update the submodule in the fennel-lang.org repository."
@echo "* Announce the release on the mailing list."
@echo "* Bump the version in src/fennel/utils.fnl to the next dev version."
@echo "* Add a stub for the next version in changelog.md"
prerelease: guard-VERSION ci test-builds
@echo "Did you look for changes that need to be mentioned in help/man text?"
sed -i s/$(VERSION)-dev/$(VERSION)/ src/fennel/utils.fnl
$(MAKE) man
grep "$(VERSION)" setup.md > /dev/null
! grep "???" changelog.md
git commit -a -m "Release $(VERSION)"
git tag -s $(VERSION) -m $(VERSION)
guard-%:
@ if [ "${${*}}" = "" ]; then \
echo "Environment variable $* not set"; \
exit 1; \
fi
.PHONY: build test testall fuzz count format ci clean coverage install \
man upload prerelease release guard-VERSION test-builds
# Steps to release a new Fennel version
# The `make release` command should be run on a system with the lowest
# available glibc for maximum compatibility.
# 1. Check for changes which need to be mentioned in help text or man page
# 2. Date `changelog.md` and update download links in `setup.md`
# 3. Run `make prerelease VERSION=$VERSION`
# 4. Run `make release VERSION=$VERSION`
# 5. Update fennel submodule in fennel-lang.org and make upload there
# 6. Announce on the mailing list