+ (if (ly:get-option 'read-file-list)
+ (set! files
+ (filter (lambda (s)
+ (> (string-length s) 0))
+ (apply append
+ (map (lambda (f) (string-split (ly:gulp-file f) #\nl))
+ files)))
+ ))
+
+ (if (and (number? (ly:get-option 'job-count))
+ (>= (length files) (ly:get-option 'job-count)))
+
+ (let*
+ ((count (ly:get-option 'job-count))
+ (split-todo (split-list files count))
+ (joblist (multi-fork count))
+ (errors '()))
+
+ (if (not (string-or-symbol? (ly:get-option 'log-file)))
+ (ly:set-option 'log-file "lilypond-multi-run"))
+
+ (if (number? joblist)
+ (begin
+ (ly:set-option 'log-file (format "~a-~a"
+ (ly:get-option 'log-file) joblist))
+ (set! files (vector-ref split-todo joblist)))
+
+ (begin
+ (ly:progress "\nForking into jobs: ~a\n" joblist)
+ (for-each
+ (lambda (pid)
+ (let* ((stat (cdr (waitpid pid))))
+
+ (if (not (= stat 0))
+ (set! errors (acons (list-element-index joblist pid) stat errors)))))
+ joblist)
+
+ (for-each
+ (lambda (x)
+ (let* ((job (car x))
+ (state (cdr x))
+ (logfile (format "~a-~a.log"
+ (ly:get-option 'log-file) job))
+ (log (ly:gulp-file logfile))
+ (len (string-length log))
+ (tail (substring log (max 0 (- len 1024)))))
+
+ (if (status:term-sig state)
+ (ly:message "\n\n~a\n"
+ (format (_ "job ~a terminated with signal: ~a")
+ job
+ (status:term-sig state)))
+ (ly:message (_ "logfile ~a (exit ~a):\n~a") logfile (status:exit-val state) tail))))
+
+ errors)
+
+ (if (pair? errors)
+ (ly:error "Children ~a exited with errors." (map car errors)))
+
+ ;; must overwrite individual entries
+ (if (ly:get-option 'dump-profile)
+ (dump-profile "lily-run-total" '(0 0) (profile-measurements)))
+
+ (exit (if (null? errors) 0 1))))))
+
+
+ (if (string-or-symbol? (ly:get-option 'log-file))
+ (ly:stderr-redirect (format "~a.log" (ly:get-option 'log-file)) "w"))
+
+