pman/CHEATSHEET.md

118 lines
3.5 KiB
Markdown
Raw Normal View History

2021-02-10 18:20:14 +01:00
# CHEATSHEET FOR STUDIOUS POTATO MAKE
## Boilerplate
Add this at the top of your build script.
#!/usr/bin/env sh
exec guile -s "$0" "$@"
!#
(use-modules (studious-potato))
(initialize)
Add this at the bottom of your build script
(build)
The rules go in between `initialize` and `build`
## MAKEVARS
2021-02-10 18:25:27 +01:00
A hash table called `%makevars` has string keys. These procedures
are syntax that add quotation marks around `key`, so you call them without the quotes on
2021-02-10 18:57:25 +01:00
`key`. The returned value of `$` is a string, or an empty string on failure.
2021-02-10 18:25:27 +01:00
($ KEY) -> "VAL"
2021-02-10 18:20:14 +01:00
($ key [transformer])
Look up `key` in the `%makevars` hash table and return the result.
2021-02-10 18:28:37 +01:00
If a string-to-string transformer procedure is provided, apply it to each
2021-02-10 18:20:14 +01:00
space-separated token in the result.
(?= key val)
Assign `val` to `key` in the `%makevars` hash table. If `val` is a procedure,
2021-02-10 18:57:25 +01:00
assign its output to `key` the first time that `key` is referenced.
2021-02-10 18:20:14 +01:00
(:= key val)
Assign `val` to `key` in the `%makevars` hash table. If `val` is a procedure,
evaluate it and assign its output to `key` immediately.
## RULES
The target rule is for when the target, and the prerequisites, if any,
have filenames or phony names.
(: target-name '(prereq-name-1 prereq-name-2 ...)
recipe-1
recipe-2
...)
`target-name` is a string which is either a filename to be created
or an phony name like "all" or "clean".
2021-02-10 18:38:59 +01:00
Recipe as a string to be evaluated by the system
2021-02-10 18:20:14 +01:00
(: "foo.o" '("foo.c")
"cc -c foo.o")
2021-02-10 18:38:59 +01:00
Recipe as a procedure
2021-02-10 18:20:14 +01:00
(: "clean-foo" '()
2021-02-10 18:57:25 +01:00
(lambda ()
(delete-file "foo.o")))
2021-02-10 18:20:14 +01:00
2021-02-10 18:38:59 +01:00
Recipe as a procedure that returns #f to indicate failure
2021-02-10 18:20:14 +01:00
(: "recent" '()
2021-02-10 18:57:25 +01:00
(lambda ()
(if condition
#t
#f))))
2021-02-10 18:20:14 +01:00
2021-02-10 18:38:59 +01:00
Recipe as a procedure returning a string to be evaluated by the system
2021-02-10 18:20:14 +01:00
(: "foo.o" '("foo.c")
(lambda ()
(format #f "cc ~A -c foo.c" some-flags))
2021-02-10 18:38:59 +01:00
Recipe using recipe helper procedures, which create a string to be
evaluated by the system
2021-02-10 18:20:14 +01:00
(: "foo.c" '("foo.c")
(~ ($ CC) ($ CFLAGS) "-c" $<))
The suffix rule is a generic rule to convert one file type to another.
Note that the prerequisites is *not* a list.
(-> ".c" ".o"
(~ ($ CC) ($ CFLAGS) ".c" $<))
2021-02-10 18:38:59 +01:00
# RECIPE HELPERS
2021-02-10 18:20:14 +01:00
Concatenate elements with `~`. `~` inserts spaces between the elements.
Elements can be
2021-02-10 18:38:59 +01:00
- strings
2021-02-10 18:20:14 +01:00
- procedures that return strings
2021-02-10 18:38:59 +01:00
- `%makevar` hash-table references
2021-02-10 18:20:14 +01:00
- special variables
2021-02-10 18:38:59 +01:00
- anything whose string representation as created by
(format #f "~A" ...) make sense
2021-02-10 18:20:14 +01:00
2021-02-10 18:38:59 +01:00
(~ "string" (lambda () "string") ($ KEY) $@ 100 )
2021-02-10 18:20:14 +01:00
Three versions of `~` with special effects
(~- ...) ignores any errors
(~@ ...) doesn't print recipe to console
(~+ ...) runs even when `--no-execute` was chosen
Recipes can contain the following special variables
$@ the target
$* the target w/o a filename suffix
$< the first prerequisite
2021-02-10 18:57:25 +01:00
$^ the prerequisites, as a single space-separated string
$$^ the prerequisites, as a scheme list of strings
2021-02-10 18:20:14 +01:00
$? the prerequisites that are files newer than the target file
2021-02-10 18:42:44 +01:00
as a single space-separated string
2021-02-10 18:57:25 +01:00
$$? the prerequisites that are files newer than the target file
as a scheme list of strings