X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcold%2Fshared.lisp;h=b92bc79690a96eb88ebc0c181b174a47a7820483;hb=89a02d3ba803a1d85d745e22b4ac05ef8cb12370;hp=7a77c6d338cf02eb0995aadb896f1e8c11626bf7;hpb=4898ef32c639b1c7f4ee13a5ba566ce6debd03e6;p=sbcl.git diff --git a/src/cold/shared.lisp b/src/cold/shared.lisp index 7a77c6d..b92bc79 100644 --- a/src/cold/shared.lisp +++ b/src/cold/shared.lisp @@ -33,29 +33,20 @@ (defvar *host-obj-prefix*) (defvar *target-obj-prefix*) -;;; suffixes for filename stems when cross-compiling -(defvar *host-obj-suffix* - (or - ;; On some xc hosts, it's impossible to LOAD a fasl file unless it - ;; has the same extension that the host uses for COMPILE-FILE - ;; output, so we have to be careful to use the xc host's preferred - ;; extension. - ;; - ;; FIXME: This is a little ugly and annoying to maintain. And - ;; there's very likely some way to rearrange the build process so - ;; that we never explicitly refer to host object file suffixes, - ;; only to the result of CL:COMPILE-FILE-PATHNAME. - #+lispworks ".ufsl" ; as per Lieven Marchand sbcl-devel 2002-02-01 - #+(and openmcl (not darwin)) ".pfsl" - #+(and openmcl darwin) ".dfsl" - ;; On most xc hosts, any old extension works, so we use an - ;; arbitrary one. - ".lisp-obj")) (defvar *target-obj-suffix* ;; Target fasl files are LOADed (actually only quasi-LOADed, in ;; GENESIS) only by SBCL code, and it doesn't care about particular ;; extensions, so we can use something arbitrary. ".lisp-obj") +(defvar *target-assem-obj-suffix* + ;; Target fasl files from SB!C:ASSEMBLE-FILE are LOADed via GENESIS. + ;; The source files are compiled once as assembly files and once as + ;; normal lisp files. In the past, they were kept separate by + ;; clever symlinking in the source tree, but that became less clean + ;; as ports to host environments without symlinks started appearing. + ;; In order to keep them separate, we have the assembled versions + ;; with a separate suffix. + ".assem-obj") ;;; a function of one functional argument, which calls its functional argument ;;; in an environment suitable for compiling the target. (This environment @@ -101,135 +92,6 @@ (rename-file x path))) (compile 'rename-file-a-la-unix) -;;; a wrapper for compilation/assembly, used mostly to centralize -;;; the procedure for finding full filenames from "stems" -;;; -;;; Compile the source file whose basic name is STEM, using some -;;; standard-for-the-SBCL-build-process procedures to generate the -;;; full pathnames of source file and object file. Return the pathname -;;; of the object file for STEM. Several &KEY arguments are accepted: -;;; :SRC-PREFIX, :SRC-SUFFIX = -;;; strings to be concatenated to STEM to produce source filename -;;; :OBJ-PREFIX, :OBJ-SUFFIX = -;;; strings to be concatenated to STEM to produce object filename -;;; :TMP-OBJ-SUFFIX-SUFFIX = -;;; string to be appended to the name of an object file to produce -;;; the name of a temporary object file -;;; :COMPILE-FILE, :IGNORE-FAILURE-P = -;;; :COMPILE-FILE is a function to use for compiling the file -;;; (with the same calling conventions as ANSI CL:COMPILE-FILE). -;;; If the third return value (FAILURE-P) of this function is -;;; true, a continuable error will be signalled, unless -;;; :IGNORE-FAILURE-P is set, in which case only a warning will be -;;; signalled. -(defun compile-stem (stem - &key - (obj-prefix "") - (obj-suffix (error "missing OBJ-SUFFIX")) - (tmp-obj-suffix-suffix "-tmp") - (src-prefix "") - (src-suffix ".lisp") - (compile-file #'compile-file) - trace-file - ignore-failure-p) - - (declare (type function compile-file)) - - (let* (;; KLUDGE: Note that this CONCATENATE 'STRING stuff is not The Common - ;; Lisp Way, although it works just fine for common UNIX environments. - ;; Should it come to pass that the system is ported to environments - ;; where version numbers and so forth become an issue, it might become - ;; urgent to rewrite this using the fancy Common Lisp PATHNAME - ;; machinery instead of just using strings. In the absence of such a - ;; port, it might or might be a good idea to do the rewrite. - ;; -- WHN 19990815 - (src (concatenate 'string src-prefix stem src-suffix)) - (obj (concatenate 'string obj-prefix stem obj-suffix)) - (tmp-obj (concatenate 'string obj tmp-obj-suffix-suffix))) - - (ensure-directories-exist obj :verbose t) - - ;; We're about to set about building a new object file. First, we - ;; delete any preexisting object file in order to avoid confusing - ;; ourselves later should we happen to bail out of compilation - ;; with an error. - (when (probe-file obj) - (delete-file obj)) - - ;; Original comment: - ;; - ;; Work around a bug in CLISP 1999-01-08 #'COMPILE-FILE: CLISP - ;; mangles relative pathnames passed as :OUTPUT-FILE arguments, - ;; but works OK with absolute pathnames. - ;; - ;; following discussion on cmucl-imp 2002-07 - ;; "COMPILE-FILE-PATHNAME", it would seem safer to deal with - ;; absolute pathnames all the time; it is no longer clear that the - ;; original behaviour in CLISP was wrong or that the current - ;; behaviour is right; and in any case absolutifying the pathname - ;; insulates us against changes of behaviour. -- CSR, 2002-08-09 - (setf tmp-obj - ;; (Note that this idiom is taken from the ANSI - ;; documentation for TRUENAME.) - (with-open-file (stream tmp-obj - :direction :output - ;; Compilation would overwrite the - ;; temporary object anyway and overly - ;; strict implementations default - ;; to :ERROR. - :if-exists :supersede) - (close stream) - (truename stream))) - ;; and some compilers (e.g. OpenMCL) will complain if they're - ;; asked to write over a file that exists already (and isn't - ;; recognizeably a fasl file), so - (when (probe-file tmp-obj) - (delete-file tmp-obj)) - - ;; Try to use the compiler to generate a new temporary object file. - (flet ((report-recompile-restart (stream) - (format stream "Recompile file ~S" src)) - (report-continue-restart (stream) - (format stream "Continue, using possibly bogus file ~S" obj))) - (tagbody - retry-compile-file - (multiple-value-bind (output-truename warnings-p failure-p) - (if trace-file - (funcall compile-file src :output-file tmp-obj - :trace-file t) - (funcall compile-file src :output-file tmp-obj )) - (declare (ignore warnings-p)) - (cond ((not output-truename) - (error "couldn't compile ~S" src)) - (failure-p - (if ignore-failure-p - (warn "ignoring FAILURE-P return value from compilation of ~S" - src) - (unwind-protect - (restart-case - (error "FAILURE-P was set when creating ~S." - obj) - (recompile () - :report report-recompile-restart - (go retry-compile-file)) - (continue () - :report report-continue-restart - (setf failure-p nil))) - ;; Don't leave failed object files lying around. - (when (and failure-p (probe-file tmp-obj)) - (delete-file tmp-obj) - (format t "~&deleted ~S~%" tmp-obj))))) - ;; Otherwise: success, just fall through. - (t nil))))) - - ;; If we get to here, compilation succeeded, so it's OK to rename - ;; the temporary output file to the permanent object file. - (rename-file-a-la-unix tmp-obj obj) - - ;; nice friendly traditional return value - (pathname obj))) -(compile 'compile-stem) - ;;; other miscellaneous tools (load "src/cold/read-from-file.lisp") (load "src/cold/rename-package-carefully.lisp") @@ -251,7 +113,7 @@ (setf *shebang-features* (let* ((default-features (append (read-from-file "base-target-features.lisp-expr") - (read-from-file "local-target-features.lisp-expr"))) + (eval (read-from-file "local-target-features.lisp-expr")))) (customizer-file-name "customize-target-features.lisp") (customizer (if (probe-file customizer-file-name) (compile nil @@ -334,12 +196,66 @@ (,flags (rest ,stem-and-flags))) ,@body)))) +;;; Given a STEM, remap the path component "/target/" to a suitable +;;; target directory. +(defun stem-remap-target (stem) + (let ((position (search "/target/" stem))) + (if position + (concatenate 'string + (subseq stem 0 (1+ position)) + #!+x86 "x86" + #!+x86-64 "x86-64" + #!+sparc "sparc" + #!+ppc "ppc" + #!+mips "mips" + #!+alpha "alpha" + #!+hppa "hppa" + (subseq stem (+ position 7))) + stem))) +(compile 'stem-remap-target) + +;;; Determine the source path for a stem. +(defun stem-source-path (stem) + (concatenate 'string "" (stem-remap-target stem) ".lisp")) +(compile 'stem-source-path) + +;;; Determine the object path for a stem/flags/mode combination. +(defun stem-object-path (stem flags mode) + (multiple-value-bind + (obj-prefix obj-suffix) + (ecase mode + (:host-compile + ;; On some xc hosts, it's impossible to LOAD a fasl file unless it + ;; has the same extension that the host uses for COMPILE-FILE + ;; output, so we have to be careful to use the xc host's preferred + ;; extension. + (values *host-obj-prefix* + (concatenate 'string "." + (pathname-type (compile-file-pathname stem))))) + (:target-compile (values *target-obj-prefix* + (if (find :assem flags) + *target-assem-obj-suffix* + *target-obj-suffix*)))) + (concatenate 'string obj-prefix (stem-remap-target stem) obj-suffix))) +(compile 'stem-object-path) + ;;; Check for stupid typos in FLAGS list keywords. (let ((stems (make-hash-table :test 'equal))) (do-stems-and-flags (stem flags) - (if (gethash stem stems) - (error "duplicate stem ~S in *STEMS-AND-FLAGS*" stem) - (setf (gethash stem stems) t)) + ;; We do duplicate stem comparison based on the object path in + ;; order to cover the case of stems with an :assem flag, which + ;; have two entries but separate object paths for each. KLUDGE: + ;; We have to bind *target-obj-prefix* here because it's normally + ;; set up later in the build process and we don't actually care + ;; what it is so long as it doesn't change while we're checking + ;; for duplicate stems. + (let* ((*target-obj-prefix* "") + (object-path (stem-object-path stem flags :target-compile))) + (if (gethash object-path stems) + (error "duplicate stem ~S in *STEMS-AND-FLAGS*" stem) + (setf (gethash object-path stems) t))) + ;; FIXME: We should make sure that the :assem flag is only used + ;; when paired with :not-host. (let ((set-difference (set-difference flags *expected-stem-flags*))) (when set-difference (error "found unexpected flag(s) in *STEMS-AND-FLAGS*: ~S" @@ -347,6 +263,122 @@ ;;;; tools to compile SBCL sources to create the cross-compiler +;;; a wrapper for compilation/assembly, used mostly to centralize +;;; the procedure for finding full filenames from "stems" +;;; +;;; Compile the source file whose basic name is STEM, using some +;;; standard-for-the-SBCL-build-process procedures to generate the +;;; full pathnames of source file and object file. Return the pathname +;;; of the object file for STEM. +;;; +;;; STEM and FLAGS are as per DO-STEMS-AND-FLAGS. MODE is one of +;;; :HOST-COMPILE and :TARGET-COMPILE. +(defun compile-stem (stem flags mode) + + (let* (;; KLUDGE: Note that this CONCATENATE 'STRING stuff is not The Common + ;; Lisp Way, although it works just fine for common UNIX environments. + ;; Should it come to pass that the system is ported to environments + ;; where version numbers and so forth become an issue, it might become + ;; urgent to rewrite this using the fancy Common Lisp PATHNAME + ;; machinery instead of just using strings. In the absence of such a + ;; port, it might or might be a good idea to do the rewrite. + ;; -- WHN 19990815 + (src (stem-source-path stem)) + (obj (stem-object-path stem flags mode)) + (tmp-obj (concatenate 'string obj "-tmp")) + + (compile-file (ecase mode + (:host-compile #'compile-file) + (:target-compile (if (find :assem flags) + *target-assemble-file* + *target-compile-file*)))) + (trace-file (find :trace-file flags)) + (ignore-failure-p (find :ignore-failure-p flags))) + (declare (type function compile-file)) + + (ensure-directories-exist obj :verbose t) + + ;; We're about to set about building a new object file. First, we + ;; delete any preexisting object file in order to avoid confusing + ;; ourselves later should we happen to bail out of compilation + ;; with an error. + (when (probe-file obj) + (delete-file obj)) + + ;; Original comment: + ;; + ;; Work around a bug in CLISP 1999-01-08 #'COMPILE-FILE: CLISP + ;; mangles relative pathnames passed as :OUTPUT-FILE arguments, + ;; but works OK with absolute pathnames. + ;; + ;; following discussion on cmucl-imp 2002-07 + ;; "COMPILE-FILE-PATHNAME", it would seem safer to deal with + ;; absolute pathnames all the time; it is no longer clear that the + ;; original behaviour in CLISP was wrong or that the current + ;; behaviour is right; and in any case absolutifying the pathname + ;; insulates us against changes of behaviour. -- CSR, 2002-08-09 + (setf tmp-obj + ;; (Note that this idiom is taken from the ANSI + ;; documentation for TRUENAME.) + (with-open-file (stream tmp-obj + :direction :output + ;; Compilation would overwrite the + ;; temporary object anyway and overly + ;; strict implementations default + ;; to :ERROR. + :if-exists :supersede) + (close stream) + (truename stream))) + ;; and some compilers (e.g. OpenMCL) will complain if they're + ;; asked to write over a file that exists already (and isn't + ;; recognizeably a fasl file), so + (when (probe-file tmp-obj) + (delete-file tmp-obj)) + + ;; Try to use the compiler to generate a new temporary object file. + (flet ((report-recompile-restart (stream) + (format stream "Recompile file ~S" src)) + (report-continue-restart (stream) + (format stream "Continue, using possibly bogus file ~S" obj))) + (tagbody + retry-compile-file + (multiple-value-bind (output-truename warnings-p failure-p) + (if trace-file + (funcall compile-file src :output-file tmp-obj + :trace-file t) + (funcall compile-file src :output-file tmp-obj )) + (declare (ignore warnings-p)) + (cond ((not output-truename) + (error "couldn't compile ~S" src)) + (failure-p + (if ignore-failure-p + (warn "ignoring FAILURE-P return value from compilation of ~S" + src) + (unwind-protect + (restart-case + (error "FAILURE-P was set when creating ~S." + obj) + (recompile () + :report report-recompile-restart + (go retry-compile-file)) + (continue () + :report report-continue-restart + (setf failure-p nil))) + ;; Don't leave failed object files lying around. + (when (and failure-p (probe-file tmp-obj)) + (delete-file tmp-obj) + (format t "~&deleted ~S~%" tmp-obj))))) + ;; Otherwise: success, just fall through. + (t nil))))) + + ;; If we get to here, compilation succeeded, so it's OK to rename + ;; the temporary output file to the permanent object file. + (rename-file-a-la-unix tmp-obj obj) + + ;; nice friendly traditional return value + (pathname obj))) +(compile 'compile-stem) + ;;; Execute function FN in an environment appropriate for compiling the ;;; cross-compiler's source code in the cross-compilation host. (defun in-host-compilation-mode (fn) @@ -364,26 +396,16 @@ ;;; Process a file as source code for the cross-compiler, compiling it ;;; (if necessary) in the appropriate environment, then loading it ;;; into the cross-compilation host Common lisp. -(defun host-cload-stem (stem &key ignore-failure-p) +(defun host-cload-stem (stem flags) (let ((compiled-filename (in-host-compilation-mode (lambda () - (compile-stem - stem - :obj-prefix *host-obj-prefix* - :obj-suffix *host-obj-suffix* - :compile-file #'cl:compile-file - :ignore-failure-p ignore-failure-p))))) + (compile-stem stem flags :host-compile))))) (load compiled-filename))) (compile 'host-cload-stem) ;;; like HOST-CLOAD-STEM, except that we don't bother to compile -(defun host-load-stem (stem &key ignore-failure-p) - (declare (ignore ignore-failure-p)) ; (It's only relevant when - ;; compiling.) KLUDGE: It's untidy to have the knowledge of how to - ;; construct complete filenames from stems in here as well as in - ;; COMPILE-STEM. It should probably be factored out somehow. -- WHN - ;; 19990815 - (load (concatenate 'simple-string *host-obj-prefix* stem *host-obj-suffix*))) +(defun host-load-stem (stem flags) + (load (stem-object-path stem flags :host-compile))) (compile 'host-load-stem) ;;;; tools to compile SBCL sources to create object files which will @@ -391,17 +413,10 @@ ;;; Run the cross-compiler on a file in the source directory tree to ;;; produce a corresponding file in the target object directory tree. -(defun target-compile-stem (stem &key assem-p ignore-failure-p trace-file) +(defun target-compile-stem (stem flags) (funcall *in-target-compilation-mode-fn* (lambda () - (compile-stem stem - :obj-prefix *target-obj-prefix* - :obj-suffix *target-obj-suffix* - :trace-file trace-file - :ignore-failure-p ignore-failure-p - :compile-file (if assem-p - *target-assemble-file* - *target-compile-file*))))) + (compile-stem stem flags :target-compile)))) (compile 'target-compile-stem) ;;; (This function is not used by the build process, but is intended