Makefile.PL 2.86 KB
Newer Older
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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
use inc::Module::Install;
use Devel::CheckLib;
use Getopt::Long;
use File::Spec::Functions;

BEGIN {
    if ( $Module::Install::AUTHOR ) {
        use Module::Install::XSUtil;
    }
}

my $headdir;
my $libdir;
my $prefix;
my $randomize;

GetOptions(
    'headers=s'  => \$headdir,
    'libs=s'     => \$libdir,
    'prefix=s'   => \$prefix,
    'randomize!' => \$randomize,
);

if ( $prefix ) {
    $headdir = catdir( $prefix, 'include' );
    $libdir  = catdir( $prefix, 'lib' );
}

cc_include_paths( $headdir ) if $headdir;
cc_libs( '-L' . $libdir ) if $libdir;

cc_include_paths( 'include' );

name 'Net-LDNS';
version_from 'lib/Net/LDNS.pm';
license 'bsd';
author 'Calle Dybedahl <calle@init.se>';
abstract 'Perl wrapper for the ldns DNS library.';
perl_version '5.010001';

configure_requires 'Devel::CheckLib';
requires 'MIME::Base64';
test_requires 'JSON::PP';
test_requires 'Test::Fatal';

use_ppport 3.19;
cc_libs 'crypto';
cc_src_paths 'src';

my %assert_args = (
    lib      => 'crypto',
    header   => 'openssl/crypto.h',
    function => 'if(SSLeay()) return 0; else return 1;'
);
$assert_args{LIBS} = '-L' . $libdir  if $libdir;
$assert_args{INC}  = '-I' . $headdir if $headdir;

cc_assert_lib %assert_args;

if (not check_ecdsa(%assert_args)) {
    print "Your OpenSSL does not seem to support ECDSA.\n";
    exit;
}
else {
    print "ECDSA support detected.\n";
}

if (not check_gost(%assert_args)) {
    print "Your OpenSSL does not seem to support GOST.\n";
}
else {
    print "GOST support detected.\n";
    cc_define '-DUSE_GOST';
}

if (
    check_lib(
        lib      => 'idn',
        header   => 'idna.h',
        function => 'if(strcmp(IDNA_ACE_PREFIX,"xn--")==0) return 0; else return 1;'
    )
  )
{
    cc_libs 'idn';
    cc_define '-DWE_CAN_HAZ_IDN';
    print "IDNA support detected.\n";
}

if ( $randomize ) {
    cc_define '-DRANDOMIZE';
    print( ( "=" x 65 ) . "\n" );
    print "Compiling with randomzied capitalization.\n";
    print( ( "=" x 65 ) . "\n" );
}

WriteAll;

sub check_ecdsa {
    my %args = @_;

    $args{header} = [ 'openssl/crypto.h', 'openssl/ecdsa.h' ];
    $args{function} = q[if(ECDSA_SIG_new()) return 0; else return 1;];

    return check_lib(%args);
}

sub check_gost {
    my %args = @_;

    $args{header} = [ 'openssl/crypto.h', 'openssl/ecdsa.h', 'openssl/engine.h' ];
    $args{function} = <<'CODE';
    const EVP_PKEY_ASN1_METHOD* meth;
    ENGINE* e;

    meth = EVP_PKEY_asn1_find_str(NULL, "gost2001", -1);
    if(meth) {
       return 0;
    }

    e = ENGINE_by_id("gost");
    if(!e) {
       ENGINE_load_builtin_engines();
       ENGINE_load_dynamic();
       e = ENGINE_by_id("gost");
    }
    if(!e) {
       return 1;
    }
    if(!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
       return 1;
    }

    meth = EVP_PKEY_asn1_find_str(&e, "gost2001", -1);
    if(!meth) {
       return 1;
    }

    return 0;

CODE

    return check_lib(%args);
}