-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.lsp
104 lines (92 loc) · 3.19 KB
/
Makefile.lsp
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
(defglobal EXE (shell "go env GOEXE"))
(defglobal CURDIR (getwd))
(defglobal NAME (notdir CURDIR))
(defglobal TARGET (string-append NAME EXE))
(defglobal SOURCE (wildcard "*.go"))
(defglobal NUL (if windows "NUL" "/dev/null"))
(defglobal VERSION
(catch
'notag
(with-handler
(lambda (c) (throw 'notag "v0.0.0"))
(shell (string-append "git describe --tags 2>" NUL)))))
(case $1
(("get")
(sh "go get -u"
"go get -u github.com/hymkor/gmnlisp@master"
"go mod tidy"))
(("touch")
(dolist (fname SOURCE)
(touch fname)))
(("clean")
(pushd "examples/cc"
(spawnlp $0 "clean"))
(dolist (fname (wildcard "*~"))
(rm fname))
(if (-e TARGET)
(mv TARGET (string-append "." TARGET "~"))))
(("upgrade") ; upgrade the installed program with the newly built version
(if (probe-file TARGET)
(let ((delimiter (elt (if windows ";" ":") 0)))
(dolist (dir (string-split delimiter (getenv "PATH")))
(if (and (not (equalp CURDIR dir))
(probe-file (joinpath dir TARGET)))
(progn
(format (standard-output) "copy \"~A\" to \"~A\" ? [Y or N] " TARGET dir)
(if (equalp (read-line (standard-input) nil nil) "y")
(cp TARGET dir))))))))
(("test")
(assert-eq (match "^a*$" "aaaa") '("aaaa"))
(assert-eq (match "^v([0-9]+)\.([0-9]+)\.([0-9]+)$" "v10.20.30")
'("v10.20.30" "10" "20" "30"))
(assert-eq (match "^a*$" "hogehoge") nil)
(assert-eq (catch
'fail
(with-handler
(lambda (c) (throw 'fail 'NG))
(match "(" "hogehoge")))
'NG)
(sh "go test"))
(("dist")
(dolist (goos '("linux" "windows"))
(dolist (goarch '("386" "amd64"))
(env (("GOOS" goos) ("GOARCH" goarch))
(let* ((exe (shell "go env GOEXE"))
(target (string-append NAME exe)))
(rm target)
(sh "go build")
(spawnlp
"zip"
(string-append NAME "-" VERSION "-" goos "-" goarch ".zip")
target))))))
(("release")
(let ((b (create-string-output-stream)))
(format b "gh release create -d --notes \"\" -t")
(format b " \"~A\"" VERSION)
(format b " \"~A\"" VERSION)
(dolist (zip (wildcard (string-append NAME "-" VERSION "-*.zip")))
(format b " \"~A\"" zip))
(sh (get-output-stream-string b))))
(("clean-zip")
(dolist (fname (wildcard "*.zip"))
(rm fname)))
(("manifest")
(sh "make-scoop-manifest *.zip > smake.json"))
(("readme")
(sh "example-into-readme"))
(t
(let ((ufiles (updatep TARGET "Makefile.lsp" "embed.lsp" "go.mod" "go.sum" SOURCE)))
(if ufiles
(progn
(format (error-output) "Found update files: ~S~%" ufiles)
(sh "go fmt")
(spawnlp "go" "build" "-ldflags"
(string-append "-s -w -X main.version=" VERSION)))
(progn
(format (error-output) "No files updated~%")
)
); if
); let
); t
); case
; vim:set lispwords+=env,mapc,pushd,while,doenv: