1.0.28.44: better MACHINE-VERSION answers on BSD'ish platforms
[sbcl.git] / src / code / linux-os.lisp
index 134ca54..2efe31b 100644 (file)
 ;;; Return the system page size.
 (defun get-page-size ()
   sb!c:*backend-page-bytes*)
+
+;;; support for CL:MACHINE-VERSION defined OAOO elsewhere
+(defun get-machine-version ()
+  (or
+   #!+(and mips little-endian)
+   "little-endian"
+   #!+(and mips big-endian)
+   "big-endian"
+   (let ((marker
+          ;; hoping "cpu" exists and gives something useful in
+          ;; all relevant Linuxen...
+          ;;
+          ;; from Lars Brinkhoff sbcl-devel 26 Jun 2003:
+          ;;   I examined different versions of Linux/PPC at
+          ;;   http://lxr.linux.no/ (the file that outputs
+          ;;   /proc/cpuinfo is arch/ppc/kernel/setup.c, if
+          ;;   you want to check), and all except 2.0.x
+          ;;   seemed to do the same thing as far as the
+          ;;   "cpu" field is concerned, i.e. it always
+          ;;   starts with the (C-syntax) string "cpu\t\t: ".
+          #!+ppc "cpu"
+          ;; The field "model name" exists on kernel 2.4.21-rc6-ac1
+          ;; anyway, with values e.g.
+          ;;   "AMD Athlon(TM) XP 2000+"
+          ;;   "Intel(R) Pentium(R) M processor 1300MHz"
+          ;; which seem comparable to the information in the example
+          ;; in the MACHINE-VERSION page of the ANSI spec.
+          #!+(or x86 x86-64) "model name"))
+     (when marker
+       (with-open-file (stream "/proc/cpuinfo"
+                               ;; Even on Linux it's an option to build
+                               ;; kernels without /proc filesystems, so
+                               ;; degrade gracefully.
+                               :if-does-not-exist nil)
+         (loop with line while (setf line (read-line stream nil))
+               when (eql (search marker line) 0)
+               return (string-trim " " (subseq line (1+ (position #\: line))))))))))