X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=contrib%2Fsb-grovel%2Fdef-to-lisp.lisp;h=e1f54f006196283c7df17cdeb53fb1d49b7eb5d9;hb=c27ee1dba86042cb431c298699c19ed3fcd70026;hp=97b524bae89c07ba5258e275b54534cc194fd0e2;hpb=4373334c459af4a06a08db880e613c7aeb4876f7;p=sbcl.git diff --git a/contrib/sb-grovel/def-to-lisp.lisp b/contrib/sb-grovel/def-to-lisp.lisp index 97b524b..e1f54f0 100644 --- a/contrib/sb-grovel/def-to-lisp.lisp +++ b/contrib/sb-grovel/def-to-lisp.lisp @@ -5,7 +5,7 @@ (destructuring-bind (c-name &rest elements) c-struct (format stream "printf(\"(sb-grovel::define-c-struct ~A %d)\\n\",sizeof (~A));~%" lisp-name c-name) (dolist (e elements) - (destructuring-bind (lisp-type lisp-el-name c-type c-el-name) e + (destructuring-bind (lisp-type lisp-el-name c-type c-el-name &key distrust-length) e ;; FIXME: this format string doesn't actually guarantee ;; non-multilined-string-constantness, it just makes it more ;; likely. Sort out the required behaviour (and maybe make @@ -18,8 +18,10 @@ (format stream "{ ~A t;printf(\"%d \",((unsigned long)&(t.~A)) - ((unsigned long)&(t)) ); }~%" c-name c-el-name) ;; length - (format stream "{ ~A t;printf(\"%d\",(sizeof t.~A));}~%" - c-name c-el-name) + (if distrust-length + (format stream "printf(\"|CL|:|NIL|\");") + (format stream "{ ~A t;printf(\"%d\",(sizeof t.~A));}~%" + c-name c-el-name)) (format stream "printf(\")\\n\");~%"))))) (defun c-for-function (stream lisp-name alien-defn) @@ -48,8 +50,12 @@ printf(\"(in-package ~S)\\\n\");~%" package-name) (destructuring-bind (type lispname cname &optional doc) def (cond ((eq type :integer) (format stream - "printf(\"(cl:defconstant ~A %d \\\"~A\\\")\\\n\",~A);~%" - lispname doc cname)) + "#ifdef ~A~%~ + printf(\"(cl:defconstant ~A %d \\\"~A\\\")\\\n\",~A);~%~ + #else~%~ + printf(\"(sb-int:style-warn \\\"Couln't grovel definition for ~A (unknown to the C compiler).\\\")\\n\");~%~ + #endif~%" + cname lispname doc cname cname)) ((eq type :type) (format stream "printf(\"(sb-alien:define-alien-type ~A (sb-alien:%ssigned %d))\\\n\",SIGNED_(~A),8*(sizeof(~A)));~%" @@ -68,7 +74,7 @@ printf(\"(in-package ~S)\\\n\");~%" package-name) (format stream "exit(0);~%}~%"))) (defun c-constants-extract (filename output-file package) - (with-open-file (f output-file :direction :output) + (with-open-file (f output-file :direction :output :if-exists :supersede) (with-open-file (i filename :direction :input) (let* ((headers (read i)) (definitions (read i))) @@ -98,8 +104,12 @@ printf(\"(in-package ~S)\\\n\");~%" package-name) (funcall (intern "C-CONSTANTS-EXTRACT" (find-package "SB-GROVEL")) filename tmp-c-source (constants-package component)) (and - (= (run-shell-command "gcc -o ~S ~S" (namestring tmp-a-dot-out) - (namestring tmp-c-source)) 0) + (= (run-shell-command "gcc ~A -o ~S ~S" + (if (sb-ext:posix-getenv "EXTRA_CFLAGS") + (sb-ext:posix-getenv "EXTRA_CFLAGS") + "") + (namestring tmp-a-dot-out) + (namestring tmp-c-source)) 0) (= (run-shell-command "~A >~A" (namestring tmp-a-dot-out) (namestring tmp-constants)) 0)