From 898345db5240fcfca1567725fa9779b1fecbe1c7 Mon Sep 17 00:00:00 2001
From: Matt Birkholz <puck@birchwood-abbey.net>
Date: Wed, 7 May 2014 21:22:58 -0700
Subject: [PATCH] ffi: Punt AUXDIR from shim-config.scm.

Procedures like compile-shim need to use the first directory in
MITSCHEME_LIBRARY_PATH (not the installation directory) so that the
FFI test can override it, getting the not-yet-installed configuration
from the build directory.

Symlink shim-config.scm to src/lib/ and generate it during `make all',
not `make install', so that it is available to the test FFI (during
`make check').

Fix FFI test NOT to use with-notification around `make', which cannot
use fresh-line.  Just write whole lines to notification-output-port.
---
 src/Setup.sh                         |  1 +
 src/ffi/build.scm                    | 36 ++++++++++++++--------------
 src/microcode/makegen/Makefile.in.in |  8 +++----
 tests/ffi/test-ffi.scm               | 19 ++++++++-------
 4 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/src/Setup.sh b/src/Setup.sh
index cd75b2ed7..be58b94cb 100755
--- a/src/Setup.sh
+++ b/src/Setup.sh
@@ -82,6 +82,7 @@ OTHER_SUBDIRS="6001 compiler rcs runtime win32 xdoc microcode"
 maybe_mkdir lib
 maybe_link lib/include ../microcode
 maybe_link lib/mit-scheme.h ../microcode/pruxffi.h
+maybe_link lib/shim-config.scm ../microcode/shim-config.scm
 maybe_link lib/optiondb.scm ../etc/optiondb.scm
 
 maybe_link lib/compiler ../compiler
diff --git a/src/ffi/build.scm b/src/ffi/build.scm
index e31bcb5b9..63bd5a146 100644
--- a/src/ffi/build.scm
+++ b/src/ffi/build.scm
@@ -28,12 +28,11 @@ USA.
 ;;; package: (ffi build)
 
 (define (compile-shim)
-  (let ((vals (conf-values (shim-conf) 'COMPILE-SHIM))
-	(auxdir (conf-value (shim-conf) 'AUXDIR)))
+  (let ((vals (conf-values (shim-conf) 'COMPILE-SHIM)))
     (let ((prefix (append
 		   (filter (lambda (i) (not (string=? "-DMIT_SCHEME" i)))
 			   (parse-words (car vals)))
-		   (list (string-append "-I" auxdir))
+		   (list (string-append "-I" (auxdir)))
 		   (parse-words (cadr vals)))))
       (run-command (append prefix (command-line))))))
 
@@ -48,25 +47,21 @@ USA.
   (guarantee-string libname 'INSTALL-SHIM)
   (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)))))))
+  (run-command (append (conf-words (shim-conf) '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 ((conf (shim-conf))
-	(dir (if (default-object? directory)
+  (let ((dir (if (default-object? directory)
 		 name
 		 directory)))
     (guarantee-string dir 'INSTALL-LOAD-OPTION)
-    (let ((install (conf-words conf 'INSTALL))
-	  (auxdir (conf-value conf 'AUXDIR)))
+    (let ((install (conf-words (shim-conf) 'INSTALL))
+	  (auxdir (auxdir)))
       (let ((library-dir (string-append destdir auxdir dir)))
 	(run-command (list "rm" "-rf" library-dir))
 	(run-command (list "mkdir" library-dir))
@@ -181,12 +176,17 @@ USA.
 
   (copy-suffix (copy-items)))
 
+(define (auxdir)
+  (->namestring (system-library-directory-pathname)))
+
 (define (shim-conf)
-  (load (system-library-pathname "shim-config.scm")))
+  (fluid-let ((load/suppress-loading-message? #t))
+    (load (system-library-pathname "shim-config.scm"))))
 
 (define (doc-conf)
-  (load (string-append (conf-value (shim-conf) 'INFODIR)
-		       "mit-scheme-doc-config.scm")))
+  (fluid-let ((load/suppress-loading-message? #t))
+    (load (string-append (conf-value (shim-conf) 'INFODIR)
+				     "mit-scheme-doc-config.scm"))))
 
 (define (conf-values conf name)
   (let ((entry (assq name conf)))
diff --git a/src/microcode/makegen/Makefile.in.in b/src/microcode/makegen/Makefile.in.in
index 6f4585109..4045791e7 100644
--- a/src/microcode/makegen/Makefile.in.in
+++ b/src/microcode/makegen/Makefile.in.in
@@ -120,7 +120,7 @@ MODULE_LIBS = -lc
 
 aux_PROGRAMS = @AUX_PROGRAMS@
 aux_LIBS = $(MODULE_TARGETS)
-aux_DATA = @AUX_DATA@
+aux_DATA = shim-config.scm @AUX_DATA@
 EXTRA_PROGRAMS = findprim
 
 scheme_SOURCES = $(STD_SOURCES) usrdef.c $(LIARC_SOURCES)
@@ -269,7 +269,7 @@ install-auxLIBS: $(aux_LIBS)
 	    fi; \
 	done
 
-install-auxDATA: shim-config.scm $(aux_DATA)
+install-auxDATA: $(aux_DATA)
 	$(mkinstalldirs) $(DESTDIR)$(AUXDIR)
 	@list='$(aux_DATA)'; \
 	for p in $$list; do \
@@ -279,7 +279,6 @@ install-auxDATA: shim-config.scm $(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."
@@ -288,8 +287,7 @@ shim-config.scm:
 	    echo "                \"@CFLAGS@ @MODULE_CFLAGS@\")"; \
 	    echo "  (LINK-SHIM \"@CCLD@ @LDFLAGS@\" \"@MODULE_LDFLAGS@\")"; \
 	    echo "  (INSTALL \"@INSTALL_DATA@\")"; \
-	    echo "  (INFODIR \"$(infodir)/\")"; \
-	    echo "  (AUXDIR \"$(AUXDIR)/\")))" ) >shim-config.scm
+	    echo "  (INFODIR \"$(infodir)/\")))" ) >shim-config.scm
 
 install-include:
 	$(mkinstalldirs) $(DESTDIR)$(AUXDIR)
diff --git a/tests/ffi/test-ffi.scm b/tests/ffi/test-ffi.scm
index 90d5d3c07..52c6b81dd 100644
--- a/tests/ffi/test-ffi.scm
+++ b/tests/ffi/test-ffi.scm
@@ -28,15 +28,16 @@ USA.
 
 (with-working-directory-pathname (directory-pathname (current-load-pathname))
   (lambda ()
-    (let ((code
-	   (with-notification
-	    (lambda (port)
-	      (write-string "make all" port)
-	      (newline port))
-	    (lambda ()
-	      (run-synchronous-subprocess "make" (list "all"))))))
-      (if (not (zero? code))
-	  (warn "Test library build failed:" code)
+    (let ((port (notification-output-port)))
+      (fresh-line port)
+      (write-string "make all in tests/ffi/" port)
+      (newline port))
+    (let ((status (run-synchronous-subprocess "make" (list "all"))))
+      (if (not (zero? status))
+	  (begin
+	    (write-string "../tests/ffi/test-ffi.scm:0: Test FFI build failed."
+			  (notification-output-port))
+	    (error "Test FFI build failed:" status))
 	  (begin
 	    (fluid-let ((load/suppress-loading-message? #t))
 	      (load-option 'FFI))
-- 
2.25.1