Skip to content

Commit

Permalink
grovel: rename pkg-config to pkg-config-cflags
Browse files Browse the repository at this point in the history
Also, by default failure to execute pkg-config is fatal and it takes a
single pkg rather than a list.
  • Loading branch information
luismbo committed Nov 28, 2014
1 parent 4101620 commit 5b40937
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
21 changes: 12 additions & 9 deletions doc/cffi-manual.texinfo
Expand Up @@ -6489,15 +6489,18 @@ Adds @var{cc-flags} to the command line arguments used for the C compiler
invocation.
@end deffn

@deffn {Grovel Form} pkg-flags &rest pkgs

Adds @var{pkgs} to the command line arguments for the external program
pkg-config and runs it to retrieve the relevant include flags used for the
C compiler invocation. This syntax can be used instead of hard-coding
paths using @code{cc-flags}, and ensures that include flags are added
correctly on the build system. Assumes pkg-config is installed and working.
@var{pkgs} are strings that identify installed pkg-config packages. See
the pkg-config manual for more information.
@deffn {Grovel Form} pkg-config-cflags pkg &key optional

Adds @var{pkg} to the command line arguments for the external program
@code{pkg-config} and runs it to retrieve the relevant include flags
used for the C compiler invocation. This syntax can be used instead of
hard-coding paths using @code{cc-flags}, and ensures that include
flags are added correctly on the build system. Assumes
@code{pkg-config} is installed and working. @var{pkg} is a string
that identifies an installed @code{pkg-config} package. See the
pkg-config manual for more information. If @var{optional} is true,
failure to execute @code{pkg-config} does @emph{not} abort
compilation.
@end deffn

@deffn {Grovel Form} cstruct lisp-name c-name slots
Expand Down
17 changes: 9 additions & 8 deletions grovel/grovel.lisp
Expand Up @@ -334,15 +334,16 @@ int main(int argc, char**argv) {
(define-grovel-syntax cc-flags (&rest flags)
(appendf *cc-flags* (trim-whitespace flags)))

(define-grovel-syntax pkg-flags (&rest pkgs)
(handler-case
(define-grovel-syntax pkg-config-cflags (pkg &key optional)
(block nil
(handler-bind
((error (lambda (e)
(when optional
(format *debug-io* "~&ERROR: ~a" e)
(format *debug-io* "~&Attempting to continue anyway.~%")
(return)))))
(appendf *cc-flags*
(trim-whitespace (mapcar #'(lambda (p)
(invoke "pkg-config" p "--cflags"))
(trim-whitespace pkgs))))
(error (e)
(format *debug-io* "~&ERROR: ~a" e)
(format *debug-io* "~&Attempting to continue anyway.~%"))))
(trim-whitespace (list (invoke "pkg-config" pkg "--cflags")))))))

;;; This form also has some "read time" effects. See GENERATE-C-FILE.
(define-grovel-syntax in-package (name)
Expand Down
3 changes: 1 addition & 2 deletions libffi/libffi-unix.lisp
Expand Up @@ -38,8 +38,7 @@
#+openbsd
(cc-flags "-I/usr/local/include")

#+linux
(pkg-flags "libffi")
(pkg-config-cflags "libffi" :optional t)

#+darwin
(include "ffi/ffi.h")
Expand Down

0 comments on commit 5b40937

Please sign in to comment.