-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMakefile
183 lines (157 loc) · 6.12 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
ifeq ($(OS), Windows_NT)
os = windows
m ?= ta6nt
else ifeq ($(shell uname -s), Darwin)
os = macOS
m ?= ta6osx
else
os = linux
m ?= ta6le
endif
ifeq ($(os), windows)
S = \\\\
objext = .obj
binext = .exe
archiveext = .zip
cskernelname = mainmd
compress = 7z a -tzip
uncompress = 7z x
uncompressToFlag = -o
else
S = /
objext = .o
binext =
archiveext = .tar.gz
cskernelname = kernel
compress = tar cvzf
uncompress = tar xzf
uncompressToFlag = -C
endif
ifeq ($(os), linux)
linkerflags = -lm -ldl -lpthread -luuid
endif
shenversion ?= 34.5
csversion ?= 9.5.8
build_dir ?= _build
chez_build_dir ?= $(build_dir)$(S)chez
csdir ?= $(chez_build_dir)$(S)csv$(csversion)
cslicense = $(csdir)$(S)LICENSE
cscopyright = $(csdir)$(S)NOTICE
csbootpath = $(csdir)$(S)$(m)$(S)boot$(S)$(m)
psboot = .$(S)$(csbootpath)$(S)petite.boot
csboot = .$(S)$(csbootpath)$(S)scheme.boot
cskernelname ?= kernel
cskernel = $(csbootpath)$(S)$(cskernelname)$(objext)
csbinpath = $(csdir)$(S)$(m)$(S)bin$(S)$(m)
scmexe = $(csbinpath)$(S)scheme
klsources_dir ?= kl
compiled_dir ?= compiled
exe ?= $(build_dir)/bin/shen-scheme$(binext)
prefix ?= /usr/local
home_path ?= "$(prefix)/lib/shen-scheme"
bootfile = $(build_dir)/lib/shen-scheme/shen.boot
precompiled_dir = $(build_dir)$(S)shen-scheme-v0.26-src
git_tag ?= $(shell git tag -l --contains HEAD 2> /dev/null)
ifeq ("$(git_tag)","")
git_tag = $(shell git rev-parse --short HEAD 2> /dev/null)
endif
archive_name = shen-scheme-$(git_tag)-src
CFLAGS += -m64
.DEFAULT: all
.PHONY: all
all: $(exe) $(bootfile)
$(csdir):
echo "Downloading and uncompressing Chez..."
mkdir -p $(chez_build_dir)
cd $(chez_build_dir); curl -LO 'https://github.com/cisco/ChezScheme/releases/download/v$(csversion)/csv$(csversion).tar.gz'; tar xzf csv$(csversion).tar.gz; rm csv$(csversion).tar.gz
# Workaround to make the build work with Visual Studio > 2017
curl -L -o "$(csdir)$(S)c$(S)vs.bat" 'https://raw.githubusercontent.com/cisco/ChezScheme/bf4f42105325f03778c07139f502294ebf8a0b50/c/vs.bat'
$(cskernel): $(csdir)
echo "Building Chez..."
cd $(csdir) && ./configure --threads && make
$(exe): $(cskernel) main$(objext)
mkdir -p $(build_dir)/bin
ifeq ($(os), windows)
cmd.exe /C '$(csdir)$(S)c$(S)vs.bat amd64 && link.exe /out:$(exe) /machine:X64 /incremental:no /release /nologo main$(objext) $(csbootpath)$(S)csv958mt.lib /DEFAULTLIB:rpcrt4.lib /DEFAULTLIB:User32.lib /DEFAULTLIB:Advapi32.lib /DEFAULTLIB:Ole32.lib'
else
$(CC) -o $@ $^ $(linkerflags)
endif
%$(objext): %.c
ifeq ($(os), windows)
cmd.exe /C '$(csdir)$(S)c$(S)vs.bat amd64 && cl.exe /c /nologo /W3 /D_CRT_SECURE_NO_WARNINGS /I$(csbootpath) /I.$(S)lib /MT /Fo$@ $<'
else
$(CC) -c -o $@ $< -I$(csbootpath) -I./lib -Wall -Wextra -pedantic $(CFLAGS)
endif
$(bootfile): $(psboot) $(csboot) shen-scheme.scm src/* $(compiled_dir)/*.scm
mkdir -p $(build_dir)/lib/shen-scheme
echo '(make-boot-file "$(bootfile)" (list) "$(psboot)" "$(csboot)" "shen-scheme.scm")' | "$(scmexe)" -q -b "$(psboot)" -b "$(csboot)"
.PHONY: fetch-kernel
fetch-kernel:
curl -LO 'https://github.com/Shen-Language/shen-sources/releases/download/shen-$(shenversion)/ShenOSKernel-$(shenversion).tar.gz'
tar xzf ShenOSKernel-$(shenversion).tar.gz
cp ShenOSKernel-$(shenversion)/klambda/*.kl $(klsources_dir)/
.PHONY: fetch-prebuilt
fetch-prebuilt:
mkdir -p $(build_dir)
curl -LO 'https://github.com/tizoc/shen-scheme/releases/download/v0.26/shen-scheme-v0.26-$(os)-bin$(archiveext)'
$(uncompress) shen-scheme-v0.26-$(os)-bin$(archiveext) $(uncompressToFlag)$(build_dir)
.PHONY: precompile-with-prebuilt
precompile-with-prebuilt:
$(build_dir)$(S)shen-scheme-v0.26-$(os)-bin$(S)bin$(S)shen-scheme$(binext) script scripts/do-build.shen > /dev/null
$(precompiled_dir):
mkdir -p $(build_dir)
curl -LO 'https://github.com/tizoc/shen-scheme/releases/download/v0.26/shen-scheme-v0.26-src.tar.gz'
tar xzf shen-scheme-v0.26-src.tar.gz -C $(build_dir)
rm -f $(precompiled_dir)$(S)Makefile
cp Makefile $(precompiled_dir)$(S)Makefile
.PHONY: precompile
precompile:
$(SHEN) script scripts/do-build.shen > /dev/null
.PHONY: build-precompiled
build-precompiled: $(precompiled_dir) $(cskernel)
mkdir -p $(precompiled_dir)$(S)_build
cp -a $(chez_build_dir) $(precompiled_dir)$(S)$(chez_build_dir)
cd $(precompiled_dir); make csversion=$(csversion)
.PHONY: test-shen
test-shen: $(exe) $(bootfile)
./$(exe) script scripts/run-shen-tests.shen
.PHONY: test-compiler
test-compiler: $(exe) $(bootfile)
./$(exe) script scripts/run-compiler-tests.shen
.PHONY: test
test: test-shen test-compiler
.PHONY: run
run: $(exe) $(bootfile)
./$(exe)
.PHONY: install
install: $(exe) $(bootfile)
mkdir -p $(DESTDIR)$(prefix)/bin
mkdir -p $(DESTDIR)$(home_path)
install -m 0755 $(exe) $(DESTDIR)$(prefix)/bin
install -m 0644 $(bootfile) $(DESTDIR)$(home_path)/
.PHONY: source-release
source-release:
mkdir -p _dist
git archive --format=tar --prefix="$(archive_name)/" $(git_tag) | (cd _dist && tar xf -)
cp $(compiled_dir)/*.scm "_dist/$(archive_name)/compiled/"
cp shen-scheme.scm "_dist/$(archive_name)/shen-scheme.scm"
rm -rf "_dist/$(archive_name)/".git*
rm "_dist/$(archive_name)/"*/.gitignore
cd _dist; tar cvzf "$(archive_name).tar.gz" "$(archive_name)/"; rm -rf "$(archive_name)/"
echo "Generated tarball for tag $(git_tag) as _dist/$(archive_name).tar.gz"
.PHONY: binary-release
binary-release: $(exe) $(bootfile)
mkdir -p "_dist/shen-scheme-$(git_tag)-$(os)-bin"
mkdir -p "_dist/shen-scheme-$(git_tag)-$(os)-bin/bin"
mkdir -p "_dist/shen-scheme-$(git_tag)-$(os)-bin/lib/shen-scheme"
mkdir -p "_dist/shen-scheme-$(git_tag)-$(os)-bin/chez-legal"
cp $(exe) "_dist/shen-scheme-$(git_tag)-$(os)-bin/bin"
cp $(bootfile) "_dist/shen-scheme-$(git_tag)-$(os)-bin/lib/shen-scheme"
cp README.md "_dist/shen-scheme-$(git_tag)-$(os)-bin/README.txt"
cp LICENSE "_dist/shen-scheme-$(git_tag)-$(os)-bin/LICENSE.txt"
cp $(cslicense) "_dist/shen-scheme-$(git_tag)-$(os)-bin/chez-legal/LICENSE.txt"
cp $(cscopyright) "_dist/shen-scheme-$(git_tag)-$(os)-bin/chez-legal/NOTICE.txt"
cd _dist; $(compress) "shen-scheme-$(git_tag)-$(os)-bin$(archiveext)" "shen-scheme-$(git_tag)-$(os)-bin"; rm -rf "shen-scheme-$(git_tag)-$(os)-bin"
.PHONY: clean
clean:
rm -f $(exe) $(bootfile) *.o *.obj