2019-05-27 20:50:57 +00:00
|
|
|
#!/usr/bin/env janet
|
|
|
|
|
2019-05-28 02:14:24 +00:00
|
|
|
# CLI tool for building janet projects. Wraps cook.
|
2019-05-27 20:50:57 +00:00
|
|
|
|
2019-05-29 15:04:38 +00:00
|
|
|
(import cook)
|
2019-05-27 20:50:57 +00:00
|
|
|
|
2019-05-28 02:14:24 +00:00
|
|
|
(def- argpeg
|
|
|
|
(peg/compile
|
|
|
|
'(* "--" '(some (if-not "=" 1)) "=" '(any 1))))
|
|
|
|
|
|
|
|
(defn- help
|
2019-05-27 20:50:57 +00:00
|
|
|
[]
|
2019-05-28 02:14:24 +00:00
|
|
|
(print "usage: jpm [targets]... --key=value ...")
|
|
|
|
(print "Available targets are:")
|
|
|
|
(each k (sort (keys (dyn :rules @{})))
|
|
|
|
(print " " k))
|
|
|
|
(print `
|
|
|
|
|
|
|
|
Keys are:
|
2019-06-19 04:48:57 +00:00
|
|
|
--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)
|
2019-05-29 15:04:38 +00:00
|
|
|
--binpath : The directory to install binaries and scripts. Defaults to $JANET_BINPATH.
|
2019-05-28 02:14:24 +00:00
|
|
|
--optimize : Optimization level for natives. Defaults to $OPTIMIZE or 2.
|
2019-06-01 14:38:28 +00:00
|
|
|
--compiler : C compiler to use for natives. Defaults to $COMPILER or cc.
|
2019-05-28 02:14:24 +00:00
|
|
|
--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))
|
2019-05-29 02:12:42 +00:00
|
|
|
(def todo @[])
|
2019-05-28 02:14:24 +00:00
|
|
|
(each arg args
|
|
|
|
(if (string/has-prefix? "--" arg)
|
2019-06-02 17:26:51 +00:00
|
|
|
(if-let [m (peg/match argpeg arg)]
|
|
|
|
(let [[key value] m]
|
|
|
|
(setdyn (keyword key) value))
|
|
|
|
(print "invalid argument " arg))
|
2019-05-29 02:12:42 +00:00
|
|
|
(array/push todo arg)))
|
|
|
|
|
2019-05-29 15:04:38 +00:00
|
|
|
(cook/import-rules "./project.janet")
|
2019-05-29 02:12:42 +00:00
|
|
|
|
2019-05-29 15:04:38 +00:00
|
|
|
(if (empty? todo) (help))
|
|
|
|
(each rule todo (cook/do-rule rule))
|