Allow itensor's diff to work on lists
[maxima.git] / configure.lisp
blob243e5e666a9d01533350f296bd5e142bfce6f01f
1 (defun replace-substring (in-string old new)
2 (let ((result ""))
3 (do ((begin 0)
4 (end (search old in-string)
5 (search old in-string :start2 begin)))
6 ((>= begin (length in-string)) 'done)
7 (if end
8 (progn (setf result (concatenate 'string result
9 (subseq in-string begin end)
10 new))
11 (setf begin (+ end (length old))))
12 (progn (setf result (concatenate 'string result
13 (subseq in-string begin
14 (length in-string))))
15 (setf begin (length in-string)))))
16 result))
18 (defun process-file (in-filename out-filename substitutions)
19 (with-open-file (in in-filename :direction :input)
20 (with-open-file (out out-filename :direction :output
21 :if-exists :supersede)
22 (do ((line (read-line in nil 'eof)
23 (read-line in nil 'eof)))
24 ((eql line 'eof))
25 (mapc #'(lambda (pair)
26 (setf line (replace-substring line
27 (first pair)
28 (rest pair))))
29 substitutions)
30 (format out "~a~%" line)))))
32 (defun read-with-default (prompt default)
33 (format t "~a [~a]: " prompt default)
34 (terpri)
35 (let ((response (read-line)))
36 (if (string= response "") default response)))
39 ;;; This function (only) modified from CLOCC http://clocc.sourceforge.net
40 (defun default-directory-string ()
41 (string-right-trim
42 "\\" (string-right-trim
43 "/"
44 (namestring
45 #+allegro (excl:current-directory)
46 #+clisp (#+lisp=cl ext:default-directory
47 #-lisp=cl lisp:default-directory)
48 #+cmu (ext:default-directory)
49 #+scl (unix-namestring (ext:default-directory))
50 #+cormanlisp (ccl:get-current-directory)
51 #+lispworks (hcl:get-working-directory)
52 #+lucid (lcl:working-directory)
53 #-(or allegro clisp cmu scl cormanlisp lispworks lucid)
54 (truename ".")))))
56 (defun get-version ()
57 (with-open-file (in "configure.ac" :direction :input)
58 (do ((line (read-line in nil 'eof)
59 (read-line in nil 'eof))
60 (version "")
61 temp)
62 ((eq line 'eof)
63 (when (string= version "")
64 (format t "WARNING: No version information found.~%~%"))
65 version)
66 (when (search "AC_INIT([maxima]," line)
67 #+openmcl (setq line (string-trim '(#\Return) line))
68 (setq temp
69 (replace-substring line "AC_INIT([maxima], [" ""))
70 (setq version
71 (replace-substring temp "])" ""))
72 (when (or (string= temp line)
73 (string= temp version))
74 ; Failed substitution
75 (format t "WARNING: Problem parsing version information. ")
76 (format t "Found: \"~a\"~%~%" version))))))
78 (defvar *maxima-lispname* #+clisp "clisp"
79 #+cmu "cmucl"
80 #+scl "scl"
81 #+sbcl "sbcl"
82 #+gcl "gcl"
83 #+allegro "acl"
84 #+openmcl "openmcl"
85 #+abcl "abcl"
86 #+ecl "ecl"
87 #-(or clisp cmu scl sbcl gcl allegro openmcl abcl ecl) "unknownlisp")
89 (defun configure (&key (interactive t) (verbose nil)
90 is-win32
91 maxima-directory
92 posix-shell
93 clisp-name
94 cmucl-name
95 scl-name
96 acl-name
97 openmcl-name
98 sbcl-name
99 ecl-name)
100 (let ((prefix (if maxima-directory
101 maxima-directory
102 (default-directory-string)))
103 (win32-string (if is-win32 "true" "false"))
104 (shell (if posix-shell posix-shell "/bin/sh"))
105 (clisp (if clisp-name clisp-name "clisp"))
106 (cmucl (if cmucl-name cmucl-name "lisp"))
107 (scl (if scl-name scl-name "lisp"))
108 (acl (if acl-name acl-name "acl"))
109 (openmcl (if openmcl-name openmcl-name "mcl"))
110 (sbcl (if sbcl-name sbcl-name "sbcl"))
111 (ecl (if ecl-name ecl-name "ecl"))
112 (files (list "maxima-local.in" "src/maxima.in" "src/maxima.bat.in"
113 "src/autoconf-variables.lisp.in"))
114 (substitutions))
115 (if interactive
116 (progn
117 (setf prefix (read-with-default "Enter the Maxima directory" prefix))
118 (setf win32-string
119 (read-with-default "Is this a Windows system? (true/false)"
120 win32-string))
121 (setf shell (read-with-default "Posix shell (optional)" shell))
122 (setf clisp
123 (read-with-default "Name of the Clisp executable (optional)"
124 clisp))
125 (setf cmucl
126 (read-with-default "Name of the CMUCL executable (optional)"
127 cmucl))
128 (setf scl
129 (read-with-default "Name of the SCL executable (optional)"
130 scl))
131 (setf acl
132 (read-with-default "Name of the Allegro executable (optional)"
133 acl))
134 (setf openmcl
135 (read-with-default "Name of the OpenMCL executable (optional)"
136 openmcl))
137 (setf ecl
138 (read-with-default "Name of the ECL executable (optional)"
139 ecl))
140 (setf sbcl
141 (read-with-default "Name of the SBCL executable (optional)"
142 sbcl))))
143 (setf substitutions (list (cons "@prefix@"
144 (replace-substring prefix "\\" "\\\\"))
145 (cons "@PACKAGE@" "maxima")
146 (cons "@VERSION@" (get-version))
147 (cons "@host@" "unknown")
148 (cons "@win32@" win32-string)
149 (cons "@default_layout_autotools@" "false")
150 (cons "@POSIX_SHELL@" shell)
151 (cons "@expanded_top_srcdir@"
152 (replace-substring prefix "\\" "\\\\"))
153 (cons "@DEFAULTLISP@" *maxima-lispname*)
154 (cons "@CLISP_NAME@" clisp)
155 (cons "@CMUCL_NAME@" cmucl)
156 (cons "@SCL_NAME@" scl)
157 (cons "@ACL_NAME@" acl)
158 (cons "@OPENMCL_NAME@" openmcl)
159 (cons "@ECL_NAME@" ecl)
160 (cons "@SBCL_NAME@" sbcl)))
161 (if verbose
162 (mapc #'(lambda (pair) (format t "~a=~a~%" (first pair) (rest pair)))
163 substitutions))
164 (mapc #'(lambda (filename)
165 (let ((out-filename (replace-substring filename ".in" "")))
166 (process-file filename out-filename substitutions)
167 (format t "Created ~a~%" out-filename)))
168 files)))