2018-02-06 20:22:50 +00:00
|
|
|
#!/usr/bin/guile -s
|
|
|
|
!#
|
|
|
|
(use-modules
|
|
|
|
(ice-9 match)
|
|
|
|
(srfi srfi-1)
|
|
|
|
(ice-9 format)
|
|
|
|
(ice-9 regex))
|
|
|
|
|
|
|
|
;; (format #t "~2%")
|
|
|
|
|
|
|
|
(define *options*
|
|
|
|
'("pac" "size"))
|
|
|
|
|
|
|
|
(define *project-name*
|
|
|
|
(regexp-substitute #f (string-match ".*/" (getcwd)) 'post))
|
|
|
|
|
2018-12-20 05:19:42 +00:00
|
|
|
;; Looks through the args list for the first occurrence of each valid
|
|
|
|
;; option from *options*
|
2018-02-06 20:22:50 +00:00
|
|
|
(define get-valid-args
|
|
|
|
(lambda (cli-args)
|
2018-12-20 05:19:42 +00:00
|
|
|
;; (format (current-error-port) "cli-args - ~s~%" cli-args)
|
2018-02-06 20:22:50 +00:00
|
|
|
(map (lambda (opt)
|
|
|
|
(find (lambda (cli-word)
|
|
|
|
(string-match
|
2018-12-20 05:19:42 +00:00
|
|
|
(string-append "^" opt)
|
2018-02-06 20:22:50 +00:00
|
|
|
cli-word))
|
|
|
|
cli-args))
|
|
|
|
*options*)))
|
|
|
|
|
2018-12-20 05:19:42 +00:00
|
|
|
;; changes args into a key-value alist
|
2018-02-06 20:22:50 +00:00
|
|
|
(define valid-args->alist
|
|
|
|
(lambda (valid-args)
|
2018-12-20 05:19:42 +00:00
|
|
|
;; (format (current-error-port) "valid-args - ~s~%" valid-args)
|
2018-02-06 20:22:50 +00:00
|
|
|
(map (lambda (arg)
|
|
|
|
(and arg
|
|
|
|
(string-contains arg "=")
|
|
|
|
(cons
|
|
|
|
(regexp-substitute #f (string-match "=" arg) 'pre)
|
|
|
|
(regexp-substitute #f (string-match "=" arg) 'post))))
|
|
|
|
valid-args)))
|
|
|
|
|
|
|
|
(if (< (length (command-line)) 2)
|
|
|
|
(format #t "~a~%" "Usage: build.scm TARGET [ARG=VALUE]*")
|
2018-12-20 05:19:42 +00:00
|
|
|
(let* ((cli-args (command-line))
|
|
|
|
(target (cadr cli-args))
|
2018-02-06 20:22:50 +00:00
|
|
|
(valid-args (get-valid-args cli-args))
|
2018-12-20 05:19:42 +00:00
|
|
|
(args-alist (valid-args->alist valid-args))
|
|
|
|
(size (match (assoc-ref args-alist "size")
|
|
|
|
("a4" "-a4")
|
|
|
|
(_ "")))
|
|
|
|
(pac (match (assoc-ref args-alist "pac")
|
|
|
|
("off" "-dno-point-and-click ")
|
|
|
|
(_ "")))
|
|
|
|
(ly-command (string-append "lilypond "
|
|
|
|
pac
|
|
|
|
"-o \"output/"
|
|
|
|
*project-name*
|
|
|
|
(match target
|
|
|
|
("main" "")
|
|
|
|
(_ (string-append "-" target)))
|
|
|
|
(match pac
|
|
|
|
("" "-pacON")
|
|
|
|
(_ ""))
|
|
|
|
(match size
|
|
|
|
("" "")
|
|
|
|
(_ "-"))
|
|
|
|
size
|
|
|
|
"\" "
|
|
|
|
target size ".ly")))
|
|
|
|
;; (format (current-error-port)
|
|
|
|
;; (string-append
|
|
|
|
;; "cli-args - ~s~%"
|
|
|
|
;; "target - ~s~%"
|
|
|
|
;; "valid-args - ~s~%"
|
|
|
|
;; "args-alist - ~s~%"
|
|
|
|
;; "size - ~s~%"
|
|
|
|
;; "pac - ~s~%")
|
|
|
|
;; cli-args
|
|
|
|
;; target
|
|
|
|
;; valid-args
|
|
|
|
;; args-alist
|
|
|
|
;; size
|
|
|
|
;; pac)
|
2018-02-06 20:22:50 +00:00
|
|
|
(format #t "~2%~a~2%" ly-command)
|
|
|
|
(system ly-command)))
|