2018-12-02 13:27:53 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Getopt::Long;
|
|
|
|
use File::Find 'find';
|
|
|
|
use File::Basename 'basename';
|
|
|
|
use File::Glob 'bsd_glob';
|
|
|
|
|
|
|
|
sub read_file {
|
|
|
|
my $f = shift;
|
|
|
|
open my $fh, "<", $f or die "FATAL: read_rawfile() cannot open file '$f': $!";
|
|
|
|
binmode $fh;
|
|
|
|
return do { local $/; <$fh> };
|
|
|
|
}
|
|
|
|
|
|
|
|
sub write_file {
|
|
|
|
my ($f, $data) = @_;
|
|
|
|
die "FATAL: write_file() no data" unless defined $data;
|
|
|
|
open my $fh, ">", $f or die "FATAL: write_file() cannot open file '$f': $!";
|
|
|
|
binmode $fh;
|
|
|
|
print $fh $data or die "FATAL: write_file() cannot write to '$f': $!";
|
|
|
|
close $fh or die "FATAL: write_file() cannot close '$f': $!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-07 08:56:13 +00:00
|
|
|
sub sanitize_comments {
|
|
|
|
my($content) = @_;
|
|
|
|
$content =~ s{/\*(.*?)\*/}{my $x=$1; $x =~ s/\w/x/g; "/*$x*/";}egs;
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
2018-12-02 13:27:53 +00:00
|
|
|
sub check_source {
|
|
|
|
my @all_files = (
|
|
|
|
bsd_glob("makefile*"),
|
|
|
|
bsd_glob("*.{h,c,sh,pl}"),
|
|
|
|
bsd_glob("*/*.{h,c,sh,pl}"),
|
|
|
|
);
|
|
|
|
|
|
|
|
my $fails = 0;
|
|
|
|
for my $file (sort @all_files) {
|
|
|
|
my $troubles = {};
|
|
|
|
my $lineno = 1;
|
|
|
|
my $content = read_file($file);
|
2019-05-07 08:56:13 +00:00
|
|
|
$content = sanitize_comments $content;
|
2018-12-02 13:27:53 +00:00
|
|
|
push @{$troubles->{crlf_line_end}}, '?' if $content =~ /\r/;
|
|
|
|
for my $l (split /\n/, $content) {
|
|
|
|
push @{$troubles->{merge_conflict}}, $lineno if $l =~ /^(<<<<<<<|=======|>>>>>>>)([^<=>]|$)/;
|
|
|
|
push @{$troubles->{trailing_space}}, $lineno if $l =~ / $/;
|
|
|
|
push @{$troubles->{tab}}, $lineno if $l =~ /\t/ && basename($file) !~ /^makefile/i;
|
|
|
|
push @{$troubles->{non_ascii_char}}, $lineno if $l =~ /[^[:ascii:]]/;
|
|
|
|
push @{$troubles->{cpp_comment}}, $lineno if $file =~ /\.(c|h)$/ && ($l =~ /\s\/\// || $l =~ /\/\/\s/);
|
2019-10-23 21:25:37 +00:00
|
|
|
# we prefer using MP_MALLOC, MP_FREE, MP_REALLOC, MP_CALLOC ...
|
2018-12-02 13:27:53 +00:00
|
|
|
push @{$troubles->{unwanted_malloc}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmalloc\s*\(/;
|
|
|
|
push @{$troubles->{unwanted_realloc}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\brealloc\s*\(/;
|
|
|
|
push @{$troubles->{unwanted_calloc}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bcalloc\s*\(/;
|
|
|
|
push @{$troubles->{unwanted_free}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bfree\s*\(/;
|
|
|
|
# and we probably want to also avoid the following
|
2019-11-05 16:53:08 +00:00
|
|
|
push @{$troubles->{unwanted_memcpy}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemcpy\s*\(/ && $file !~ /s_mp_copy_digs.c/;
|
|
|
|
push @{$troubles->{unwanted_memset}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemset\s*\(/ && $file !~ /s_mp_zero_buf.c/ && $file !~ /s_mp_zero_digs.c/;
|
2018-12-02 13:27:53 +00:00
|
|
|
push @{$troubles->{unwanted_memmove}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemmove\s*\(/;
|
|
|
|
push @{$troubles->{unwanted_memcmp}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmemcmp\s*\(/;
|
|
|
|
push @{$troubles->{unwanted_strcmp}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bstrcmp\s*\(/;
|
|
|
|
push @{$troubles->{unwanted_strcpy}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bstrcpy\s*\(/;
|
|
|
|
push @{$troubles->{unwanted_strncpy}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bstrncpy\s*\(/;
|
|
|
|
push @{$troubles->{unwanted_clock}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bclock\s*\(/;
|
|
|
|
push @{$troubles->{unwanted_qsort}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bqsort\s*\(/;
|
|
|
|
push @{$troubles->{sizeof_no_brackets}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bsizeof\s*[^\(]/;
|
|
|
|
if ($file =~ m|^[^\/]+\.c$| && $l =~ /^static(\s+[a-zA-Z0-9_]+)+\s+([a-zA-Z0-9_]+)\s*\(/) {
|
|
|
|
my $funcname = $2;
|
|
|
|
# static functions should start with s_
|
|
|
|
push @{$troubles->{staticfunc_name}}, "$lineno($funcname)" if $funcname !~ /^s_/;
|
|
|
|
}
|
|
|
|
$lineno++;
|
|
|
|
}
|
|
|
|
for my $k (sort keys %$troubles) {
|
|
|
|
warn "[$k] $file line:" . join(",", @{$troubles->{$k}}) . "\n";
|
|
|
|
$fails++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
warn( $fails > 0 ? "check-source: FAIL $fails\n" : "check-source: PASS\n" );
|
|
|
|
return $fails;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub check_comments {
|
|
|
|
my $fails = 0;
|
|
|
|
my $first_comment = <<'MARKER';
|
2019-04-07 13:29:11 +00:00
|
|
|
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
|
|
|
/* SPDX-License-Identifier: Unlicense */
|
2018-12-02 13:27:53 +00:00
|
|
|
MARKER
|
|
|
|
#my @all_files = (bsd_glob("*.{h,c}"), bsd_glob("*/*.{h,c}"));
|
|
|
|
my @all_files = (bsd_glob("*.{h,c}"));
|
|
|
|
for my $f (@all_files) {
|
|
|
|
my $txt = read_file($f);
|
|
|
|
if ($txt !~ /\Q$first_comment\E/s) {
|
|
|
|
warn "[first_comment] $f\n";
|
|
|
|
$fails++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
warn( $fails > 0 ? "check-comments: FAIL $fails\n" : "check-comments: PASS\n" );
|
|
|
|
return $fails;
|
|
|
|
}
|
|
|
|
|
2018-12-08 18:35:28 +00:00
|
|
|
sub check_doc {
|
|
|
|
my $fails = 0;
|
|
|
|
my $tex = read_file('doc/bn.tex');
|
|
|
|
my $tmh = read_file('tommath.h');
|
2019-10-27 14:48:38 +00:00
|
|
|
my @functions = $tmh =~ /\n\s*[a-zA-Z0-9_* ]+?(mp_[a-z0-9_]+)\s*\([^\)]+\)\s*[MP_WUR]+?;/sg;
|
2018-12-08 18:35:28 +00:00
|
|
|
my @macros = $tmh =~ /\n\s*#define\s+([a-z0-9_]+)\s*\([^\)]+\)/sg;
|
|
|
|
for my $n (sort @functions) {
|
|
|
|
(my $nn = $n) =~ s/_/\\_/g; # mp_sub_d >> mp\_sub\_d
|
|
|
|
if ($tex !~ /index\Q{$nn}\E/) {
|
|
|
|
warn "[missing_doc_for_function] $n\n";
|
|
|
|
$fails++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for my $n (sort @macros) {
|
|
|
|
(my $nn = $n) =~ s/_/\\_/g; # mp_iszero >> mp\_iszero
|
|
|
|
if ($tex !~ /index\Q{$nn}\E/) {
|
|
|
|
warn "[missing_doc_for_macro] $n\n";
|
|
|
|
$fails++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
warn( $fails > 0 ? "check_doc: FAIL $fails\n" : "check-doc: PASS\n" );
|
|
|
|
return $fails;
|
|
|
|
}
|
|
|
|
|
2018-12-02 13:27:53 +00:00
|
|
|
sub prepare_variable {
|
|
|
|
my ($varname, @list) = @_;
|
|
|
|
my $output = "$varname=";
|
|
|
|
my $len = length($output);
|
|
|
|
foreach my $obj (sort @list) {
|
|
|
|
$len = $len + length $obj;
|
|
|
|
$obj =~ s/\*/\$/;
|
|
|
|
if ($len > 100) {
|
|
|
|
$output .= "\\\n";
|
|
|
|
$len = length $obj;
|
|
|
|
}
|
|
|
|
$output .= $obj . ' ';
|
|
|
|
}
|
|
|
|
$output =~ s/ $//;
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub prepare_msvc_files_xml {
|
|
|
|
my ($all, $exclude_re, $targets) = @_;
|
|
|
|
my $last = [];
|
|
|
|
my $depth = 2;
|
|
|
|
|
|
|
|
# sort files in the same order as visual studio (ugly, I know)
|
|
|
|
my @parts = ();
|
|
|
|
for my $orig (@$all) {
|
|
|
|
my $p = $orig;
|
|
|
|
$p =~ s|/|/~|g;
|
|
|
|
$p =~ s|/~([^/]+)$|/$1|g;
|
|
|
|
my @l = map { sprintf "% -99s", $_ } split /\//, $p;
|
|
|
|
push @parts, [ $orig, join(':', @l) ];
|
|
|
|
}
|
|
|
|
my @sorted = map { $_->[0] } sort { $a->[1] cmp $b->[1] } @parts;
|
|
|
|
|
|
|
|
my $files = "<Files>\r\n";
|
|
|
|
for my $full (@sorted) {
|
|
|
|
my @items = split /\//, $full; # split by '/'
|
|
|
|
$full =~ s|/|\\|g; # replace '/' bt '\'
|
|
|
|
shift @items; # drop first one (src)
|
|
|
|
pop @items; # drop last one (filename.ext)
|
|
|
|
my $current = \@items;
|
|
|
|
if (join(':', @$current) ne join(':', @$last)) {
|
|
|
|
my $common = 0;
|
|
|
|
$common++ while ($last->[$common] && $current->[$common] && $last->[$common] eq $current->[$common]);
|
|
|
|
my $back = @$last - $common;
|
|
|
|
if ($back > 0) {
|
|
|
|
$files .= ("\t" x --$depth) . "</Filter>\r\n" for (1..$back);
|
|
|
|
}
|
|
|
|
my $fwd = [ @$current ]; splice(@$fwd, 0, $common);
|
|
|
|
for my $i (0..scalar(@$fwd) - 1) {
|
|
|
|
$files .= ("\t" x $depth) . "<Filter\r\n";
|
|
|
|
$files .= ("\t" x $depth) . "\tName=\"$fwd->[$i]\"\r\n";
|
|
|
|
$files .= ("\t" x $depth) . "\t>\r\n";
|
|
|
|
$depth++;
|
|
|
|
}
|
|
|
|
$last = $current;
|
|
|
|
}
|
|
|
|
$files .= ("\t" x $depth) . "<File\r\n";
|
|
|
|
$files .= ("\t" x $depth) . "\tRelativePath=\"$full\"\r\n";
|
|
|
|
$files .= ("\t" x $depth) . "\t>\r\n";
|
|
|
|
if ($full =~ $exclude_re) {
|
|
|
|
for (@$targets) {
|
|
|
|
$files .= ("\t" x $depth) . "\t<FileConfiguration\r\n";
|
|
|
|
$files .= ("\t" x $depth) . "\t\tName=\"$_\"\r\n";
|
|
|
|
$files .= ("\t" x $depth) . "\t\tExcludedFromBuild=\"true\"\r\n";
|
|
|
|
$files .= ("\t" x $depth) . "\t\t>\r\n";
|
|
|
|
$files .= ("\t" x $depth) . "\t\t<Tool\r\n";
|
|
|
|
$files .= ("\t" x $depth) . "\t\t\tName=\"VCCLCompilerTool\"\r\n";
|
|
|
|
$files .= ("\t" x $depth) . "\t\t\tAdditionalIncludeDirectories=\"\"\r\n";
|
|
|
|
$files .= ("\t" x $depth) . "\t\t\tPreprocessorDefinitions=\"\"\r\n";
|
|
|
|
$files .= ("\t" x $depth) . "\t\t/>\r\n";
|
|
|
|
$files .= ("\t" x $depth) . "\t</FileConfiguration>\r\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$files .= ("\t" x $depth) . "</File>\r\n";
|
|
|
|
}
|
|
|
|
$files .= ("\t" x --$depth) . "</Filter>\r\n" for (@$last);
|
|
|
|
$files .= "\t</Files>";
|
|
|
|
return $files;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub patch_file {
|
|
|
|
my ($content, @variables) = @_;
|
|
|
|
for my $v (@variables) {
|
|
|
|
if ($v =~ /^([A-Z0-9_]+)\s*=.*$/si) {
|
|
|
|
my $name = $1;
|
|
|
|
$content =~ s/\n\Q$name\E\b.*?[^\\]\n/\n$v\n/s;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
die "patch_file failed: " . substr($v, 0, 30) . "..";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub process_makefiles {
|
|
|
|
my $write = shift;
|
|
|
|
my $changed_count = 0;
|
|
|
|
my @o = map { my $x = $_; $x =~ s/\.c$/.o/; $x } bsd_glob("*.c");
|
2018-12-02 13:32:08 +00:00
|
|
|
my @all = bsd_glob("*.{c,h}");
|
2018-12-02 13:27:53 +00:00
|
|
|
|
|
|
|
my $var_o = prepare_variable("OBJECTS", @o);
|
|
|
|
(my $var_obj = $var_o) =~ s/\.o\b/.obj/sg;
|
|
|
|
|
|
|
|
# update MSVC project files
|
|
|
|
my $msvc_files = prepare_msvc_files_xml(\@all, qr/NOT_USED_HERE/, ['Debug|Win32', 'Release|Win32', 'Debug|x64', 'Release|x64']);
|
|
|
|
for my $m (qw/libtommath_VS2008.vcproj/) {
|
|
|
|
my $old = read_file($m);
|
|
|
|
my $new = $old;
|
|
|
|
$new =~ s|<Files>.*</Files>|$msvc_files|s;
|
|
|
|
if ($old ne $new) {
|
|
|
|
write_file($m, $new) if $write;
|
|
|
|
warn "changed: $m\n";
|
|
|
|
$changed_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# update OBJECTS + HEADERS in makefile*
|
2018-12-02 17:28:59 +00:00
|
|
|
for my $m (qw/ makefile makefile.shared makefile_include.mk makefile.msvc makefile.unix makefile.mingw /) {
|
2018-12-02 13:27:53 +00:00
|
|
|
my $old = read_file($m);
|
|
|
|
my $new = $m eq 'makefile.msvc' ? patch_file($old, $var_obj)
|
|
|
|
: patch_file($old, $var_o);
|
|
|
|
if ($old ne $new) {
|
|
|
|
write_file($m, $new) if $write;
|
|
|
|
warn "changed: $m\n";
|
|
|
|
$changed_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($write) {
|
|
|
|
return 0; # no failures
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
warn( $changed_count > 0 ? "check-makefiles: FAIL $changed_count\n" : "check-makefiles: PASS\n" );
|
|
|
|
return $changed_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-24 10:26:17 +00:00
|
|
|
sub draw_func
|
|
|
|
{
|
2019-05-24 10:40:17 +00:00
|
|
|
my ($deplist, $depmap, $out, $indent, $funcslist) = @_;
|
2019-05-24 10:26:17 +00:00
|
|
|
my @funcs = split ',', $funcslist;
|
|
|
|
# try this if you want to have a look at a minimized version of the callgraph without all the trivial functions
|
2019-10-19 14:24:39 +00:00
|
|
|
#if ($deplist =~ /$funcs[0]/ || $funcs[0] =~ /MP_(ADD|SUB|CLEAR|CLEAR_\S+|DIV|MUL|COPY|ZERO|GROW|CLAMP|INIT|INIT_\S+|SET|ABS|CMP|CMP_D|EXCH)_C/) {
|
2019-05-24 10:26:17 +00:00
|
|
|
if ($deplist =~ /$funcs[0]/) {
|
2019-05-24 10:40:17 +00:00
|
|
|
return $deplist;
|
2019-05-24 10:26:17 +00:00
|
|
|
} else {
|
|
|
|
$deplist = $deplist . $funcs[0];
|
|
|
|
}
|
|
|
|
if ($indent == 0) {
|
|
|
|
} elsif ($indent >= 1) {
|
|
|
|
print {$out} '| ' x ($indent - 1) . '+--->';
|
|
|
|
}
|
|
|
|
print {$out} $funcs[0] . "\n";
|
|
|
|
shift @funcs;
|
2019-05-24 10:40:17 +00:00
|
|
|
my $olddeplist = $deplist;
|
2019-05-24 10:26:17 +00:00
|
|
|
foreach my $i (@funcs) {
|
2019-05-24 10:40:17 +00:00
|
|
|
$deplist = draw_func($deplist, $depmap, $out, $indent + 1, ${$depmap}{$i}) if exists ${$depmap}{$i};
|
2019-05-24 10:26:17 +00:00
|
|
|
}
|
2019-05-24 10:40:17 +00:00
|
|
|
return $olddeplist;
|
2019-05-24 10:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub update_dep
|
|
|
|
{
|
|
|
|
#open class file and write preamble
|
|
|
|
open(my $class, '>', 'tommath_class.h') or die "Couldn't open tommath_class.h for writing\n";
|
|
|
|
print {$class} << 'EOS';
|
|
|
|
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
|
|
|
/* SPDX-License-Identifier: Unlicense */
|
|
|
|
|
|
|
|
#if !(defined(LTM1) && defined(LTM2) && defined(LTM3))
|
2019-06-06 10:44:36 +00:00
|
|
|
#define LTM_INSIDE
|
2019-05-24 10:26:17 +00:00
|
|
|
#if defined(LTM2)
|
|
|
|
# define LTM3
|
|
|
|
#endif
|
|
|
|
#if defined(LTM1)
|
|
|
|
# define LTM2
|
|
|
|
#endif
|
|
|
|
#define LTM1
|
|
|
|
#if defined(LTM_ALL)
|
|
|
|
EOS
|
|
|
|
|
2019-10-19 14:24:39 +00:00
|
|
|
foreach my $filename (glob '*mp_*.c') {
|
2019-05-24 10:26:17 +00:00
|
|
|
my $define = $filename;
|
|
|
|
|
|
|
|
print "Processing $filename\n";
|
|
|
|
|
2019-06-06 21:01:51 +00:00
|
|
|
# convert filename to upper case so we can use it as a define
|
2019-05-24 10:26:17 +00:00
|
|
|
$define =~ tr/[a-z]/[A-Z]/;
|
|
|
|
$define =~ tr/\./_/;
|
2019-06-06 20:48:12 +00:00
|
|
|
print {$class} "# define $define\n";
|
2019-05-24 10:26:17 +00:00
|
|
|
|
|
|
|
# now copy text and apply #ifdef as required
|
|
|
|
my $apply = 0;
|
|
|
|
open(my $src, '<', $filename);
|
|
|
|
open(my $out, '>', 'tmp');
|
|
|
|
|
|
|
|
# first line will be the #ifdef
|
|
|
|
my $line = <$src>;
|
|
|
|
if ($line =~ /include/) {
|
|
|
|
print {$out} $line;
|
|
|
|
} else {
|
|
|
|
print {$out} << "EOS";
|
|
|
|
#include "tommath_private.h"
|
|
|
|
#ifdef $define
|
|
|
|
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
|
|
|
/* SPDX-License-Identifier: Unlicense */
|
|
|
|
$line
|
|
|
|
EOS
|
|
|
|
$apply = 1;
|
|
|
|
}
|
|
|
|
while (<$src>) {
|
2019-06-06 21:01:51 +00:00
|
|
|
if ($_ !~ /tommath\.h/) {
|
2019-05-24 10:26:17 +00:00
|
|
|
print {$out} $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($apply == 1) {
|
2019-06-06 20:48:12 +00:00
|
|
|
print {$out} "#endif\n";
|
2019-05-24 10:26:17 +00:00
|
|
|
}
|
|
|
|
close $src;
|
|
|
|
close $out;
|
|
|
|
|
|
|
|
unlink $filename;
|
|
|
|
rename 'tmp', $filename;
|
|
|
|
}
|
2019-06-06 20:48:12 +00:00
|
|
|
print {$class} "#endif\n#endif\n";
|
2019-05-24 10:26:17 +00:00
|
|
|
|
|
|
|
# now do classes
|
2019-05-24 10:38:04 +00:00
|
|
|
my %depmap;
|
2019-10-19 14:24:39 +00:00
|
|
|
foreach my $filename (glob '*mp_*.c') {
|
2019-06-06 10:44:36 +00:00
|
|
|
my $content;
|
2019-10-16 08:28:28 +00:00
|
|
|
my $cc = $ENV{'CC'} || 'gcc';
|
|
|
|
$content = `$cc -E -x c -DLTM_ALL $filename`;
|
|
|
|
$content =~ s/^# 1 "$filename".*?^# 2 "$filename"//ms;
|
2019-05-24 10:26:17 +00:00
|
|
|
|
|
|
|
# convert filename to upper case so we can use it as a define
|
|
|
|
$filename =~ tr/[a-z]/[A-Z]/;
|
|
|
|
$filename =~ tr/\./_/;
|
|
|
|
|
2019-06-06 20:48:12 +00:00
|
|
|
print {$class} "#if defined($filename)\n";
|
2019-05-24 10:26:17 +00:00
|
|
|
my $list = $filename;
|
|
|
|
|
|
|
|
# strip comments
|
|
|
|
$content =~ s{/\*.*?\*/}{}gs;
|
|
|
|
|
|
|
|
# scan for mp_* and make classes
|
2019-06-06 21:01:51 +00:00
|
|
|
my @deps = ();
|
2019-05-24 10:26:17 +00:00
|
|
|
foreach my $line (split /\n/, $content) {
|
2019-09-06 08:22:45 +00:00
|
|
|
while ($line =~ /(fast_)?(s_)?mp\_[a-z_0-9]*((?=\;)|(?=\())|(?<=\()mp\_[a-z_0-9]*(?=\()/g) {
|
2019-05-24 10:26:17 +00:00
|
|
|
my $a = $&;
|
|
|
|
next if $a eq "mp_err";
|
|
|
|
$a =~ tr/[a-z]/[A-Z]/;
|
2019-10-19 14:24:39 +00:00
|
|
|
$a = $a . '_C';
|
2019-06-06 21:01:51 +00:00
|
|
|
push @deps, $a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@deps = sort(@deps);
|
|
|
|
foreach my $a (@deps) {
|
|
|
|
if ($list !~ /$a/) {
|
|
|
|
print {$class} "# define $a\n";
|
2019-05-24 10:26:17 +00:00
|
|
|
}
|
2019-06-06 21:01:51 +00:00
|
|
|
$list = $list . ',' . $a;
|
2019-05-24 10:26:17 +00:00
|
|
|
}
|
2019-05-24 10:35:58 +00:00
|
|
|
$depmap{$filename} = $list;
|
2019-05-24 10:26:17 +00:00
|
|
|
|
2019-06-06 20:48:12 +00:00
|
|
|
print {$class} "#endif\n\n";
|
2019-05-24 10:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print {$class} << 'EOS';
|
2019-06-06 10:44:36 +00:00
|
|
|
#ifdef LTM_INSIDE
|
|
|
|
#undef LTM_INSIDE
|
2019-05-24 10:26:17 +00:00
|
|
|
#ifdef LTM3
|
|
|
|
# define LTM_LAST
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "tommath_superclass.h"
|
|
|
|
#include "tommath_class.h"
|
|
|
|
#else
|
|
|
|
# define LTM_LAST
|
|
|
|
#endif
|
|
|
|
EOS
|
|
|
|
close $class;
|
|
|
|
|
|
|
|
#now let's make a cool call graph...
|
|
|
|
|
|
|
|
open(my $out, '>', 'callgraph.txt');
|
2019-05-24 10:35:58 +00:00
|
|
|
foreach (sort keys %depmap) {
|
2019-05-24 10:40:17 +00:00
|
|
|
draw_func("", \%depmap, $out, 0, $depmap{$_});
|
2019-05-24 10:26:17 +00:00
|
|
|
print {$out} "\n\n";
|
|
|
|
}
|
|
|
|
close $out;
|
2019-05-24 10:35:11 +00:00
|
|
|
|
|
|
|
return 0;
|
2019-05-24 10:17:13 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 08:36:33 +00:00
|
|
|
sub generate_def {
|
2019-11-27 19:55:22 +00:00
|
|
|
my @files = glob '*mp_*.c';
|
|
|
|
@files = map { my $x = $_; $x =~ s/\.c$//g; $x; } @files;
|
2019-11-05 19:35:19 +00:00
|
|
|
@files = grep(!/mp_cutoffs/, @files);
|
2019-06-06 16:15:19 +00:00
|
|
|
|
|
|
|
my $files = join("\n ", sort(grep(/^mp_/, @files)));
|
|
|
|
write_file "tommath.def", "; libtommath
|
|
|
|
;
|
|
|
|
; Use this command to produce a 32-bit .lib file, for use in any MSVC version
|
|
|
|
; lib -machine:X86 -name:libtommath.dll -def:tommath.def -out:tommath.lib
|
|
|
|
; Use this command to produce a 64-bit .lib file, for use in any MSVC version
|
|
|
|
; lib -machine:X64 -name:libtommath.dll -def:tommath.def -out:tommath.lib
|
|
|
|
;
|
|
|
|
EXPORTS
|
|
|
|
$files
|
|
|
|
";
|
|
|
|
return 0;
|
2019-06-06 08:36:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-02 13:27:53 +00:00
|
|
|
sub die_usage {
|
|
|
|
die <<"MARKER";
|
|
|
|
usage: $0 -s OR $0 --check-source
|
|
|
|
$0 -o OR $0 --check-comments
|
|
|
|
$0 -m OR $0 --check-makefiles
|
2019-10-27 15:19:02 +00:00
|
|
|
$0 -d OR $0 --check-doc
|
2018-12-02 13:27:53 +00:00
|
|
|
$0 -a OR $0 --check-all
|
2019-06-06 16:15:19 +00:00
|
|
|
$0 -u OR $0 --update-files
|
2018-12-02 13:27:53 +00:00
|
|
|
MARKER
|
|
|
|
}
|
|
|
|
|
|
|
|
GetOptions( "s|check-source" => \my $check_source,
|
|
|
|
"o|check-comments" => \my $check_comments,
|
|
|
|
"m|check-makefiles" => \my $check_makefiles,
|
2018-12-08 18:35:28 +00:00
|
|
|
"d|check-doc" => \my $check_doc,
|
2018-12-02 13:27:53 +00:00
|
|
|
"a|check-all" => \my $check_all,
|
2019-06-06 16:15:19 +00:00
|
|
|
"u|update-files" => \my $update_files,
|
2018-12-02 13:27:53 +00:00
|
|
|
"h|help" => \my $help
|
|
|
|
) or die_usage;
|
|
|
|
|
|
|
|
my $failure;
|
|
|
|
$failure ||= check_source() if $check_all || $check_source;
|
|
|
|
$failure ||= check_comments() if $check_all || $check_comments;
|
2019-10-27 15:19:02 +00:00
|
|
|
$failure ||= check_doc() if $check_all || $check_doc;
|
2018-12-02 13:27:53 +00:00
|
|
|
$failure ||= process_makefiles(0) if $check_all || $check_makefiles;
|
2019-06-06 16:15:19 +00:00
|
|
|
$failure ||= process_makefiles(1) if $update_files;
|
|
|
|
$failure ||= update_dep() if $update_files;
|
|
|
|
$failure ||= generate_def() if $update_files;
|
2018-12-02 13:27:53 +00:00
|
|
|
|
|
|
|
die_usage unless defined $failure;
|
|
|
|
exit $failure ? 1 : 0;
|