-make $testfilestem.o
-ld -shared -o $testfilestem.so $testfilestem.o
-
-${SBCL:-sbcl} <<EOF
- (handler-case
- (load-foreign '("$testfilestem.so"))
- (sb-int:unsupported-operator ()
- ;; At least as of sbcl-0.7.0.5, LOAD-FOREIGN isn't supported
- ;; on every OS. In that case, there's nothing to test, and we
- ;; can just fall through to success.
- (sb-ext:quit :unix-status 52))) ; success convention for Lisp program
+echo 'int numberish = 42;' >> $testfilestem.c
+echo 'int nummish(int x) { return numberish + x; }' >> $testfilestem.c
+echo 'short negative_short() { return -1; }' >> $testfilestem.c
+echo 'int negative_int() { return -2; }' >> $testfilestem.c
+echo 'long negative_long() { return -3; }' >> $testfilestem.c
+build_so $testfilestem
+
+echo 'int foo = 13;' > $testfilestem-b.c
+echo 'int bar() { return 42; }' >> $testfilestem-b.c
+build_so $testfilestem-b
+
+echo 'int foo = 42;' > $testfilestem-b2.c
+echo 'int bar() { return 13; }' >> $testfilestem-b2.c
+build_so $testfilestem-b2
+
+echo 'int late_foo = 43;' > $testfilestem-c.c
+echo 'int late_bar() { return 14; }' >> $testfilestem-c.c
+build_so $testfilestem-c
+
+## Foreign definitions & load
+
+cat > $testfilestem.def.lisp <<EOF
+ (define-alien-variable environ (* c-string))
+ (defvar *environ* environ)
+ (eval-when (:compile-toplevel :load-toplevel :execute)
+ (handler-case
+ (progn
+ (load-shared-object "$testfilestem.so")
+ (load-shared-object "$testfilestem-b.so"))
+ (sb-int:unsupported-operator ()
+ ;; At least as of sbcl-0.7.0.5, LOAD-SHARED-OBJECT isn't
+ ;; supported on every OS. In that case, there's nothing to test,
+ ;; and we can just fall through to success.
+ (sb-ext:quit :unix-status 22)))) ; catch that