]> Dogcows Code - chaz/p5-File-KDBX-XS/blob - Makefile.PL
make sure MakeMaker::Custom is listed as a prereq
[chaz/p5-File-KDBX-XS] / Makefile.PL
1 #!/usr/bin/env perl
2
3 # A lot of this is cargo-culted from CryptX which has already gone through a lot of working around platform
4 # incompatibilities which we're grateful to take advantage of here -- thanks cpan:MIK!
5
6 use warnings;
7 use strict;
8
9 use Config;
10 use ExtUtils::MakeMaker;
11
12 ##{ $share_dir_code{preamble} || '' ##}
13
14 my (@EUMM_INC_LIB, $myarflags, $mycflags);
15
16 # use bundled libtomcrypt
17 my @myobjs = map { /^(.*)\.c$/ ? "$1$Config{obj_ext}" : () } qw(
18 libtomcrypt/src/ciphers/aes/aes.c
19 libtomcrypt/src/misc/compare_testvector.c
20 libtomcrypt/src/misc/crypt/crypt_argchk.c
21 libtomcrypt/src/misc/zeromem.c
22 );
23 $mycflags = " $Config{ccflags} $Config{cccdlflags} $Config{optimize} "; # keep leading + trailing spaces
24
25 #FIX: this is particularly useful for Debian https://github.com/DCIT/perl-CryptX/pull/39
26 $mycflags .= " $ENV{CFLAGS} " if $ENV{CFLAGS};
27 $mycflags .= " $ENV{CPPFLAGS} " if $ENV{CPPFLAGS};
28
29 #### remove all lto hacks - https://github.com/DCIT/perl-CryptX/issues/70
30 ## #FIX: gcc with -flto is a trouble maker see https://github.com/DCIT/perl-CryptX/issues/32
31 ## #FIX: another issue with "-flto=auto" see https://github.com/DCIT/perl-CryptX/pull/66
32 ## $mycflags =~ s/\s-flto\S+\s/ /g; # -flto -flto=auto -flto=jobserver -flto=N ...
33
34 #FIX: avoid -Wwrite-strings -Wcast-qual -pedantic -pedantic-errors -ansi -std=c89
35 $mycflags =~ s/\s-pedantic-errors\s/ /g;
36 $mycflags =~ s/\s-pedantic\s/ /g;
37 $mycflags =~ s/\s-std=c89\s/ /g;
38 $mycflags =~ s/\s-ansi\s/ /g;
39 $mycflags =~ s/\s-Wwrite-strings\s/ /g;
40 $mycflags =~ s/\s-Wcast-qual\s/ /g;
41
42 #FIX: avoid "ar: fatal: Numeric group ID too large" see https://github.com/DCIT/perl-CryptX/issues/33
43 $myarflags = '$(AR_STATIC_ARGS)';
44 if ($^O ne 'MSWin32' && $Config{ar}) {
45 # for ar's "deterministic mode" we need GNU binutils 2.20+ (2009-10-16)
46 my $arver = `$Config{ar} --version 2>/dev/null`;
47 my ($maj, $min) = $arver =~ /^GNU ar [^\d]*(\d)\.(\d+)\.\d+/s;
48 $myarflags = 'rcD' if ($maj && $min && $maj >= 2 && $min >= 20) || $arver=~ /^BSD ar /;
49 }
50
51 # turn on extra warnings in AUTHOR_MODE (it is gcc only!!)
52 $mycflags = "$mycflags -Wall -Werror -Wextra" if $ENV{AUTHOR_MODE};
53
54 @EUMM_INC_LIB = (
55 INC => $ENV{AUTHOR_MODE} ? '-DLTM_DESC -Ilibtomcrypt/src/headers -Wall -Werror -Wextra' # gcc only
56 : '-DLTM_DESC -Ilibtomcrypt/src/headers',
57 MYEXTLIB => "libtomcrypt/libonlyaes$Config{lib_ext}",
58 clean => { FILES => join(' ', @myobjs, "libtomcrypt/libonlyaes$Config{lib_ext}") },
59 realclean => { FILES => join(' ', qw{cover_db *.gcda *.gcno *.gcov})},
60 );
61
62 #FIX: https://github.com/DCIT/perl-CryptX/pull/79
63 # not needed on MS Windows
64 # does not work on macos - Apple LLVM 12.0.5 (clang-1205.0.22.9) ld: unknown option: --exclude-libs
65 # does not work on solaris - gcc 9.3.0 - ld: fatal: unrecognized option '--exclude-libs'
66 if ($^O !~ /^(MSWin32|darwin|solaris)$/ && ($Config{ld} =~ /gcc|g\+\+/ || $Config{gccversion})) {
67 push @EUMM_INC_LIB, (LDDLFLAGS => "$Config{lddlflags} -Wl,--exclude-libs,ALL");
68 }
69
70 my %eumm_args = (
71 'NAME' => 'File::KDBX::XS',##{ # List NAME explicitly here so it works even without dzil. ##}
72 ##{ $plugin->get_default(qw{ABSTRACT AUTHOR DISTNAME LICENSE MIN_PERL_VERSION VERSION test}) ##}
73 ##{ $plugin->get_prereqs(1) ##}
74 @EUMM_INC_LIB,
75 );
76
77 my $eumm_ver = eval $ExtUtils::MakeMaker::VERSION;
78 delete $eumm_args{MIN_PERL_VERSION} if $eumm_ver < 6.48;
79 delete $eumm_args{META_ADD} if $eumm_ver < 6.46;
80 delete $eumm_args{META_MERGE} if $eumm_ver < 6.46;
81 delete $eumm_args{LICENSE} if $eumm_ver < 6.31;
82 delete $eumm_args{CONFIGURE_REQUIRES} if $eumm_ver < 6.52;
83 delete $eumm_args{BUILD_REQUIRES} if $eumm_ver < 6.56;
84 delete $eumm_args{TEST_REQUIRES} if $eumm_ver < 6.64;
85
86 WriteMakefile(%eumm_args);
87
88 sub MY::postamble {
89 return "" unless $mycflags && $myarflags;
90
91 my $extra_targets = qq{
92 \$(MYEXTLIB): libtomcrypt/Makefile
93 \tcd libtomcrypt && \$(MAKE) ARFLAGS="$myarflags" RANLIB="\$(RANLIB)" AR="\$(AR)" CC="\$(CC)" LIB_EXT=\$(LIB_EXT) OBJ_EXT=\$(OBJ_EXT) CFLAGS="$mycflags"
94 };
95
96 $extra_targets = qq{
97 \$(MYEXTLIB): libtomcrypt/Makefile
98 \tcd libtomcrypt && \$(MAKE) -f Makefile.nmake CFLAGS="$mycflags"
99 } if $^O eq 'MSWin32' && $Config{make} =~ /nmake/ && $Config{cc} =~ /cl/;
100
101 $extra_targets = qq{
102 \$(MYEXTLIB): libtomcrypt/Makefile
103 \tcd libtomcrypt && \$(MAKE) CC="$Config{cc}" CFLAGS="$mycflags"
104 } if $^O eq 'MSWin32' && $Config{cc} =~ /gcc/;
105
106 return $extra_targets;
107 }
108
109 ##{ $share_dir_code{postamble} || '' ##}
This page took 0.042299 seconds and 4 git commands to generate.