+ (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 (cons (list-element-index joblist pid) errors)))))
+ joblist)
+
+ (for-each
+ (lambda (x)
+ (let* ((logfile (format "~a-~a.log"
+ (ly:get-option 'log-file) x))
+ (log (ly:gulp-file logfile))
+ (len (string-length log))
+ (tail (substring log (max 0 (- len 1024)))))
+
+ (display (format "\n\nlogfile ~a:\n\n ~a" logfile tail))))
+
+ errors)
+
+ (if (pair? errors)
+ (ly:error "Children ~a exited with errors." errors))
+
+ (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"))
+