diff --git a/scheme/install-lib/install-lib-module.scm b/scheme/install-lib/install-lib-module.scm index 78804ad..04af2e3 100644 --- a/scheme/install-lib/install-lib-module.scm +++ b/scheme/install-lib/install-lib-module.scm @@ -1,10 +1,12 @@ ;;; Installation library for scsh modules. -;;; $Id: install-lib-module.scm,v 1.4 2003/12/21 20:55:40 michel-schinz Exp $ +;;; $Id: install-lib-module.scm,v 1.5 2004/02/01 17:22:43 michel-schinz Exp $ ;;; Interfaces (define-interface install-interface - (export version->string + (export tmpl-libtool-la-reader + + version->string string->version version-compare versionsymbol key) + (kill-matches left-quotes-rx + (kill-matches right-quotes-rx val))))) + (define add-la-entry + (let ((splitter (infix-splitter (rx #\=))) + (comment-rx (rx (: bos #\#)))) + (lambda (line alist) + (cond + ((and (not (regexp-search? comment-rx line)) + (string-index line #\=)) + (let ((lst (splitter line))) + (if (= 2 (length lst)) + (cons (apply normalize-la-entry lst) alist) + (error "Could not read la entry" line list)))) + (else alist))))) + (define (read-libtool-la file-name) + (call-with-input-file + file-name + (lambda (port) + (let lp ((line (read-line port)) (alist '())) + (if (eof-object? line) + alist + (lp (read-line port) (add-la-entry line alist))))))))) ;; ;; Utilities ;; -(define default-perms #o755) +(define default-perms-fn + (lambda (name) #o755)) ;; Return the name of the parent directory of FNAME. (define (parent-directory fname) @@ -20,12 +58,13 @@ ;; Create directory FNAME and all its parents, as needed. (define (create-directory&parents fname . rest) - (let-optionals rest ((perms default-perms)) + (let-optionals rest ((perms-fn default-perms-fn)) (let ((parent (parent-directory fname))) (if (not (file-exists? parent)) (apply create-directory&parents parent rest)) (if (not (file-exists? fname)) - (-create-directory fname perms))))) + (-create-directory fname + (perms-fn (absolute-file-name fname))))))) ;; Return the length of the longest prefix common to lists L1 and L2, ;; by comparing elements using PRED (defaults to EQUAL?). @@ -54,17 +93,16 @@ (path-list->file-name (append new-root-pl (cdr fname-pl))) (error "no root to replace in relative file name" fname)))) -;; Copy file/symlink SOURCE to TARGET and set the permisions of TARGET -;; to PERMS. TARGET must be the name of a non-existing file (i.e. it -;; cannot be the name of a directory). -(define (copy-file source target perms) +;; Copy file/symlink SOURCE to TARGET. TARGET must be the name of a +;; non-existing file (i.e. it cannot be the name of a directory). +(define (copy-file source target) (if (file-exists? target) (error "copy-file: target file exists" target)) (if (file-symlink? source) (create-symlink (read-symlink source) target) (begin (run (cp ,source ,target)) - (set-file-mode target perms)))) + (set-file-mode target (file-mode source))))) ;; Like "load" but without printing anything. (define load-quietly @@ -91,49 +129,47 @@ ((not (null? rest)) (first rest)) (else (error "internal error: cannot find key in alist" key alist)))) +;; Convert all arguments to strings using DISPLAY and concatenate the +;; result in a single string which is returned. +(define (as-string . args) + (call-with-string-output-port + (lambda (port) (for-each (lambda (arg) (display arg port)) args)))) + ;; Return a string of max(M,N) white spaces. (define (spaces m n) (make-string (max m n) #\space)) ;; -;; Support for dry runs. +;; Support for dry runs / verbose operation. ;; -(define (wrap-for-dry-run real-fn dry-fn) +(define (wrap real-fn info-fn) (lambda args - (apply (if (get-option-value 'dry-run) dry-fn real-fn) args))) - -(define (dry-run-print msg . args) - (apply format #t msg args) (newline)) + (if (or (get-option-value 'verbose) (get-option-value 'dry-run)) + (begin (display (apply info-fn args)) (newline))) + (if (not (get-option-value 'dry-run)) + (apply real-fn args)))) (define -create-directory - (wrap-for-dry-run - create-directory - (lambda (fname . rest) - (let-optionals rest ((perms default-perms)) - (dry-run-print "creating directory ~a with permissions ~a" - fname - (permissions->string perms)))))) + (wrap create-directory + (lambda (fname . rest) + (let-optionals rest ((perms #o777)) + (as-string "creating directory " fname + " (perms: " (permissions->string perms) ")"))))) (define -create-symlink - (wrap-for-dry-run - create-symlink - (lambda (old-name new-name) - (dry-run-print "creating symbolic link ~a pointing to ~a" - new-name - old-name)))) + (wrap create-symlink + (lambda (old-name new-name) + (as-string "creating symbolic link " new-name + " pointing to " old-name)))) (define -copy-file - (wrap-for-dry-run - copy-file - (lambda (source target perms) - (dry-run-print "copying file ~a to ~a with permissions ~a" - source - target - (permissions->string perms))))) + (wrap copy-file + (lambda (source target) + (as-string "copying file " source " to " target)))) (define -delete-file - (wrap-for-dry-run delete-file - (lambda (fname) (dry-run-print "deleting file ~a" fname)))) + (wrap delete-file + (lambda (fname) (as-string "deleting file " fname)))) ;; ;; Versions @@ -368,6 +404,31 @@ (else '()))) packages)) +;; +;; Load script handling +;; + +;; Evaluate THUNK with CURRENT-OUTPUT-PORT opened on the current +;; package's loading script (in the install directory). During a dry +;; run, or when only non-shared data has to be installed, do nothing. +(define (with-output-to-load-script* thunk) + (let ((dir (get-directory 'base #t))) + (create-directory&parents dir) + (if (not (or (get-option-value 'dry-run) (get-option 'non-shared-only))) + (with-output-to-file (absolute-file-name "load.scm" dir) + thunk)))) + +;; Sugar for with-output-to-load-script*. +(define-syntax with-output-to-load-script + (syntax-rules () + ((with-output-to-load-script body ...) + (with-output-to-load-script* (lambda () body ...))))) + +;; Pretty-print all the elements of s-exps, one after the other, to +;; the current package's loading script (in the install directory). +(define (write-to-load-script s-exps) + (with-output-to-load-script (for-each p s-exps))) + ;; ;; Actions ;; @@ -383,7 +444,7 @@ (file-name-directory lnk-name)) lnk-name))) -(define (install-thing% layout name-or-pair location target-rel-dir perms) +(define (install-thing% layout name-or-pair location target-rel-dir perms-fn) (let* ((target-dir (absolute-file-name target-rel-dir (layout-dir layout location))) (source (if (pair? name-or-pair) (car name-or-pair) name-or-pair)) @@ -391,33 +452,37 @@ (cdr name-or-pair) name-or-pair))) (target (absolute-file-name target-name target-dir))) - (create-directory&parents target-dir perms) + (create-directory&parents target-dir perms-fn) (cond ((or (file-regular? source) (file-symlink? source)) - (-copy-file source target perms)) + (-copy-file source target)) ((file-directory? source) - (-create-directory target perms) + (-create-directory target (file-mode source)) (install-directory-contents% layout source location (absolute-file-name target-name target-rel-dir) - perms)) + perms-fn)) (else (error "cannot install file-system object" source))))) -(define (install-directory-contents% layout name location target-rel-dir perms) +(define (install-directory-contents% layout + name + location + target-rel-dir + perms-fn) (for-each (lambda (thing) - (install-thing% layout thing location target-rel-dir perms)) + (install-thing% layout thing location target-rel-dir perms-fn)) (map (lambda (f) (absolute-file-name f name)) (directory-files name #t)))) (define (install-thing name-or-pair location . rest) (if (active-location? location) - (let-optionals rest ((target-rel-dir ".") (perms default-perms)) + (let-optionals rest ((target-rel-dir ".") (perms-fn default-perms-fn)) (install-thing% (fluid *install-layout*) name-or-pair location target-rel-dir - perms)))) + perms-fn)))) (define (install-things names-or-pairs . rest) (for-each (lambda (name-or-pair) @@ -431,23 +496,12 @@ (define (install-directory-contents name location . rest) (if (active-location? location) - (let-optionals rest ((target-rel-dir ".") (perms default-perms)) + (let-optionals rest ((target-rel-dir ".") (perms-fn default-perms-fn)) (install-directory-contents% (fluid *install-layout*) name location target-rel-dir - perms)))) - -(define (install-empty-directory% layout name location dir . rest) - (let-optionals rest ((perms default-perms)) - (-create-directory (absolute-file-name dir (layout-dir layout location)) - perms))) - -(define (install-empty-directory&parents% layout name location dir . rest) - (let-optionals rest ((perms default-perms)) - (create-directory&parents - (absolute-file-name dir (layout-dir layout location)) - perms))) + perms-fn)))) (define *layout* (make-fluid #f)) (define *install-layout* (make-fluid #f)) @@ -488,6 +542,7 @@ options: --layout specify layout of installation directory (predefined: ~a) --dry-run don't do anything, print what would have been done + --verbose print messages about what is being done --inactive don't activate package after installing it --non-shared-only only install platform-dependent files, if any @@ -588,7 +643,8 @@ END (option '("non-shared-only") #f #f (alist-boolean-updater 'non-shared-only)) (option '("inactive") #f #f (alist-boolean-updater 'inactive)) - (option '("dry-run") #f #f (alist-boolean-updater 'dry-run))))) + (option '("dry-run") #f #f (alist-boolean-updater 'dry-run)) + (option '("verbose") #f #f (alist-boolean-updater 'verbose))))) (define options-defaults `((prefix . #f) @@ -598,7 +654,8 @@ END (build . ,(host)) (non-shared-only . #f) (inactive . #f) - (dry-run . #f))) + (dry-run . #f) + (verbose . #f))) (define (parse-options args options defaults) (args-fold args diff --git a/scheme/install-lib/install-pkg b/scheme/install-lib/install-pkg index edfb852..58023dd 100755 --- a/scheme/install-lib/install-pkg +++ b/scheme/install-lib/install-pkg @@ -1,3 +1,3 @@ #!/bin/sh -exec scsh -lm configure.scm -lm install-lib-module.scm -o configure -o install -e install-main -s "$0" "$@" +exec scsh -lm configure.scm -lm install-lib-module.scm -o pp -o configure -o install -e install-main -s "$0" "$@" !#