SMake is the build tool like MAKE(UNIX) whose Makefile is written with S-expression.
(defglobal EXE (shell "go env GOEXE"))
(defglobal NAME (notdir (getwd)))
(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")
(foreach (fname SOURCE)
(touch fname)))
(("clean")
(pushd "examples/cc"
(spawnlp $0 "clean"))
(foreach (fname (wildcard "*~"))
(rm fname))
(if (-e TARGET)
(mv TARGET (string-append "." TARGET "~"))))
(("install")
(foreach (path (string-split #\newline (q "where" (notdir $0))))
(if (not (equal path $0))
(cp $0 path))))
(("test")
(sh "go test"))
(("dist")
(foreach (goos '("linux" "windows"))
(foreach (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)
(foreach (zip (wildcard (string-append NAME "-" VERSION "-*.zip")))
(format b " \"~A\"" zip))
(sh (get-output-stream-string b))))
(("clean-zip")
(foreach (fname (wildcard "*.zip"))
(rm fname)))
(("manifest")
(sh "make-scoop-manifest *.zip > smake.json"))
(("readme")
(sh "example-into-readme"))
(t
(if (updatep TARGET "Makefile.lsp" "embed.lsp" "go.mod" "go.sum" SOURCE)
(progn
(sh "go fmt")
(spawnlp "go" "build" "-ldflags"
(string-append "-s -w -X main.version=" VERSION)))
)
) ; end-t
) ; end-case
; vim:set lispwords+=foreach,env,mapc,make,pushd,while,doenv:
Other examples:
- examples/cc/Makefile.lsp for C Project
Download the zipfile for your environment from Releases and unzip.
go install github.com/hymkor/smake@latest
scoop install https://raw.githubusercontent.com/hymkor/smake/master/smake.json
or
scoop bucket add hymkor https://github.com/hymkor/scoop-bucket
scoop install smake
go build
It returns the list of newer files in SOURCES than TARGET
If the file TARGET is newer than SOURCE or TARGET does not exist, execute COMMANDS.
The entry after MAINTARGET is evaluated when the TARGET equals the MAINTARGET or the TARGET is written on other evaluated SOURCES.
Expand the value of the variable written in the string-literal.
- "$(x)" to the value of the symbol x or the environment variable.
- "$/" is same as "$($/)"
These are available in (make)
block
- "$<" is same as "$($<)"
- "$?" is same as "$($?)"
- "$@" is same as "$($@)"
Execute the external executable directly. If it failes, top.
Execute the external executable directly and return its standard-output as string.
Execute the shell command by CMD.exe or /bin/sh. If it fails, stop.
Same as (sh) but ignores errors.
Execute the shell command and return its standard-output as string. Same as $(shell "..") of GNU Make.
Same as the UNIX command echo.
Same as the UNIX command rm.
Same as the UNIX command touch.
Return the value of the environment variable NAME. If it does not exist, return nil.
Set the environment variable "NAME" to "VALUE".
Set the environment variables and execute COMMANDS. Then, restores them to thier original values.
Expand PATTERNs as a wildcard and return them as a list.
Same as $(abspath FILEPATH) of GNU Make
Same as $(dir FILEPATH) of GNU Make
Same as $(notdir FILEPATH) of GNU Make
Same as $(basename FILEPATH) of GNU Make
Make path with "DIR"... "FNAME". (joinpath) is an alias of (pathjoin). Same as filepath.Join of golang.
If FILENAME exists, it returns t. Otherwise nil. Same as -e of Perl.
If DIRNAME exists and it is a directory, it returns t. Otherwise nil. Same as -d of Perl.
Change the current working directory to "DIRNAME"
Returns the current working directory.
Change the current directory to "DIRNAME" and execute COMMANDS like (progn). After COMMANDS, return to the original current directory.
Copy file SRC... to DST (directory or new filename)
Move file SRC... to DST (directory or new filename)
(string-split #\: "a:b:c")
=> ("a" "b" "c")
Call Windows-API: shellexecute
Split "STRING" with whilte-spaces. This function is similar with strings.Fields in golang
They are compatible functions with ISLisp. See also hymkor/gmnlisp
It is t
(true) when %OS% is Windows_NT
- $/ - OS-specific path separator (Windows
\
, UNIX/
) - *args* - the command-line arguments
- $1...$9 - the same as
(elt *args* N)
- $0 ... the current executing smake filename
These are available in (make)
block
- $@ - the target filename
- $< - the first source filename
- $? - the updated source filenames