Commit f00cc99f8c250760308d2a12b9407f58ab2caa16

Daniel Mendler 2019-06-06T18:15:19

replace generate_def.sh with perl function

diff --git a/generate_def.sh b/generate_def.sh
deleted file mode 100755
index fc8f2fb..0000000
--- a/generate_def.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-echo "; libtommath" >tommath.def
-echo ";" >>tommath.def
-echo "; Use this command to produce a 32-bit .lib file, for use in any MSVC version" >>tommath.def
-echo ";   lib -machine:X86 -name:libtommath.dll -def:tommath.def -out:tommath.lib" >>tommath.def
-echo "; Use this command to produce a 64-bit .lib file, for use in any MSVC version" >>tommath.def
-echo ";   lib -machine:X64 -name:libtommath.dll -def:tommath.def -out:tommath.lib" >>tommath.def
-echo ";" >>tommath.def
-echo "EXPORTS" >>tommath.def
-git ls-files|grep \\.c|sed -e 's/bn_mp_rand/bn_mp_rand\nbn_mp_rand_digit/'|sed -e 's/bn_conversion/bn_mp_set_i32\nbn_mp_set_i64\nbn_mp_set_u32\nbn_mp_set_u64\nbn_mp_set_int\nbn_mp_set_long\nbn_mp_set_long_long\nbn_mp_get_i32\nbn_mp_get_i64\nbn_mp_get_mag32\nbn_mp_get_mag64\nbn_mp_get_int\nbn_mp_get_long\nbn_mp_get_long_long\nbn_mp_init_i32\nbn_mp_init_i64\nbn_mp_init_u32\nbn_mp_init_u64\nbn_mp_init_set_int/'|grep -v bn_mp_radix_smap|grep bn_mp_|sort|sed -e 's/bn_/    /g'|sed -e 's/\.c//g'>>tommath.def
diff --git a/helper.pl b/helper.pl
index e0baeb0..ab3a4a0 100755
--- a/helper.pl
+++ b/helper.pl
@@ -437,7 +437,26 @@ EOS
 }
 
 sub generate_def {
-  system("sh", "generate_def.sh");
+    my @files = split /\n/, `git ls-files`;
+    @files = grep(/\.c/, @files);
+    @files = map { my $x = $_; $x =~ s/^bn_|\.c$//g; $x; } @files;
+    @files = grep(!/mp_radix_smap/, @files);
+
+    @files = grep(!/conversion/, @files);
+    push(@files, qw(mp_set_i32 mp_set_i64 mp_set_u32 mp_set_u64 mp_set_int mp_set_long mp_set_long_long mp_get_i32 mp_get_i64 mp_get_mag32 mp_get_mag64 mp_get_int mp_get_long mp_get_long_long mp_init_i32 mp_init_i64 mp_init_u32 mp_init_u64 mp_init_set_int));
+
+    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;
 }
 
 sub die_usage {
@@ -446,7 +465,7 @@ usage: $0 -s   OR   $0 --check-source
        $0 -o   OR   $0 --check-comments
        $0 -m   OR   $0 --check-makefiles
        $0 -a   OR   $0 --check-all
-       $0 -u   OR   $0 --update-makefiles
+       $0 -u   OR   $0 --update-files
 MARKER
 }
 
@@ -455,7 +474,7 @@ GetOptions( "s|check-source"        => \my $check_source,
             "m|check-makefiles"     => \my $check_makefiles,
             "d|check-doc"           => \my $check_doc,
             "a|check-all"           => \my $check_all,
-            "u|update-makefiles"    => \my $update_makefiles,
+            "u|update-files"        => \my $update_files,
             "h|help"                => \my $help
           ) or die_usage;
 
@@ -464,9 +483,9 @@ $failure ||= check_source()       if $check_all || $check_source;
 $failure ||= check_comments()     if $check_all || $check_comments;
 $failure ||= check_doc()          if $check_doc; # temporarily excluded from --check-all
 $failure ||= process_makefiles(0) if $check_all || $check_makefiles;
-$failure ||= process_makefiles(1) if $update_makefiles;
-$failure ||= update_dep()         if $update_makefiles;
-$failure ||= generate_def()       if $update_makefiles;
+$failure ||= process_makefiles(1) if $update_files;
+$failure ||= update_dep()         if $update_files;
+$failure ||= generate_def()       if $update_files;
 
 die_usage unless defined $failure;
 exit $failure ? 1 : 0;
diff --git a/makefile b/makefile
index d7619f2..e1828da 100644
--- a/makefile
+++ b/makefile
@@ -149,7 +149,7 @@ zipup: clean astyle new_file manual poster docs
 	gpg -b -a ltm-$(VERSION).zip
 
 new_file:
-	perl helper.pl --update-makefiles
+	perl helper.pl --update-files
 
 perlcritic:
 	perlcritic *.pl doc/*.pl
diff --git a/testme.sh b/testme.sh
index 0e035ce..df1b60b 100755
--- a/testme.sh
+++ b/testme.sh
@@ -295,8 +295,8 @@ if [[ "$CHECK_FORMAT" == "1" ]]
 then
   make astyle
   _check_git "make astyle"
-  perl helper.pl --update-makefiles
-  _check_git "helper.pl --update-makefiles"
+  perl helper.pl --update-files
+  _check_git "helper.pl --update-files"
   perl helper.pl --check-all
   _check_git "helper.pl --check-all"
   exit $?
diff --git a/tommath.def b/tommath.def
index 8258c65..7f061ed 100755
--- a/tommath.def
+++ b/tommath.def
@@ -23,10 +23,10 @@ EXPORTS
     mp_copy
     mp_count_bits
     mp_decr
+    mp_div
     mp_div_2
     mp_div_2d
     mp_div_3
-    mp_div
     mp_div_d
     mp_dr_is_modulus
     mp_dr_reduce
@@ -63,25 +63,25 @@ EXPORTS
     mp_init_u32
     mp_init_u64
     mp_invmod
+    mp_is_square
     mp_iseven
     mp_isodd
-    mp_is_square
     mp_kronecker
     mp_lcm
     mp_lshd
-    mp_mod_2d
     mp_mod
+    mp_mod_2d
     mp_mod_d
     mp_montgomery_calc_normalization
     mp_montgomery_reduce
     mp_montgomery_setup
+    mp_mul
     mp_mul_2
     mp_mul_2d
-    mp_mul
     mp_mul_d
     mp_mulmod
-    mp_neg
     mp_n_root
+    mp_neg
     mp_or
     mp_prime_fermat
     mp_prime_frobenius_underwood
@@ -93,15 +93,14 @@ EXPORTS
     mp_prime_strong_lucas_selfridge
     mp_radix_size
     mp_rand
-    mp_rand_digit
     mp_read_radix
     mp_read_signed_bin
     mp_read_unsigned_bin
+    mp_reduce
     mp_reduce_2k
     mp_reduce_2k_l
     mp_reduce_2k_setup
     mp_reduce_2k_setup_l
-    mp_reduce
     mp_reduce_is_2k
     mp_reduce_is_2k_l
     mp_reduce_setup
@@ -125,12 +124,12 @@ EXPORTS
     mp_sub
     mp_sub_d
     mp_submod
-    mp_toradix
-    mp_toradix_n
     mp_to_signed_bin
     mp_to_signed_bin_n
     mp_to_unsigned_bin
     mp_to_unsigned_bin_n
+    mp_toradix
+    mp_toradix_n
     mp_unsigned_bin_size
     mp_xor
     mp_zero