Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View libgcrypt.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
require 'formula'
 
class Libgcrypt < Formula
homepage 'http://gnupg.org/'
url 'ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.5.0.tar.bz2'
sha1 '3e776d44375dc1a710560b98ae8437d5da6e32cf'
 
depends_on 'libgpg-error'
 
option :universal
 
def patches
if ENV.compiler == :clang
{:p0 =>
"https://trac.macports.org/export/85232/trunk/dports/devel/libgcrypt/files/clang-asm.patch"}
end
end
 
def cflags
cflags = ENV.cflags.to_s
cflags += ' -std=gnu89 -fheinous-gnu-extensions' if ENV.compiler == :clang
cflags
end
 
def install
ENV.universal_binary if build.universal?
 
ENV.macosxsdk "10.8"
ENV.remove_from_cflags(/ ?-mmacosx-version-min=10\.\d/)
ENV['MACOSX_DEPLOYMENT_TARGET'] = "10.6"
ENV.append_to_cflags("-mmacosx-version-min=10.6")
 
ENV.append_to_cflags("-D_FORTIFY_SOURCE=2")
ENV.append_to_cflags("-fstack-protector-all")
ENV.append_to_cflags("-arch i386 -arch x86_64")
 
system "./configure", "--disable-dependency-tracking",
"--prefix=#{prefix}",
"--disable-asm",
"--with-gpg-error-prefix=#{HOMEBREW_PREFIX}"
# Parallel builds work, but only when run as separate steps
if build.universal?
system "curl 'https://trac.macports.org/export/56608/trunk/dports/devel/libgcrypt/files/config.h.ed' | ed - config.h"
end
 
system "make", "CFLAGS=#{cflags}"
system "make check"
system "make install"
end
 
test do
(testpath/'test.c').write <<-EOS.undent
#include <gcrypt.h>
int main(void)
{
gcry_error_t err;
if(!gcry_check_version(GCRYPT_VERSION)) {
exit(2);
}
gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
gcry_sexp_t key, parms, privkey;
static const char *parmstr = "(genkey (dsa (nbits 4:1024)))";
err = gcry_sexp_new(&parms, parmstr, strlen(parmstr), 0);
if (err) return err;
err = gcry_pk_genkey(&key, parms);
if (err) return err;
gcry_sexp_release(parms);
privkey = gcry_sexp_find_token(key, "private-key", 0);
gcry_sexp_release(key);
return 0;
}
EOS
 
ENV.macosxsdk "10.8"
ENV.remove_from_cflags(/ ?-mmacosx-version-min=10\.\d/)
ENV['MACOSX_DEPLOYMENT_TARGET'] = "10.6"
ENV.append_to_cflags("-mmacosx-version-min=10.6")
 
flags = *`#{bin}/libgcrypt-config --cflags --libs`.split
flags += ENV.cflags.split
flags.delete("-arch=x86")
flags.delete("-march=native")
flags << "-arch x86_64"
system ENV.cc, "-o", "test", "test.c", *flags
system "./test"
 
flags.delete("-arch x86_64")
flags << "-arch i386"
flags << "-m32"
system ENV.cc, "-o", "test", "test.c", *flags
 
system "arch", "-i386", "./test"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.