mirror of
https://github.com/janet-lang/janet
synced 2024-12-23 23:10:26 +00:00
9943bdd907
They should throw better error messages when project.janet not found.
44 lines
1.4 KiB
Plaintext
Executable File
44 lines
1.4 KiB
Plaintext
Executable File
#!/usr/bin/env janet
|
|
|
|
# CLI tool for building janet projects. Wraps cook.
|
|
|
|
(import cook)
|
|
|
|
(def- argpeg
|
|
(peg/compile
|
|
'(* "--" '(some (if-not "=" 1)) "=" '(any 1))))
|
|
|
|
(defn- help
|
|
[]
|
|
(print "usage: jpm [targets]... --key=value ...")
|
|
(print "Available targets are:")
|
|
(each k (sort (keys (dyn :rules @{})))
|
|
(print " " k))
|
|
(print `
|
|
|
|
Keys are:
|
|
--modpath : The directory to install modules to. Defaults to $JANET_MODPATH or (dyn :syspath)
|
|
--headerpath : The directory containing janet headers. Defaults to $JANET_HEADERPATH or (dyn :headerpath)
|
|
--binpath : The directory to install binaries and scripts. Defaults to $JANET_BINPATH.
|
|
--optimize : Optimization level for natives. Defaults to $OPTIMIZE or 2.
|
|
--compiler : C compiler to use for natives. Defaults to $COMPILER or cc.
|
|
--linker : C linker to use for linking natives. Defaults to $LINKER or cc.
|
|
--cflags : Extra compiler flags for native modules. Defaults to $CFLAGS if set.
|
|
--lflags : Extra linker flags for native modules. Defaults to $LFLAGS if set.
|
|
`))
|
|
|
|
(def args (tuple/slice process/args 2))
|
|
(def todo @[])
|
|
(each arg args
|
|
(if (string/has-prefix? "--" arg)
|
|
(if-let [m (peg/match argpeg arg)]
|
|
(let [[key value] m]
|
|
(setdyn (keyword key) value))
|
|
(print "invalid argument " arg))
|
|
(array/push todo arg)))
|
|
|
|
(cook/import-rules "./project.janet")
|
|
|
|
(if (empty? todo) (help))
|
|
(each rule todo (cook/do-rule rule))
|