From 961a08e65410a0b23ce10cbd49916e96e45aa1cc Mon Sep 17 00:00:00 2001 From: Matt Birkholz Date: Tue, 6 May 2014 20:36:12 -0700 Subject: [PATCH] ffi: Use Makefile to save shim build parameters. Install them in AUXDIR/shim-config.scm and use them in the compile-shim, link-shim, install-shim and install-load-option procedures. --- src/ffi/{build.scm.in => build.scm} | 119 +++++++++++++++------------ src/microcode/configure.ac | 1 - src/microcode/makegen/Makefile.in.in | 15 +++- 3 files changed, 79 insertions(+), 56 deletions(-) rename src/ffi/{build.scm.in => build.scm} (58%) diff --git a/src/ffi/build.scm.in b/src/ffi/build.scm similarity index 58% rename from src/ffi/build.scm.in rename to src/ffi/build.scm index 2696812c5..0f2cdb348 100644 --- a/src/ffi/build.scm.in +++ b/src/ffi/build.scm @@ -28,44 +28,53 @@ USA. ;;; package: (ffi build) (define (compile-shim) - (run-command (append cc-cmdline-prefix (command-line)))) + (let ((vals (conf-values (shim-conf) 'COMPILE-SHIM)) + (auxdir (conf-value (shim-conf) 'AUXDIR))) + (let ((prefix (append + (filter (lambda (i) (not (string=? "-DMIT_SCHEME" i))) + (parse-words (car vals))) + (list (string-append "-I" auxdir)) + (parse-words (cadr vals))))) + (run-command (append prefix (command-line)))))) (define (link-shim) - (run-command (append CCLD LDFLAGS (command-line) MODULE_LDFLAGS))) + (let ((vals (conf-values (shim-conf) 'LINK-SHIM))) + (let ((prefix (parse-words (car vals))) + (suffix (parse-words (cadr vals)))) + (run-command (append prefix (command-line) suffix))))) (define (install-shim destdir libname) (guarantee-string destdir 'INSTALL-SHIM) (guarantee-string libname 'INSTALL-SHIM) - (run-command (list "install" "-m" "644" - (string-append libname "-shim.so") - (string-append libname "-types.bin") - (string-append libname "-const.bin") - (string-append destdir - (->namestring - (system-library-directory-pathname)))))) + (if (string-find-next-char libname #\/) + (error "Directory separator, #\/, in library name:" libname)) + (let ((conf (shim-conf))) + (let ((install (conf-words conf 'INSTALL)) + (auxdir (conf-value conf 'AUXDIR))) + (run-command (append install + (list (string-append libname "-shim.so") + (string-append libname "-types.bin") + (string-append libname "-const.bin") + (string-append destdir auxdir))))))) (define (install-load-option destdir name #!optional directory) (guarantee-string destdir 'INSTALL-LOAD-OPTION) (guarantee-string name 'INSTALL-LOAD-OPTION) - (let ((dir (if (default-object? directory) name directory))) + (let ((conf (shim-conf)) + (dir (if (default-object? directory) + name + directory))) (guarantee-string dir 'INSTALL-LOAD-OPTION) - (let ((library-dir - (string-append destdir (->namestring - (merge-pathnames - (pathname-as-directory dir) - (system-library-directory-pathname)))))) - (run-command (list "rm" "-rf" library-dir)) - (run-command (list "mkdir" library-dir)) - (run-command (list "chmod" "755" library-dir)) - (run-command (append (list "install" "-m644") - (files) (list library-dir)))) - (rewrite-file (string-append - destdir - (->namestring - (merge-pathnames "optiondb.scm" - (system-library-directory-pathname)))) - (lambda (in out) - (rewrite-optiondb name dir in out))))) + (let ((install (conf-words conf 'INSTALL)) + (auxdir (conf-value conf 'AUXDIR))) + (let ((library-dir (string-append destdir auxdir dir))) + (run-command (list "rm" "-rf" library-dir)) + (run-command (list "mkdir" library-dir)) + (run-command (list "chmod" "755" library-dir)) + (run-command (append install (files) (list library-dir))) + (rewrite-file (string-append destdir auxdir "optiondb.scm") + (lambda (in out) + (rewrite-optiondb name dir in out))))))) (define (files) (append-map! @@ -90,15 +99,6 @@ USA. files))))) (command-line))) -(define (rewrite-file name rewriter) - (let ((tmp (pathname-new-type name "tmp"))) - (call-with-exclusive-output-file tmp - (lambda (out) - (call-with-input-file name - (lambda (in) - (rewriter in out))))) - (rename-file tmp name))) - (define (rewrite-optiondb name dirname in out) (do ((line (read-line in) (read-line in))) ((eof-object? line)) @@ -113,26 +113,39 @@ USA. (write-string dirname out) (write-string "\"))" out)) +(define (shim-conf) + (load (system-library-pathname "shim-config.scm"))) + +(define (conf-values conf name) + (let ((entry (assq name conf))) + (if (pair? entry) + (if (list-of-type? (cdr entry) string?) + (cdr entry) + (error "Configuration value not a list:" name)) + (error "Configuration value not found:" name)))) + +(define (conf-value conf name) + (let ((vals (conf-values conf name))) + (if (= 1 (length vals)) + (car vals) + (error "Configuration value not a single string:" name)))) + +(define (conf-words conf name) + (let ((val (conf-value conf name))) + (parse-words val))) + +(define (rewrite-file name rewriter) + (let ((tmp (pathname-new-type name "tmp"))) + (call-with-exclusive-output-file tmp + (lambda (out) + (call-with-input-file name + (lambda (in) + (rewriter in out))))) + (rename-file tmp name))) + (define (parse-words string) (burst-string string char-set:whitespace #t)) -(define CC (parse-words "@CC@")) -(define CFLAGS (parse-words "@CFLAGS@")) -(define CCLD (parse-words "@CCLD@")) -(define LDFLAGS (parse-words "@LDFLAGS@")) -(define MODULE_LDFLAGS (parse-words "@MODULE_LDFLAGS@")) -(define AUXDIR/ "@libdir@/@AUXDIR_NAME@/") -(define INSTALL_DATA (parse-words "@INSTALL_DATA@")) -(define cc-cmdline-prefix - (append - (filter - (lambda (i) (not (string=? "-DMIT_SCHEME" i))) - (parse-words "@CC@ @DEFS@ @SCHEME_DEFS@ @CPPFLAGS@")) - (list (string-append "-I" (->namestring - (directory-pathname - (system-library-pathname "mit-scheme.h"))))) - (parse-words "@CFLAGS@ @MODULE_CFLAGS@"))) - (define (run-command command) (fresh-line) (write-string (decorated-string-append "" " " "" command)) diff --git a/src/microcode/configure.ac b/src/microcode/configure.ac index 7ad05431f..d5ce85fcc 100644 --- a/src/microcode/configure.ac +++ b/src/microcode/configure.ac @@ -1129,7 +1129,6 @@ AC_SUBST([INSTALL_INCLUDE]) AC_SUBST([CCLD]) AC_CONFIG_FILES([Makefile]) -AC_CONFIG_FILES([../ffi/build.scm]) AC_OUTPUT # Make custom compilation program for "makegen.scm". diff --git a/src/microcode/makegen/Makefile.in.in b/src/microcode/makegen/Makefile.in.in index 2cf602cda..6f4585109 100644 --- a/src/microcode/makegen/Makefile.in.in +++ b/src/microcode/makegen/Makefile.in.in @@ -147,7 +147,7 @@ CLEAN_FILES = $(ALL_PROGRAMS) $(ALL_LIBS) $(ALL_DATA) $(EXTRA_PROGRAMS) DISTCLEAN_FILES = Makefile config.h config.cache config.log config.status \ cmpauxmd.m4 cmpauxmd.c cmpintmd.h makegen-cc \ - cmpintmd-config.h cmpintmd.c liarc-cc liarc-ld ../ffi/build.scm + cmpintmd-config.h cmpintmd.c liarc-cc liarc-ld MAINTAINER_CLEAN_FILES = Makefile.in Makefile.deps liarc-vars liarc-rules \ config.h.in configure TAGS @@ -269,7 +269,7 @@ install-auxLIBS: $(aux_LIBS) fi; \ done -install-auxDATA: $(aux_DATA) +install-auxDATA: shim-config.scm $(aux_DATA) $(mkinstalldirs) $(DESTDIR)$(AUXDIR) @list='$(aux_DATA)'; \ for p in $$list; do \ @@ -279,6 +279,17 @@ install-auxDATA: $(aux_DATA) fi; \ done $(INSTALL_DATA) pruxffi.h $(DESTDIR)$(AUXDIR)/mit-scheme.h + $(INSTALL_DATA) shim-config.scm $(DESTDIR)$(AUXDIR)/shim-config.scm + +shim-config.scm: + @echo "Saving shim compile/link/install configuration." + @ ( echo "(QUOTE"; \ + echo " ((COMPILE-SHIM \"@CC@ @DEFS@ @SCHEME_DEFS@ @CPPFLAGS@\""; \ + echo " \"@CFLAGS@ @MODULE_CFLAGS@\")"; \ + echo " (LINK-SHIM \"@CCLD@ @LDFLAGS@\" \"@MODULE_LDFLAGS@\")"; \ + echo " (INSTALL \"@INSTALL_DATA@\")"; \ + echo " (INFODIR \"$(infodir)/\")"; \ + echo " (AUXDIR \"$(AUXDIR)/\")))" ) >shim-config.scm install-include: $(mkinstalldirs) $(DESTDIR)$(AUXDIR) -- 2.25.1