Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options to build with Libidn and LDNS in uncommon locations #152

Merged
5 commits merged into from Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 134 additions & 45 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ The PATH is passed to the LDNS compiler via the CFLAGS variable.
Search for OpenSSL library in PATH.
The PATH is passed to the LDNS compiler via the LDFLAGS variable.

=item --libidn-inc=PATH

Search for Libidn include in PATH.

=item --libidn-lib=PATH

Search for Libidn library in PATH.

=item --ldns-inc=PATH

Search for LDNS include in PATH.

=item --ldns-lib=PATH

Search for LDNS library in PATH.

=item --debug

Enable debug mode, more verbose output.

=back

=cut
Expand All @@ -66,17 +86,36 @@ my $opt_ed25519 = 1;
my $opt_idn = 1;
my $opt_internal_ldns = 1;
my $opt_randomize = 0;
my $opt_prefix_openssl = "";
my $opt_openssl_inc = "";
my $opt_openssl_lib = "";
my $opt_debug = 0;
my $opt_assets = {
openssl => {
prefix => "",
inc => "",
lib => ""
},
ldns => {
inc => "",
lib => ""
},
libidn => {
inc => "",
lib => ""
}
};

GetOptions(
'ed25519!' => \$opt_ed25519,
'idn!' => \$opt_idn,
'internal-ldns!' => \$opt_internal_ldns,
'randomize!' => \$opt_randomize,
'prefix-openssl=s' => \$opt_prefix_openssl,
'openssl-inc=s' => \$opt_openssl_inc,
'openssl-lib=s' => \$opt_openssl_lib,
'debug!' => \$opt_debug,
'prefix-openssl=s' => \$$opt_assets{openssl}{prefix},
'openssl-inc=s' => \$$opt_assets{openssl}{inc},
'openssl-lib=s' => \$$opt_assets{openssl}{lib},
'libidn-inc=s' => \$$opt_assets{libidn}{inc},
'libidn-lib=s' => \$$opt_assets{libidn}{lib},
'ldns-inc=s' => \$$opt_assets{ldns}{inc},
'ldns-lib=s' => \$$opt_assets{ldns}{lib},
);

configure_requires 'Devel::CheckLib';
Expand All @@ -91,52 +130,82 @@ cc_include_paths 'include';
cc_src_paths 'src';


# OpenSSL

