enable building dll's using makefile.msvc
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
diff --git a/.gitignore b/.gitignore
index 61495ec..696e0ec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,9 @@
*.gcda
*.gcno
*.gcov
+*.dll
+*.exp
+*.pdb
*.lib
*.tmp
[Dd]ebug/
diff --git a/makefile.msvc b/makefile.msvc
index 031f1c8..43e2bd2 100644
--- a/makefile.msvc
+++ b/makefile.msvc
@@ -12,13 +12,16 @@
#The following can be overridden from command line e.g. make -f makefile.msvc CC=gcc ARFLAGS=rcs
PREFIX = c:\devel
CFLAGS = /Ox
+LDFLAGS =
#Compilation flags
LTM_CFLAGS = /nologo /I./ /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /D__STDC_WANT_SECURE_LIB__=1 /D_CRT_HAS_CXX17=0 /Wall /wd4146 /wd4127 /wd4668 /wd4710 /wd4711 /wd4820 /wd5045 /WX $(CFLAGS)
-LTM_LDFLAGS = advapi32.lib
+LTM_LDFLAGS = $(LDFLAGS) advapi32.lib
-#Libraries to be created (this makefile builds only static libraries)
-LIBMAIN_S =tommath.lib
+#Libraries to be created
+LIBMAIN_S = tommath.lib
+LIBMAIN_I = tommath.dll.lib
+LIBMAIN_D = tommath.dll
#List of objects to compile (all goes to tommath.lib)
OBJECTS=mp_2expt.obj mp_abs.obj mp_add.obj mp_add_d.obj mp_addmod.obj mp_and.obj mp_clamp.obj mp_clear.obj mp_clear_multi.obj \
@@ -62,12 +65,16 @@ $(OBJECTS): $(HEADERS)
$(LIBMAIN_S): $(OBJECTS)
lib /out:$(LIBMAIN_S) $(OBJECTS)
+#Create DLL + import library tommath.dll.lib
+$(LIBMAIN_D) $(LIBMAIN_I): $(OBJECTS) tommath.def
+ link /dll /out:$(LIBMAIN_D) /implib:$(LIBMAIN_I) /def:tommath.def $(LTM_LDFLAGS) $(OBJECTS)
+
#Build test suite
test.exe: $(LIBMAIN_S) demo/shared.obj demo/test.obj
cl $(LTM_CFLAGS) $(TOBJECTS) $(LIBMAIN_S) $(LTM_LDFLAGS) demo/shared.c demo/test.c /Fe$@
@echo NOTICE: start the tests by launching test.exe
-all: $(LIBMAIN_S) test.exe
+all: $(LIBMAIN_S) test.exe $(LIBMAIN_D)
tune: $(LIBMAIN_S)
$(MAKE) -C etc tune
@@ -77,9 +84,11 @@ clean:
@-cmd /c del /Q /S *.OBJ *.LIB *.EXE *.DLL 2>nul
#Install the library + headers
-install: $(LIBMAIN_S)
+install: $(LIBMAIN_S) $(LIBMAIN_I) $(LIBMAIN_D)
cmd /c if not exist "$(PREFIX)\bin" mkdir "$(PREFIX)\bin"
cmd /c if not exist "$(PREFIX)\lib" mkdir "$(PREFIX)\lib"
cmd /c if not exist "$(PREFIX)\include" mkdir "$(PREFIX)\include"
copy /Y $(LIBMAIN_S) "$(PREFIX)\lib"
+ copy /Y $(LIBMAIN_I) "$(PREFIX)\lib"
+ copy /Y $(LIBMAIN_D) "$(PREFIX)\bin"
copy /Y tommath*.h "$(PREFIX)\include"
diff --git a/s_mp_rand_platform.c b/s_mp_rand_platform.c
index 06b2f1b..f4d6812 100644
--- a/s_mp_rand_platform.c
+++ b/s_mp_rand_platform.c
@@ -14,6 +14,13 @@ static mp_err s_read_arc4random(void *p, size_t n)
arc4random_buf(p, n);
return MP_OKAY;
}
+#else
+static mp_err s_read_arc4random(void *p, size_t n)
+{
+ (void)p;
+ (void)n;
+ return MP_ERR;
+}
#endif
#if defined(_WIN32)
@@ -72,6 +79,15 @@ static mp_err s_read_getrandom(void *p, size_t n)
#endif
#endif
+#ifndef S_READ_GETRANDOM_C
+static mp_err s_read_getrandom(void *p, size_t n)
+{
+ (void)p;
+ (void)n;
+ return MP_ERR;
+}
+#endif
+
/* We assume all platforms besides windows provide "/dev/urandom".
* In case yours doesn't, define MP_NO_DEV_URANDOM at compile-time.
*/
@@ -110,6 +126,13 @@ static mp_err s_read_urandom(void *p, size_t n)
close(fd);
return MP_OKAY;
}
+#else
+static mp_err s_read_urandom(void *p, size_t n)
+{
+ (void)p;
+ (void)n;
+ return MP_ERR;
+}
#endif
mp_err s_read_arc4random(void *p, size_t n);
diff --git a/tommath.def b/tommath.def
index 7d53508..f0a9703 100644
--- a/tommath.def
+++ b/tommath.def
@@ -89,6 +89,7 @@ EXPORTS
mp_radix_size
mp_radix_size_overestimate
mp_rand
+ mp_rand_source
mp_read_radix
mp_reduce
mp_reduce_2k
@@ -124,3 +125,7 @@ EXPORTS
mp_unpack
mp_xor
mp_zero
+ MP_MUL_KARATSUBA_CUTOFF
+ MP_SQR_KARATSUBA_CUTOFF
+ MP_MUL_TOOM_CUTOFF
+ MP_SQR_TOOM_CUTOFF