|
0 |
#!/usr/bin/env perl
|
|
1 |
|
|
2 |
use Modern::Perl;
|
|
3 |
use File::Find qw(find);
|
|
4 |
use File::Slurper qw(read_text write_text);
|
|
5 |
use FindBin;
|
|
6 |
|
|
7 |
my $ltc_branch = "pr/pkcs8-improved";
|
|
8 |
my $ltm_branch = "no-stdint-h";
|
|
9 |
my $tmpdir = "/tmp/libtom.git.checkout.$$";
|
|
10 |
|
|
11 |
warn "update libtommath from github (branch: $ltm_branch)..\n";
|
|
12 |
system "rm -rf $tmpdir; mkdir $tmpdir";
|
|
13 |
system "git clone -b $ltm_branch https://github.com/libtom/libtommath.git $tmpdir && cp -R $tmpdir/bn*.c $tmpdir/tom*.h $FindBin::Bin/ltm/ && echo ok";
|
|
14 |
|
|
15 |
warn "update libtomcrypt from github (branch: $ltc_branch)..\n";
|
|
16 |
system "rm -rf $tmpdir; mkdir $tmpdir";
|
|
17 |
system "git clone -b $ltc_branch https://github.com/libtom/libtomcrypt.git $tmpdir && cp -R $tmpdir/src/* $FindBin::Bin/ltc/ && echo ok";
|
|
18 |
system "rm -rf $tmpdir";
|
|
19 |
|
|
20 |
### another style
|
|
21 |
#system "wget https://github.com/libtom/libtomcrypt/tarball/$ltc_branch -q -O - | tar xz --wildcards --transform 's,^libtom.*/src/,,' -C '$FindBin::Bin/ltc' 'libtom*/src/*'";
|
|
22 |
#system "wget https://github.com/libtom/libtommath/tarball/$ltm_branch -q -O - | tar xz --wildcards --transform 's,^libtom.*/,,' -C '$FindBin::Bin/ltm' 'libtom*/bn*.c' 'libtom*/tom*.h'";
|
|
23 |
|
|
24 |
warn "gonna remove unwanted..\n";
|
|
25 |
system 'rm', '-rf', "$FindBin::Bin/ltc/encauth/ocb/";
|
|
26 |
system 'rm', '-rf', "$FindBin::Bin/ltc/modes/f8/";
|
|
27 |
system 'rm', '-rf', "$FindBin::Bin/ltc/modes/lrw/";
|
|
28 |
system 'rm', '-rf', "$FindBin::Bin/ltc/modes/xts/";
|
|
29 |
system 'rm', '-rf', "$FindBin::Bin/ltc/pk/katja/";
|
|
30 |
system 'rm', '-rf', "$FindBin::Bin/ltc/math/gmp_desc.c";
|
|
31 |
|
|
32 |
### get rid of bn_mp_set_long_long + bn_mp_get_long_long
|
|
33 |
system 'rm', '-rf', "$FindBin::Bin/ltm/bn_mp_set_long_long.c";
|
|
34 |
system 'rm', '-rf', "$FindBin::Bin/ltm/bn_mp_get_long_long.c";
|
|
35 |
system 'sed', '-i', 's,^\(int *mp_set_long_long.*\),/* \1 */,', 'src//ltm/tommath.h';
|
|
36 |
system 'sed', '-i', 's,^\(unsigned *long *long *mp_get_long_long.*\),/* \1 */,', 'src//ltm/tommath.h';
|
|
37 |
|
|
38 |
### MSVC hack required for VC6 compatibility
|
|
39 |
# #ifdef _MSC_VER
|
|
40 |
# typedef unsigned __int64 mp_word
|
|
41 |
# #else
|
|
42 |
# typedef unsigned long long mp_word;
|
|
43 |
# #endif
|
|
44 |
system 'sed', '-i', 's,^\(typedef *unsigned *long *long *mp_word;\)$,#ifdef _MSC_VER\ntypedef unsigned __int64 mp_word;\n#else\n\1 /* PATCHED */\n#endif,', 'src//ltm/tommath.h';
|
|
45 |
|
|
46 |
find({ wanted=>sub { unlink $_ if -f $_ && $_ =~ /test\.c$/ && $_ !~ /sha3_test.c$/ }, no_chdir=>1 }, "$FindBin::Bin/ltc");
|
|
47 |
find({ wanted=>sub { unlink $_ if -f $_ && $_ =~ /\.o$/ }, no_chdir=>1 }, "$FindBin::Bin/ltm", "$FindBin::Bin/ltc");
|
|
48 |
|
|
49 |
#fix modes
|
|
50 |
warn "gonna chmod..\n";
|
|
51 |
find({ wanted=>sub { system "chmod -x $_" if -f $_ && -x $_ && $_ =~ /\.(c|h)/ }, no_chdir=>1 }, "$FindBin::Bin/ltm", "$FindBin::Bin/ltc");
|
|
52 |
|
|
53 |
my @objs = ();
|
|
54 |
find({ wanted=>sub { push @objs, $_ if $_ =~ /\.c$/ && $_ !~ /tab\.c$/}, no_chdir=>1 }, "$FindBin::Bin/ltc");
|
|
55 |
find({ wanted=>sub { push @objs, $_ if $_ =~ /\.c$/ }, no_chdir=>1 }, "$FindBin::Bin/ltm");
|
|
56 |
|
|
57 |
my $o = "OBJS=" . (join " ", map { s/\.c$/.o/r } map { s!^.*/(ltm|ltc)/!$1/!r } @objs) =~ s/(.{80}) /$1 \\\n/gr;
|
|
58 |
my $obj = "OBJS=" . (join " ", map { s/\.c$/.obj/r } map { s!^.*/(ltm|ltc)/!$1/!r } @objs) =~ s/(.{80}) /$1 \\\n/gr;
|
|
59 |
|
|
60 |
write_text("$FindBin::Bin/Makefile", read_text("$FindBin::Bin/Makefile") =~ s/OBJS=.+?\.o\n/$o\n/sr);
|
|
61 |
write_text("$FindBin::Bin/Makefile.nmake", read_text("$FindBin::Bin/Makefile.nmake") =~ s/OBJS=.+?\.obj\n/$obj\n/sr);
|