From 9dc31e07ac9162ee094f34db7357c2a729d29874 Mon Sep 17 00:00:00 2001
From: Matthias Benkard <code@mail.matthias.benkard.de>
Date: Sat, 26 Jan 2008 13:07:04 +0100
Subject: Automatically build libffi when loading the system.

darcs-hash:4052b064360c7f3fea44f8360edc845540307ac3
---
 Objective-C/GNUmakefile | 18 +++++++++++++++---
 objective-cl.asd        | 23 +++++++++++++----------
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/Objective-C/GNUmakefile b/Objective-C/GNUmakefile
index 72ad050..11d87ae 100644
--- a/Objective-C/GNUmakefile
+++ b/Objective-C/GNUmakefile
@@ -30,22 +30,29 @@ libobjcl_OBJC_FILES = libobjcl.m objc_support.m objc-runtime-apple.m objc-runtim
 LIBRARIES_DEPEND_UPON = $(FND_LIBS) $(GUI_LIBS) $(OBJC_LIBS) $(SYSTEM_LIBS) $(CONFIG_SYSTEM_LIBS)
 
 ifdef USE_LIBFFI
-ADDITIONAL_LDFLAGS = -lffi
+ADDITIONAL_LDFLAGS = -Wl,-rpath $(CURDIR)/../libffi/.libs -L../libffi/.libs -lffi
 ADDITIONAL_OBJCFLAGS += -DUSE_LIBFFI
 libobjcl_OBJC_FILES += libffi_support.m
+FFI_DEPS += ../libffi/.libs/libffi.a
+FFI_CLEAN += libffi_clean
 endif
 
 ifneq ($(COMMON_MAKE_LOADED),)
 -include $(GNUSTEP_MAKEFILES)/library.make
+
+before-all:: $(FFI_DEPS)
+
+after-clean:: $(FFI_CLEAN)
+
 else  # Mac OS X
 libobjcl_OBJ_FILES = $(patsubst %.m,obj/%.o,$(libobjcl_OBJC_FILES))
 
 all: obj/libobjcl.dylib
 
-clean:
+clean: $(FFI_CLEAN)
 	rm -f obj/libobjcl.dylib obj/libobjcl.dylib.$(VERSION) $(libobjcl_OBJ_FILES)
 
-obj/libobjcl.dylib: obj/libobjcl.dylib.$(VERSION)
+obj/libobjcl.dylib: $(FFI_DEPS) obj/libobjcl.dylib.$(VERSION)
 	ln -s libobjcl.dylib.$(VERSION) $@
 
 obj/libobjcl.dylib.$(VERSION): $(libobjcl_OBJ_FILES)
@@ -57,3 +64,8 @@ obj/%.o: %.m
 	gcc -o $@ -c $< -MMD -MP -DNeXT_Foundation_LIBRARY=1 -DNeXT_GUI_LIBRARY=1 -DNeXT_RUNTIME=1 -dynamic -fno-common -fno-omit-frame-pointer -Wno-import -fno-strict-aliasing -fnext-runtime -I. $(ADDITIONAL_OBJCFLAGS)
 endif
 
+../libffi/.libs/libffi.a:
+	(cd ../libffi && sh ./configure && make)
+
+libffi_clean:
+	-make -C ../libffi distclean
diff --git a/objective-cl.asd b/objective-cl.asd
index f399aa9..859c10f 100644
--- a/objective-cl.asd
+++ b/objective-cl.asd
@@ -93,7 +93,8 @@
                     (mapcan #'(lambda (x)
                                 (directory (merge-pathnames x source-dir)))
                             '(#p"**/*.m" #p"**/*.h" #p"**/GNUmakefile.*"
-                              #p"**/*.make" #p"**/GNUmakefile"))))
+                              #p"**/*.make" #p"**/GNUmakefile"
+                              #p"libffi/**/*" #p"libffi/**/*.*"))))
            (output-dir
             (merge-pathnames #p"../../"
                              (directory-namestring (first (output-files o c))))))
@@ -104,15 +105,17 @@
           (unless (and (probe-file output-file)
                        (= (file-write-date source-file)
                           (file-write-date output-file)))
-            (with-open-file (in source-file
-                                :element-type '(unsigned-byte 8))
-              (with-open-file (out output-file
-                                   :direction :output
-                                   :if-exists :supersede
-                                   :element-type '(unsigned-byte 8))
-                (loop for byte = (read-byte in nil nil)
-                      while byte
-                      do (write-byte byte out))))))))))
+            (ignore-errors  ;; FIXME: We need to skip directories, so
+                            ;; that IGNORE-ERRORS can go away.
+              (with-open-file (in source-file
+                                  :element-type '(unsigned-byte 8))
+                (with-open-file (out output-file
+                                     :direction :output
+                                     :if-exists :supersede
+                                     :element-type '(unsigned-byte 8))
+                  (loop for byte = (read-byte in nil nil)
+                        while byte
+                        do (write-byte byte out)))))))))))
 
 (defmethod perform ((o compile-op) (c objc-source-file))
   (unless (or (operation-done-p o c)
-- 
cgit v1.2.3