Description: Handle multiple LDFLAGS
 Without this patch, building with LDFLAGS containing more than one flag results 
 in flags being dropped.
Author: Graham Inggs <ginggs@debian.org>
Bug-Debian: http://bugs.debian.org/847925

--- a/src/maxima.system
+++ b/src/maxima.system
@@ -58,6 +58,19 @@
     (and (apply #'compile-file file :output-file object-output args)
 	 (c:build-fasl output :lisp-files (list object-output)))))
 
+(defun split-string (string &key (item #\space) (test #'char=))
+  ;; Splits the string into substrings at spaces.
+  (let ((len (length string))
+	(index 0) result)
+    (dotimes (i len
+		(progn (unless (= index len)
+			 (push (subseq string index) result))
+		       (reverse result)))
+      (when (funcall test (char string i) item)
+	(unless (= index i);; two spaces in a row
+	  (push (subseq string index i) result))
+	(setf index (1+ i))))))
+
 #+ecl
 (defun build-maxima-lib ()
   (labels ((list-all-objects (module)
@@ -79,12 +92,12 @@
 			  :ld-flags
 			  (let ((x (symbol-value (find-symbol "*AUTOCONF-LD-FLAGS*"
 							      (find-package "MAXIMA")))))
-			    (if (and x (not (string= x ""))) (list x))))
+			    (if (and x (not (string= x ""))) (split-string x))))
 	(c::build-program "binary-ecl/maxima" :lisp-files obj
 			  :ld-flags
 			  (let ((x (symbol-value (find-symbol "*AUTOCONF-LD-FLAGS*"
 							      (find-package "MAXIMA")))))
-			    (if (and x (not (string= x ""))) (list x)))
+			    (if (and x (not (string= x ""))) (split-string x)))
 			  :epilogue-code '(progn (cl-user::run)))))))
 
 (defun maxima-binary-pathname ()
