-
Notifications
You must be signed in to change notification settings - Fork 197
Expand file tree
/
Copy pathMakefile
More file actions
140 lines (114 loc) · 4.78 KB
/
Copy pathMakefile
File metadata and controls
140 lines (114 loc) · 4.78 KB
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
LUA ?= lua5.1
LUA_VERSION = $(shell $(LUA) -e 'print(_VERSION:match("%d%.%d"))')
LUAROCKS = luarocks --lua-version=$(LUA_VERSION)
LUA_PATH_MAKE = $(shell $(LUAROCKS) path --lr-path);./?.lua;./?/init.lua
LUA_CPATH_MAKE = $(shell $(LUAROCKS) path --lr-cpath);./?.so
LUA_SRC_VERSION ?= 5.1.5
LPEG_VERSION ?= 1.0.2
LFS_VERSION ?= 1_8_0
.PHONY: test local build watch lint count show test_binary generate clean
clean:
rm -f moonscript/parse/native.so moonscript/parse/native.o
rm -rf dist
# regenerate the parser from the pgen grammar (requires the pgen to be installed)
generate: build
pgen moonscript/parse/grammar.lua -n moonscript_parse_native \
-o moonscript/parse/native.c --vendor-errors moonscript/parse/errors.lua
clang-format -style="{ColumnLimit: 0}" -i moonscript/parse/native.c
pgen moonscript/parse/grammar.lua -n moonscript_parse_slow \
-o moonscript/parse/slow.lua
moonscript/parse/native.so: moonscript/parse/native.c
gcc -shared -o $@ -O3 -fPIC $< `pkg-config --cflags --libs lua5.1`
build:
LUA_PATH='$(LUA_PATH_MAKE)' LUA_CPATH='$(LUA_CPATH_MAKE)' $(LUA) bin/moonc moon/ moonscript/
echo "#!/usr/bin/env lua" > bin/moon
$(LUA) bin/moonc -p bin/moon.moon >> bin/moon
echo "-- vim: set filetype=lua:" >> bin/moon
# This will rebuild MoonScript from the (hopefully working) system installation of moonc
build_from_system:
moonc moon/ moonscript/
echo "#!/usr/bin/env lua" > bin/moon
moonc -p bin/moon.moon >> bin/moon
echo "-- vim: set filetype=lua:" >> bin/moon
show:
# LUA $(LUA)
# LUA_VERSION $(LUA_VERSION)
# LUAROCKS $(LUAROCKS)
# LUA_PATH_MAKE $(LUA_PATH_MAKE)
# LUA_CPATH_MAKE $(LUA_CPATH_MAKE)
test: build moonscript/parse/native.so
LUA_PATH='$(LUA_PATH_MAKE)' LUA_CPATH='./?.so;$(LUA_CPATH_MAKE)' busted
LUA_PATH='$(LUA_PATH_MAKE)' LUA_CPATH='$(LUA_CPATH_MAKE)' busted --helper=spec/use_slow_parser.moon
build_test_outputs: build
BUILD=1 busted spec/lang_spec.moon
local: build
LUA_PATH='$(LUA_PATH_MAKE)' LUA_CPATH='$(LUA_CPATH_MAKE)' $(LUAROCKS) make --local moonscript-dev-1.rockspec
watch:
moonc moon/ moonscript/ && moonc -w moon/ moonscript/
lint:
moonc -l moonscript moon bin
count:
wc -l $$(git ls-files | grep 'moon$$') | sort -n | tail
# Binary build targets for local verification (Linux only)
lua_modules:
luarocks install argparse --tree=lua_modules
lua-$(LUA_SRC_VERSION)/src/liblua.a:
curl -L -O https://www.lua.org/ftp/lua-$(LUA_SRC_VERSION).tar.gz
tar -xzf lua-$(LUA_SRC_VERSION).tar.gz
cd lua-$(LUA_SRC_VERSION)/src && make liblua.a MYCFLAGS=-DLUA_USE_POSIX
lpeg-$(LPEG_VERSION)/lptree.c:
curl -L -o lpeg.tar.gz https://www.inf.puc-rio.br/~roberto/lpeg/lpeg-$(LPEG_VERSION).tar.gz
tar -xzf lpeg.tar.gz
luafilesystem-$(LFS_VERSION)/src/lfs.c:
curl -L -o luafilesystem.tar.gz https://github.com/keplerproject/luafilesystem/archive/v$(LFS_VERSION).tar.gz
tar -xzf luafilesystem.tar.gz
bin/binaries/moonscript.h: moonscript/*.lua moon/*.lua
bin/splat.moon -x moonscript.parse.slow -x moonscript.parse.grammar moonscript moon > moonscript.lua
xxd -i moonscript.lua > $@
rm moonscript.lua
bin/binaries/moon.h: bin/moon
awk 'FNR>1' bin/moon > moon.lua
xxd -i moon.lua > $@
rm moon.lua
bin/binaries/argparse.h: lua_modules
bin/splat.moon --strip-prefix -l argparse $$(find lua_modules/share/lua -name "argparse.lua" -exec dirname {} \; | head -1) > bin/binaries/argparse.lua
xxd -i -n argparse_lua bin/binaries/argparse.lua > $@
bin/binaries/moonc.h: bin/moonc
awk 'FNR>1' bin/moonc > moonc.lua
xxd -i moonc.lua > $@
rm moonc.lua
dist/moon: lua-$(LUA_SRC_VERSION)/src/liblua.a lpeg-$(LPEG_VERSION)/lptree.c bin/binaries/moonscript.h bin/binaries/moon.h bin/binaries/argparse.h bin/binaries/moon.c bin/binaries/moonscript.c
mkdir -p dist
gcc -static -o dist/moon \
-Ilua-$(LUA_SRC_VERSION)/src/ \
-Ilpeg-$(LPEG_VERSION)/ \
-Ibin/binaries/ \
bin/binaries/moon.c \
bin/binaries/moonscript.c \
moonscript/parse/native.c \
lpeg-$(LPEG_VERSION)/lpvm.c \
lpeg-$(LPEG_VERSION)/lpcap.c \
lpeg-$(LPEG_VERSION)/lptree.c \
lpeg-$(LPEG_VERSION)/lpcode.c \
lpeg-$(LPEG_VERSION)/lpprint.c \
lua-$(LUA_SRC_VERSION)/src/liblua.a \
-lm -ldl
dist/moonc: lua-$(LUA_SRC_VERSION)/src/liblua.a lpeg-$(LPEG_VERSION)/lptree.c luafilesystem-$(LFS_VERSION)/src/lfs.c bin/binaries/moonscript.h bin/binaries/moonc.h bin/binaries/argparse.h bin/binaries/moonc.c bin/binaries/moonscript.c
mkdir -p dist
gcc -static -o dist/moonc \
-Ilua-$(LUA_SRC_VERSION)/src/ \
-Ilpeg-$(LPEG_VERSION)/ \
-Ibin/binaries/ \
bin/binaries/moonc.c \
bin/binaries/moonscript.c \
moonscript/parse/native.c \
lpeg-$(LPEG_VERSION)/lpvm.c \
lpeg-$(LPEG_VERSION)/lpcap.c \
lpeg-$(LPEG_VERSION)/lptree.c \
lpeg-$(LPEG_VERSION)/lpcode.c \
lpeg-$(LPEG_VERSION)/lpprint.c \
luafilesystem-$(LFS_VERSION)/src/lfs.c \
lua-$(LUA_SRC_VERSION)/src/liblua.a \
-lm -ldl
test_binary: dist/moon
dist/moon