Skip to content

Commit

Permalink
Make an effort at automatically determining the Python include dir
Browse files Browse the repository at this point in the history
Ignore-this: 9a23e3f1b51804aab62d6cf3222840a0

darcs-hash:20111120043015-0344a-37614883556edbcf451effdc289b310c0a77b50a.gz
  • Loading branch information
pinterface committed Nov 20, 2011
1 parent a014960 commit b10e1cf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
17 changes: 10 additions & 7 deletions burgled-batteries.asd
Expand Up @@ -17,7 +17,8 @@
(in-package #:burgled-batteries-system)

(defsystem "burgled-batteries"
:depends-on (#:cffi #:alexandria #:parse-declarations-1.0 #:trivial-garbage)
:depends-on (#:cffi #:alexandria #:parse-declarations-1.0 #:trivial-garbage
#-burgled-batteries.guess-not-grovel #:cl-fad)
:name "burgled-batteries"
:author (:original "Dmitri Hrapof <hrapof@common-lisp.ru>"
:current "pinterface <pix@kepibu.org>")
Expand All @@ -33,17 +34,19 @@ preference for guessing by evaluating the following form before telling ASDF to
load this system:
(push :burgled-batteries.guess-not-grovel *features*)
If you /would/ like to use the groveller, you may need to edit the .ASD file to
configure the directory where Python header files are located. (My apologies: I
hope for this to be both more easily configurable, and less necessary, in the
future.)
If you /would/ like to use the groveller, B-B will attempt to determine the
location of Python's C header files, and will prompt you to specify the
appropriate directory if one cannot be found. To grovel against a specific
copy of Python's header files, you may need to edit
(defparameter *cpython-include-dir* ...)
in #p\"grovel-include-dir.lisp\".
"
:serial t
:components
((:file "packages")
#-burgled-batteries.guess-not-grovel (:file "grovel-bitfields")
;; FIXME: auto-detect location of Python include directory (or at least make it configurable)
#-burgled-batteries.guess-not-grovel (grovel-file "grovel" :cc-flags ("-I/usr/include/python2.6"))
#-burgled-batteries.guess-not-grovel (:file "grovel-include-dir")
#-burgled-batteries.guess-not-grovel (grovel-file "grovel")
#+burgled-batteries.guess-not-grovel (:file "grovel-guess")
(:file "cffi-output-args")
(:file "ffi-definers")
Expand Down
28 changes: 28 additions & 0 deletions grovel-include-dir.lisp
@@ -0,0 +1,28 @@
(in-package #:cpython)

(defun read-path ()
(format *query-io* "Enter directory containing Python's C header files: ")
(cl:list (read-line *query-io*)))

(defun query-error (format-string &rest args)
(restart-case (apply #'error format-string args)
(use-value (v)
:report "Specify directory containing CPython's header files"
:interactive read-path
v)))

(defun query-user-for-include-dir ()
(loop :for path := (query-error "Unable to determine Python include directory.")
:then (query-error "Path ~s does not appear to exist." path)
:when (cl-fad:directory-exists-p path) :return it))

(defparameter *cpython-include-dir*
(or (loop :for minor :from 7 :downto 4
:when (or (cl-fad:directory-exists-p (format nil "/usr/include/python2.~d" minor))
(cl-fad:directory-exists-p (format nil "/usr/local/include/python2.~d" minor)))
:return it)
;; This allows us to avoid querying the user during a recompile, while
;; still allowing for a change in Python version
(when (boundp '*cpython-include-dir*)
(cl-fad:directory-exists-p *cpython-include-dir*))
(query-user-for-include-dir)))
2 changes: 2 additions & 0 deletions grovel.lisp
@@ -1,5 +1,7 @@
(in-package #:python.cffi)

(cc-flags #.(format nil "-I~A" *cpython-include-dir*))

(include "Python.h")
(include "structmember.h") ; needed for member type flags

Expand Down

0 comments on commit b10e1cf

Please sign in to comment.