Merge pull request #300 from libtom/interop-mingw-w64-3 Better interoperability between MSVC and mingw-w64, 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
diff --git a/generate_def.sh b/generate_def.sh
new file mode 100755
index 0000000..fc8f2fb
--- /dev/null
+++ b/generate_def.sh
@@ -0,0 +1,9 @@
+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 27e1451..e0baeb0 100755
--- a/helper.pl
+++ b/helper.pl
@@ -436,6 +436,10 @@ EOS
return 0;
}
+sub generate_def {
+ system("sh", "generate_def.sh");
+}
+
sub die_usage {
die <<"MARKER";
usage: $0 -s OR $0 --check-source
@@ -462,6 +466,7 @@ $failure ||= check_doc() if $check_doc; # temporarily excluded from --c
$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;
die_usage unless defined $failure;
exit $failure ? 1 : 0;
diff --git a/makefile.mingw b/makefile.mingw
index 05bae1f..f46f930 100644
--- a/makefile.mingw
+++ b/makefile.mingw
@@ -21,7 +21,7 @@ LDFLAGS =
#Compilation flags
LTM_CFLAGS = -I. $(CFLAGS)
-LTM_LDFLAGS = $(LDFLAGS)
+LTM_LDFLAGS = $(LDFLAGS) -static-libgcc
#Libraries to be created
LIBMAIN_S =libtommath.a
diff --git a/tommath.def b/tommath.def
new file mode 100755
index 0000000..8258c65
--- /dev/null
+++ b/tommath.def
@@ -0,0 +1,136 @@
+; 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
+ mp_2expt
+ mp_abs
+ mp_add
+ mp_add_d
+ mp_addmod
+ mp_and
+ mp_clamp
+ mp_clear
+ mp_clear_multi
+ mp_cmp
+ mp_cmp_d
+ mp_cmp_mag
+ mp_cnt_lsb
+ mp_complement
+ mp_copy
+ mp_count_bits
+ mp_decr
+ mp_div_2
+ mp_div_2d
+ mp_div_3
+ mp_div
+ mp_div_d
+ mp_dr_is_modulus
+ mp_dr_reduce
+ mp_dr_setup
+ mp_error_to_string
+ mp_exch
+ mp_export
+ mp_expt_d
+ mp_exptmod
+ mp_exteuclid
+ mp_fread
+ mp_fwrite
+ mp_gcd
+ mp_get_double
+ mp_get_i32
+ mp_get_i64
+ mp_get_int
+ mp_get_long
+ mp_get_long_long
+ mp_get_mag32
+ mp_get_mag64
+ mp_grow
+ mp_ilogb
+ mp_import
+ mp_incr
+ mp_init
+ mp_init_copy
+ mp_init_i32
+ mp_init_i64
+ mp_init_multi
+ mp_init_set
+ mp_init_set_int
+ mp_init_size
+ mp_init_u32
+ mp_init_u64
+ mp_invmod
+ mp_iseven
+ mp_isodd
+ mp_is_square
+ mp_kronecker
+ mp_lcm
+ mp_lshd
+ mp_mod_2d
+ mp_mod
+ mp_mod_d
+ mp_montgomery_calc_normalization
+ mp_montgomery_reduce
+ mp_montgomery_setup
+ mp_mul_2
+ mp_mul_2d
+ mp_mul
+ mp_mul_d
+ mp_mulmod
+ mp_neg
+ mp_n_root
+ mp_or
+ mp_prime_fermat
+ mp_prime_frobenius_underwood
+ mp_prime_is_prime
+ mp_prime_miller_rabin
+ mp_prime_next_prime
+ mp_prime_rabin_miller_trials
+ mp_prime_rand
+ 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_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
+ mp_rshd
+ mp_set
+ mp_set_double
+ mp_set_i32
+ mp_set_i64
+ mp_set_int
+ mp_set_long
+ mp_set_long_long
+ mp_set_u32
+ mp_set_u64
+ mp_shrink
+ mp_signed_bin_size
+ mp_signed_rsh
+ mp_sqr
+ mp_sqrmod
+ mp_sqrt
+ mp_sqrtmod_prime
+ 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_unsigned_bin_size
+ mp_xor
+ mp_zero
diff --git a/tommath.h b/tommath.h
index 4fdbd60..41e93ec 100644
--- a/tommath.h
+++ b/tommath.h
@@ -21,7 +21,7 @@ extern "C" {
#endif
/* MS Visual C++ doesn't have a 128bit type for words, so fall back to 32bit MPI's (where words are 64bit) */
-#if defined(_MSC_VER) || defined(__LLP64__) || defined(__e2k__) || defined(__LCC__)
+#if (defined(_MSC_VER) || defined(__LLP64__) || defined(__e2k__) || defined(__LCC__)) && !defined(MP_64BIT)
# define MP_32BIT
#endif
@@ -32,7 +32,7 @@ extern "C" {
defined(__sparcv9) || defined(__sparc_v9__) || defined(__sparc64__) || \
defined(__ia64) || defined(__ia64__) || defined(__itanium__) || defined(_M_IA64) || \
defined(__LP64__) || defined(_LP64) || defined(__64BIT__)
-# if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT))
+# if !(defined(MP_64BIT) || defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT))
# if defined(__GNUC__) && !defined(__hppa)
/* we support 128bit integers only via: __attribute__((mode(TI))) */
# define MP_64BIT
@@ -67,7 +67,9 @@ typedef uint32_t private_mp_word;
#elif defined(MP_64BIT)
/* for GCC only on supported platforms */
typedef uint64_t mp_digit;
+#if defined(__GNUC__)
typedef unsigned long private_mp_word __attribute__((mode(TI)));
+#endif
# define MP_DIGIT_BIT 60
#else
typedef uint32_t mp_digit;