~ chicken-core (chicken-5) /scripts/makedist.scm
Trap1;;;; makedist.scm - Make distribution tarballs234(import (chicken file)5 (chicken fixnum)6 (chicken format)7 (chicken io)8 (chicken irregex)9 (chicken pathname)10 (chicken platform)11 (chicken process)12 (chicken process-context)13 (chicken string))1415(include "mini-srfi-1.scm")1617(define *help* #f)1819(define BUILDVERSION (with-input-from-file "buildversion" read))2021(define *platform*22 (let ((sv (symbol->string (software-version))))23 (cond ((irregex-match ".*bsd" sv) "bsd")24 ((string=? sv "mingw32")25 (if (equal? (get-environment-variable "MSYSTEM") "MINGW32")26 "mingw-msys"27 "mingw32"))28 (else sv))))2930(define *make*31 (cond ((string=? "bsd" *platform*) "gmake")32 ((string=? "mingw32" *platform*) "mingw32-make")33 (else "make")))3435(define (prefix dir . files)36 (if (null? files)37 (pathname-directory dir)38 (let ((files2 (map (cut make-pathname dir <>) (normalize files))))39 (if (or (pair? (cdr files)) (pair? (car files)))40 files241 (car files2) ) ) ) )4243(define (normalize fs)44 (delete-duplicates45 (map ->string46 (if (pair? fs)47 (flatten fs)48 (list fs) ) )49 equal?) )5051(define (run . args)52 (let ((cmd (apply format args)))53 (display cmd (current-error-port))54 (newline (current-error-port))55 (system* cmd)))5657(define (release)58 (let* ((files (with-input-from-file "distribution/manifest" read-lines))59 (distname (conc "chicken-" BUILDVERSION))60 (distfiles (map (cut prefix distname <>) files))61 (tgz (conc distname ".tar.gz")))62 (run "rm -fr ~a ~a" distname tgz)63 (create-directory distname)64 (for-each65 (lambda (d)66 (let ((d (make-pathname distname d)))67 (unless (file-exists? d)68 (print "creating " d)69 (create-directory d 'with-parents))))70 (delete-duplicates (filter-map prefix files) string=?))71 (let ((missing72 (foldl (lambda (missing f)73 (cond74 ((file-exists? f)75 (run "cp -p ~a ~a" (qs f) (qs (make-pathname distname f)))76 missing)77 (else (cons f missing))))78 '() files)))79 (unless (null? missing)80 (warning "files missing" missing) ) )81 (run "tar cfz ~a ~a" (conc distname ".tar.gz") distname)82 (run "rm -fr ~a" distname)))8384(define (usage)85 (print "usage: makedist [-make PROGRAM] [--platform=PLATFORM] MAKEOPTION ...")86 (exit))8788(define *makeargs*89 (let loop ((args (command-line-arguments)))90 (if (null? args)91 '()92 (let ((arg (car args)))93 (cond ((string=? "-make" arg)94 (set! *make* (cadr args))95 (loop (cddr args)))96 ((string=? "-help" arg)97 (usage))98 ((string=? "-platform" arg)99 (set! *platform* (cadr args))100 (loop (cddr args)))101 (else (cons arg (loop (cdr args)))))))))102103(run "~a -f Makefile.~a distfiles ~a" *make* *platform* (string-intersperse *makeargs*))104105(release)