~ chicken-core (master) /scripts/makedist.scm


  1;;;; makedist.scm - Make distribution tarballs
  2
  3
  4(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))
 14
 15(include "mini-srfi-1.scm")
 16
 17(define *help* #f)
 18
 19(define BUILDVERSION (with-input-from-file "buildversion" read))
 20
 21(define *platform*
 22  (let ((sv (symbol->string (software-version))))
 23    (cond ((irregex-match ".*bsd" sv) "bsd")
 24	  (else sv))))
 25
 26(define *make*
 27  (cond ((string=? "bsd" *platform*) "gmake")
 28	(else "make")))
 29
 30(define (prefix dir . files)
 31  (if (null? files)
 32      (pathname-directory dir)
 33      (let ((files2 (map (cut make-pathname dir <>) (normalize files))))
 34	(if (or (pair? (cdr files)) (pair? (car files)))
 35	    files2
 36	    (car files2) ) ) ) )
 37
 38(define (normalize fs)
 39  (delete-duplicates
 40   (map ->string
 41	(if (pair? fs)
 42	    (flatten fs)
 43	    (list fs) ) )
 44   equal?) )
 45
 46(define (run . args)
 47  (let ((cmd (apply format args)))
 48    (display cmd (current-error-port))
 49    (newline (current-error-port))
 50    (system* cmd)))
 51
 52(define (release)
 53  (let* ((files (with-input-from-file "distribution/manifest" read-lines))
 54	 (distname (conc "chicken-" BUILDVERSION))
 55	 (distfiles (map (cut prefix distname <>) files))
 56	 (tgz (conc distname ".tar.gz")))
 57    (run "rm -fr ~a ~a" distname tgz)
 58    (create-directory distname)
 59    (for-each
 60     (lambda (d)
 61       (let ((d (make-pathname distname d)))
 62	 (unless (file-exists? d)
 63	   (print "creating " d)
 64	   (create-directory d 'with-parents))))
 65     (delete-duplicates (filter-map prefix files) string=?))
 66    (let ((missing
 67	   (foldl (lambda (missing f)
 68		    (cond
 69		     ((file-exists? f)
 70		      (run "cp -p ~a ~a" (qs f) (qs (make-pathname distname f)))
 71		      missing)
 72		     (else (cons f missing))))
 73		  '() files)))
 74      (unless (null? missing)
 75        (fprintf (current-error-port) "[ERROR] files missing: ~A~%" missing)
 76        (exit 1) ) )
 77    (run "tar cfz ~a ~a" (conc distname ".tar.gz") distname)
 78    (run "rm -fr ~a" distname)))
 79
 80(define (usage)
 81  (print "usage: makedist [-make PROGRAM] [--platform=PLATFORM] MAKEOPTION ...")
 82  (exit))
 83
 84(define *makeargs*
 85  (let loop ((args (command-line-arguments)))
 86    (if (null? args)
 87	'()
 88	(let ((arg (car args)))
 89	  (cond ((string=? "-make" arg)
 90		 (set! *make* (cadr args))
 91		 (loop (cddr args)))
 92		((string=? "-help" arg)
 93		 (usage))
 94		((string=? "-platform" arg)
 95		 (set! *platform* (cadr args))
 96		 (loop (cddr args)))
 97		(else (cons arg (loop (cdr args)))))))))
 98
 99(run "~a -f Makefile.~a distfiles ~a" *make* *platform* (string-intersperse *makeargs*))
100
101(release)
Trap