2009-10-15 08:07:12 +00:00
|
|
|
require 'formula'
|
2009-09-07 19:22:45 +00:00
|
|
|
|
2011-03-10 05:11:03 +00:00
|
|
|
class Libffi < Formula
|
2010-04-07 05:58:35 +00:00
|
|
|
homepage 'http://sourceware.org/libffi/'
|
2013-03-23 23:29:23 +00:00
|
|
|
url 'http://mirrors.kernel.org/sources.redhat.com/libffi/libffi-3.0.13.tar.gz'
|
|
|
|
mirror 'ftp://sourceware.org/pub/libffi/libffi-3.0.13.tar.gz'
|
|
|
|
sha1 'f5230890dc0be42fb5c58fbf793da253155de106'
|
2010-04-07 05:58:35 +00:00
|
|
|
|
2012-01-08 06:53:17 +00:00
|
|
|
keg_only :provided_by_osx, "Some formulae require a newer version of libffi."
|
|
|
|
|
2009-09-07 19:22:45 +00:00
|
|
|
def install
|
2013-12-14 18:13:11 +00:00
|
|
|
ENV.deparallelize # https://github.com/Homebrew/homebrew/pull/19267
|
2010-08-20 19:43:18 +00:00
|
|
|
ENV.universal_binary
|
2013-03-13 04:31:34 +00:00
|
|
|
system "./configure", "--disable-debug", "--disable-dependency-tracking",
|
|
|
|
"--prefix=#{prefix}"
|
2009-09-07 19:22:45 +00:00
|
|
|
system "make install"
|
|
|
|
end
|
2013-03-13 04:31:34 +00:00
|
|
|
|
|
|
|
test do
|
|
|
|
(testpath/'closure.c').write <<-TEST_SCRIPT.undent
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ffi.h>
|
|
|
|
|
|
|
|
/* Acts like puts with the file given at time of enclosure. */
|
|
|
|
void puts_binding(ffi_cif *cif, unsigned int *ret, void* args[],
|
|
|
|
FILE *stream)
|
|
|
|
{
|
|
|
|
*ret = fputs(*(char **)args[0], stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
ffi_cif cif;
|
|
|
|
ffi_type *args[1];
|
|
|
|
ffi_closure *closure;
|
|
|
|
|
|
|
|
int (*bound_puts)(char *);
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Allocate closure and bound_puts */
|
|
|
|
closure = ffi_closure_alloc(sizeof(ffi_closure), &bound_puts);
|
|
|
|
|
|
|
|
if (closure)
|
|
|
|
{
|
|
|
|
/* Initialize the argument info vectors */
|
|
|
|
args[0] = &ffi_type_pointer;
|
|
|
|
|
|
|
|
/* Initialize the cif */
|
|
|
|
if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
|
|
|
|
&ffi_type_uint, args) == FFI_OK)
|
|
|
|
{
|
|
|
|
/* Initialize the closure, setting stream to stdout */
|
|
|
|
if (ffi_prep_closure_loc(closure, &cif, puts_binding,
|
|
|
|
stdout, bound_puts) == FFI_OK)
|
|
|
|
{
|
|
|
|
rc = bound_puts("Hello World!");
|
|
|
|
/* rc now holds the result of the call to fputs */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Deallocate both closure, and bound_puts */
|
|
|
|
ffi_closure_free(closure);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
TEST_SCRIPT
|
|
|
|
|
2013-03-14 03:38:07 +00:00
|
|
|
ENV['PKG_CONFIG_PATH'] = "#{opt_prefix}/lib/pkgconfig"
|
|
|
|
flags = `pkg-config --cflags --libs libffi`.split + ENV.cflags.split
|
2013-03-13 04:31:34 +00:00
|
|
|
system ENV.cc, "-o", "closure", "closure.c", *flags
|
|
|
|
system "./closure"
|
|
|
|
end
|
2009-09-07 19:22:45 +00:00
|
|
|
end
|