First commit

The first version was quickly hacked together on
2016-06-04T22:27:05+0530

Till the time I got around to making a repo for it and making this first
commit, I had already made a few fixes.
This commit is contained in:
Kashish Sharma 2016-06-07 10:19:01 +05:30
commit 17b28f60e3
1 changed files with 110 additions and 0 deletions

110
build.scm Normal file
View File

@ -0,0 +1,110 @@
#!/usr/bin/guile -s
!#
(use-modules
(ice-9 match)
(srfi srfi-1)
(ice-9 format)
(ice-9 regex))
;; TODO - Make it declarative - define *options* and their effect,
;; and the structure of the command, separately from the code that
;; makes it happen.
;; Use regexes to define target names and how the output file
;; name(s) derive from them.
;; Also, add support for part-<instrument>.ly ->
;; <project-name>-<instrument>.pdf files.
;;;; HYPOTHETICAL CONFIG in that style -
;; (options
;; (pac ("off" "-dno-point-and-click")
;; (_ ""))
;; (size ("a4" "-a4")
;; (_ "")))
;; (targets
;; ;; 'target' is automatically bound to the first arg - here, "main"
;; ("main" target project-name)
;; ;; and now, "band"
;; ("band" target (string-append project-name "\1"))
;; (_ (string-append "part-" target)
;; (string-append project-name "-" target)))
;; ;; ifile and ofile are taken from the first and second args of the
;; ;; target as defined in TARGETS
;; (command "lilypond" pac "-o output/" ofile size " " ifile size ".ly")
;;;; HYPOTHETICAL CONFIG ENDS
;;;; TODO - tab completion
;;;; It would also be useful to compile the part-<instrument>.ly file
;;;; if I'm editing an <instrument-class>/<instrument>.ly file -
;;;; useful when working with orchestral files and wanting to put the
;;;; generated MIDI in qtractor (importing a single track is easier
;;;; than importing a multi-track MIDI just because you changed music
;;;; on one track). That's more of an Emacs-side thing, though.
;;;;
;;;; ...hell, one could define all kinds of rules - "when I'm working
;;;; with such-and-such files, compile such-and-such targets."
;; (format #t "~2%")
(define *options*
'("pac" "size"))
(define *project-name*
(regexp-substitute #f (string-match ".*/" (getcwd)) 'post))
(define get-valid-args
(lambda (cli-args)
;; (format (current-error-port) "~s~s~%" "cli-args - " cli-args)
(map (lambda (opt)
(find (lambda (cli-word)
(string-match
(string-append opt "*")
cli-word))
cli-args))
*options*)))
(define valid-args->alist
(lambda (valid-args)
;; (format (current-error-port) "~s~s~%" "valid-args - " valid-args)
(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]*")
(let* ((cli-args (command-line))
(target (cadr cli-args))
(valid-args (get-valid-args cli-args))
(alist (valid-args->alist valid-args))
(size (match (assoc-ref alist "size")
("a4" "-a4")
(_ "")))
(ly-command (string-append
"lilypond "
(match (assoc-ref alist "pac")
("off" "-dno-point-and-click ")
(_ ""))
"-o output/"
*project-name* (match target
("main" "")
(_ (string-append "-" target)))
size
" "
target size ".ly")))
;; (format (current-error-port) "~s~s~%" "alist - " alist)
(format #t "~2%~a~2%" ly-command)
(system ly-command)))