;; Matlab-interface ;; Copyright (c) 2002 Sebastian Seidel ;; This library is free software; you can redistribute it and/or ;; modify it under the terms of the GNU Lesser General Public ;; License as published by the Free Software Foundation; either ;; version 2.1 of the License, or (at your option) any later version. ;; This library is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; Lesser General Public License for more details. ;; You should have received a copy of the GNU Lesser General Public ;; License along with this library; if not, write to the Free Software ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ;; Contact me by mail: Sebastian.H.Seidel@med.uni-giessen.de ;; -------------------------------------------------------------------- ;; In plt-scheme it's impossible to unload an extension. As a result ;; it's also impossible to link a new extension-program without ;; killing mzscheme, if the extension-program is currently loaded. ;; This file - develop.ss - provides a procedure that works around ;; that bottleneck in the test-development-cycle. ;; Plus, it provides a procedure that packages the ;; matlab-interface-collection into a file named ;; 'matlab-interface.plt' and puts it into some directory. ;; -------------------------------------------------------------------- ;; Use matlab-interface to control matlab (www.mathworks.com) via ;; interprocess-communication from within the fantastic open-source ;; scheme-interpreters/compilers mzscheme and drscheme that are ;; distributed by plt (www.plt-scheme.org). ;; -------------------------------------------------------------------- ;; develop.ss ;; ========== ;; First-edition: 2002-10-27 SSeidel ;; Latest-revision: 2002-11-07 SSeidel ;; Exports ;; ------- ;; (install-load) Compile, link and load 'primitive.c'. ;; You still have to (require primitive). ;; Needs information about the location of some ;; files and directories inside the ;; matlab-directory-tree. ;; Reads that information from 'info.ss'. ;; You have to adjust the 'devhome'-value ;; in 'info.ss' to your personal configuration or ;; this procedure won't work. ;; (package ) Package the matlab-interface-collection ;; into a file named 'matlab-interface.plt'. ;; Put this file into . ;; -------------------------------------------------------------------- (module develop mzscheme (provide install-load package) (require (lib "compile.ss" "dynext") (lib "link.ss" "dynext") (lib "file.ss" "dynext") (lib "getinfo.ss" "setup") (lib "pack.ss" "setup")) (define collection-name '("matlab-interface")) (define step-0:workdir #f) ;; path to directory /collects/matlab-interface/ which contains 'step-1:srcfile' (define step-1:srcfile #f) ;; path to 'primitive.c' in directory step-0:workdir (define step-2:binsdir #f) ;; path to binary directory, a subdirectory of /collects/matlab-interface/compiled/ (define step-3:incldir #f) ;; path to matlab-include-directory which contains 'engine.h' (define step-4:objfile #f) ;; path to object-file - result of compiling 'primitive.c' - in directory 'step-2:binsdir' (define step-5:lnklibs #f) ;; list of matlab-link-libraries-paths (define step-6:extfile #f) ;; path to extension-file - result of linking step-4:objfile with step-5:lnklibs - in directory 'step-2:binsdir' (define explode-path ;; -> ( ...) ;; Split path-string into list of path-strings ;; ( ...) ;; similar functionality: 'explode-path' in mzlib/file.ss (lambda (base) (letrec ((P (lambda (ls base name) (cond ((or (eq? base 'relative) (eq? base #f)) (cons name ls)) ((string? base) (call-with-values (lambda () (split-path base)) (lambda (new-base new-name dummy) (P (cons name ls) new-base new-name)))) (#t (error 'explode-path:unexpected-condition)))))) (call-with-values (lambda () (split-path base)) (lambda (base name dummy) (P '() base name)))))) (define make-directory-layers ;; ( ...) ;; Make those directories: ;; base-path/ ;; base-path/relative-path1 ;; base-path/relative-path1/... (lambda (ls) (if (pair? ls) (let P ((ls (cdr ls)) (path (car ls))) (begin (or (directory-exists? path) (make-directory path)) (if (pair? ls) (P (cdr ls) (build-path path (car ls))) path))) (error 'make-directory-layers:empty-list)))) (define get-info-value ;; -> ;; definition of in module ;; collects/matlab-interface/info.ss ;; The namespace-hack is neccessary to get the _actual_ value. (lambda (sym) (let ((ns (make-namespace))) (parameterize ((current-namespace ns)) ((get-info collection-name) sym))))) (define init-setup-params (lambda () (newline) (set! step-0:workdir (apply build-path (get-info-value 'devhome) "collects" collection-name)) (display `(step-0:workdir ,step-0:workdir)) (newline) (set! step-1:srcfile (build-path step-0:workdir "primitive.c")) (display `(step-1:srcfile ,step-1:srcfile)) (newline) (set! step-2:binsdir (build-path step-0:workdir "compiled" "native" (system-library-subpath))) (display `(step-2:binsdir ,step-2:binsdir)) (newline) (set! step-3:incldir (get-info-value 'matlab-include-directory)) (display `(step-3:incldir ,step-3:incldir)) (newline) (set! step-4:objfile (build-path step-2:binsdir (append-object-suffix "primitive"))) (display `(step-4:objfile ,step-4:objfile)) (newline) (set! step-5:lnklibs (get-info-value 'matlab-link-libraries)) (display `(step-5:lnklibs ,step-5:lnklibs)) (newline) (set! step-6:extfile (let F ((id 0)) (let ((name (build-path step-2:binsdir (append-extension-suffix (string-append "primitive" "-" (number->string id)))))) (if (file-exists? name) (F (+ id 1)) name)))) (display `(step-6:extfile ,step-6:extfile)) (newline) (newline))) (define install-load (lambda () (init-setup-params) (make-directory-layers (explode-path step-2:binsdir)) (and (file-exists? step-4:objfile) (delete-file step-4:objfile)) (compile-extension #f step-1:srcfile step-4:objfile (list step-3:incldir)) (link-extension #f (cons step-4:objfile step-5:lnklibs) step-6:extfile) (load-extension step-6:extfile))) (define package (lambda (destdir) (pack-collections (build-path destdir "matlab-interface.plt") "matlab-interface" '(("matlab-interface")) #t '() ))))