my %assert_lib_args_openssl;
my $custom_openssl = ( $opt_prefix_openssl or $opt_openssl_inc or $opt_openssl_lib );
if ( $custom_openssl ) {
my $openssl_incpath = "";
my $openssl_libpath = "";
my %assert_lib_args = (
openssl => {},
libidn => {},
ldns => {}
);

if ( $opt_prefix_openssl ) {
print "Custom prefix for OpenSSL: $opt_prefix_openssl\n";
$openssl_incpath = "$opt_prefix_openssl/include";
$openssl_libpath = "$opt_prefix_openssl/lib";
sub custom_assets
{
my ( $href ) = @_;
# $href = { key => "openssl", lib => "crypto", name => "OpenSSL" }

my $key = $$href{key};
my $name = $$href{name};
my $lib = $$href{lib};

my $input_prefix = $$opt_assets{$key}{prefix};
my $input_inc = $$opt_assets{$key}{inc};
my $input_lib = $$opt_assets{$key}{lib};

my $custom_lib = ( $input_prefix or $input_inc or $input_lib );
if ( $custom_lib ) {
my $incpath = "";
my $libpath = "";

if ( $input_prefix ) {
print "Custom prefix for $name: $input_prefix\n";
$incpath = "$input_prefix/include";
$libpath = "$input_prefix/lib";
}

if ( $input_inc ) {
print "Custom include directory for $name: $input_inc\n";
$incpath = "$input_inc";
}

if ( $input_lib ) {
print "Custom library directory for $name: $input_lib\n";
$libpath = "$input_lib";
}

cc_include_paths "$incpath";
cc_libs "-L$libpath", "$lib";

$assert_lib_args{$key}{incpath} = "$incpath";
$assert_lib_args{$key}{libpath} = "$libpath";
}

if ( $opt_openssl_inc ) {
print "Custom include directory for OpenSSL: $opt_openssl_inc\n";
$openssl_incpath = "$opt_openssl_inc";
else {
cc_libs "$lib";
}
}

if ( $opt_openssl_lib ) {
print "Custom library directory for OpenSSL: $opt_openssl_lib\n";
$openssl_libpath = "$opt_openssl_lib";
}
# OpenSSL

cc_include_paths "$openssl_incpath";
cc_libs "-L$openssl_libpath", "crypto";
$assert_lib_args_openssl{incpath} = "$openssl_incpath";
$assert_lib_args_openssl{libpath} = "$openssl_libpath";
}
else {
cc_libs 'crypto';
}
custom_assets(
{
name => "OpenSSL",
lib => "crypto",
key => "openssl"
}
);

cc_assert_lib(
debug => $opt_debug,
lib => 'crypto',
header => 'openssl/crypto.h',
function => 'if(SSLeay()) return 0; else return 1;',
%assert_lib_args_openssl,
%{ $assert_lib_args{openssl} },
);
if ( $opt_ed25519 ) {
print "Feature Ed25519 enabled\n";
cc_assert_lib(
debug => $opt_debug,
lib => 'crypto',
header => 'openssl/evp.h',
function => 'EVP_PKEY_ED25519; return 0;',
%assert_lib_args_openssl,
%{ $assert_lib_args{openssl} },
);
}
else {
Expand All @@ -153,28 +222,48 @@ if ( $opt_internal_ldns ) {
}
else {
print "Feature internal ldns disabled\n";
cc_libs 'ldns';

custom_assets(
{
name => "LDNS",
lib => "ldns",
key => "ldns"
}
);

if ( $opt_ed25519 ) {
cc_assert_lib(
debug => $opt_debug,
lib => 'ldns',
header => 'ldns/ldns.h',
%{ $assert_lib_args{ldns} },
ccflags => '-DUSE_ED25519',
function => 'if(LDNS_ED25519) return 0; else return 1;'
);
}
}


# IDN
# Libidn

if ( $opt_idn ) {
print "Feature idn enabled\n";

custom_assets(
{
name => "Libidn",
lib => "idn2",
key => "libidn"
}
);

check_lib_or_exit(
debug => $opt_debug,
lib => 'idn2',
header => 'idn2.h',
function =>
'return IDN2_OK;');
cc_libs 'idn2';
%{ $assert_lib_args{libidn} },
function => 'return IDN2_OK;'
);
cc_define '-DWE_CAN_HAZ_IDN';
}
else {
Expand Down Expand Up @@ -228,14 +317,14 @@ END_CONFIGURE_FLAGS

my $openssl_make = <<END_OPENSSL_MAKE;

CONFIGURE_FLAGS += --with-ssl=$opt_prefix_openssl
CONFIGURE_FLAGS += --with-ssl=$$opt_assets{openssl}{prefix}

END_OPENSSL_MAKE

my $openssl_flags = <<END_OPENSSL_FLAGS;

CFLAGS += -I$opt_openssl_inc
LDFLAGS += -L$opt_openssl_lib
CFLAGS += -I$$opt_assets{penssl}{inc}
LDFLAGS += -L$$opt_assets{openssl}{lib}

END_OPENSSL_FLAGS

Expand Down Expand Up @@ -278,10 +367,10 @@ END_INTERNAL_LDNS
$postamble .= $docker_make;
if ( $opt_internal_ldns ) {
$postamble .= $configure_flags_make;
$postamble .= $openssl_make if $opt_prefix_openssl;
$postamble .= $openssl_make if $$opt_assets{openssl}{prefix};
$postamble .= $ed25519_make if $opt_ed25519;
$postamble .= $no_ed25519_make if !$opt_ed25519;
$postamble .= $openssl_flags if ( $opt_openssl_inc or $opt_openssl_lib );
$postamble .= $openssl_flags if ( $$opt_assets{openssl}{inc} or $$opt_assets{openssl}{lib} );
$postamble .= $internal_ldns_make;
}

Expand Down
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
* [IDN]
* [Internal ldns]
* [Randomized capitalization](#randomized-capitalization)
* [Custom OpenSSL]
* [Custom LDNS]
* [Custom Libidn]
* [Debug]


## Introduction
Expand Down Expand Up @@ -175,7 +179,7 @@ Randomizes the capitalization of returned domain names.

Disabled by default.
Enabled with `--prefix-openssl=/path/to/openssl` or
`--openssl-inc=/path/to/openssl_inc` or `--openssl-lib=/path/to/openssl_lib`
`--openssl-inc=/path/to/openssl_inc` or `--openssl-lib=/path/to/openssl_lib`.

Enabling this makes the build tools look for OpenSSL in a non-standard place.

Expand All @@ -192,6 +196,39 @@ same parent directory, use `--openssl-inc` and `--openssl-lib` options to
specify both paths.


### Custom LDNS

Disabled by default.
Enabled with `--ldns-inc=/path/to/ldns_inc` or `--ldns-lib=/path/to/ldns_lib`.

Enabling this makes the build tools look for LDNS in a non-standard place.

> Requires [Internal LDNS] to be disabled.


### Custom Libidn

Disabled by default.
Enabled with `--libidn-inc=/path/to/libidn_inc` or
`--libidn-lib=/path/to/ldns_lib`.

Enabling this makes the build tools look for Libidn in a non-standard place.

> Requires [IDN] to be enabled.


### Debug

Disabled by default.
Enabled with `--debug`.

Gives a more verbose output.


[Custom LDNS]: #custom-ldns
[Custom Libidn]: #custom-libidn
[Custom OpenSSL]: #custom-openssl
[Debug]: #debug
[DNS::LDNS]: http://search.cpan.org/~erikoest/DNS-LDNS/
[Docker Hub]: https://hub.docker.com/u/zonemaster
[Docker Image Creation]: https://github.com/zonemaster/zonemaster/blob/master/docs/internal-documentation/maintenance/ReleaseProcess-create-docker-image.md
Expand Down