#!/usr/bin/csi -s (use extras posix matchable) (include "chicken-env") (define (print-error msg . args) (apply fprintf (current-error-port) msg args) (newline (current-error-port))) (define (usage) (fail "Usage: ~A [OPTION ...] NAME Build Chicken in current directory and install it to $CHICKENS/NAME. Options: -b build and use a bootstrap Chicken -d make a debug build -s use NAME as PROGRAM_SUFFIX -p use NAME as PORGRAM_PREFIX" (program-name))) (define build-boot-chicken? #f) (define debug-build? #f) (define suffix-name? #f) (define prefix-name? #f) (define chicken-name #f) (when (null? (command-line-arguments)) (usage)) (let loop ((args (command-line-arguments))) (match args (("-b" rest ...) (set! build-boot-chicken? #t) (loop rest)) (("-s" rest ...) (set! suffix-name? #t) (loop rest)) (("-p" rest ...) (set! prefix-name? #t) (loop rest)) (("-d" rest ...) (set! debug-build? #t) (loop rest)) ((name) (set! chicken-name name)) (rest (print-error "Invalid arguments: ~S" rest) (usage)))) (unless chicken-name (usage)) (when (and suffix-name? prefix-name?) (fail "Only one of -p and -s can be passed")) (define chicken-path (normalize-pathname (make-pathname chicken-coop chicken-name))) (define (run name . args) (unless (process-wait (process-run name args)) (exit 1))) (when (file-exists? chicken-path) (printf "Chicken already exists: ~A" chicken-path) (if (yes-or-no? "Purge and continue?" #f #f exit) (run "rm" "-rf" chicken-path) (exit))) (create-directory chicken-path) (when build-boot-chicken? (run "make" "boot-chicken") (setenv "CHICKEN" "./chicken-boot")) (when prefix-name? (setenv "PROGRAM_PREFIX" (string-append chicken-name "-"))) (when suffix-name? (setenv "PROGRAM_SUFFIX" (string-append "-" chicken-name))) (when debug-build? (setenv "DEBUGBUILD" "1")) (setenv "PREFIX" chicken-path) (run "make") (run "make" "install")