summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-12-13 11:05:43 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-12-13 11:05:43 (GMT)
commit6fdc83ae1490b9c80fdce1c5fc60af2ce84a08f0 (patch)
tree706c6b580a9bc0024596eed55ea34254b98a5756 /unix
parentdb35fe50e94b2e2edd00d34c42c74754cfc5c74d (diff)
parent17a9125415985348b7d2b12e75a50a8c87cc21bb (diff)
downloadtcl-6fdc83ae1490b9c80fdce1c5fc60af2ce84a08f0.zip
tcl-6fdc83ae1490b9c80fdce1c5fc60af2ce84a08f0.tar.gz
tcl-6fdc83ae1490b9c80fdce1c5fc60af2ce84a08f0.tar.bz2
Implement TIP's #538: Externalize libtommath
Diffstat (limited to 'unix')
-rw-r--r--unix/Makefile.in61
-rwxr-xr-xunix/configure119
-rw-r--r--unix/configure.ac25
-rw-r--r--unix/tcl.m42
-rw-r--r--unix/tclConfig.h.in6
-rw-r--r--unix/tclUnixPort.h2
6 files changed, 166 insertions, 49 deletions
diff --git a/unix/Makefile.in b/unix/Makefile.in
index 838da2a..c971ab6 100644
--- a/unix/Makefile.in
+++ b/unix/Makefile.in
@@ -229,7 +229,6 @@ SRC_DIR = @srcdir@
TOP_DIR = @TCL_SRC_DIR@
BUILD_DIR = @builddir@
GENERIC_DIR = $(TOP_DIR)/generic
-TOMMATH_DIR = $(TOP_DIR)/libtommath
COMPAT_DIR = $(TOP_DIR)/compat
TOOL_DIR = $(TOP_DIR)/tools
UNIX_DIR = $(TOP_DIR)/unix
@@ -242,6 +241,8 @@ TCL_BUILDTIME_LIBRARY = @TCL_SRC_DIR@/library
ZLIB_DIR = ${COMPAT_DIR}/zlib
ZLIB_INCLUDE = @ZLIB_INCLUDE@
+TOMMATH_DIR = $(TOP_DIR)/libtommath
+TOMMATH_INCLUDE = @TOMMATH_INCLUDE@
CC = @CC@
OBJEXT = @OBJEXT@
@@ -328,16 +329,17 @@ TOMMATH_OBJS = bn_s_mp_reverse.o bn_s_mp_mul_digs_fast.o \
bn_mp_cnt_lsb.o bn_mp_copy.o \
bn_mp_count_bits.o bn_mp_div.o bn_mp_div_d.o bn_mp_div_2.o \
bn_mp_div_2d.o bn_mp_div_3.o bn_mp_exch.o bn_mp_expt_u32.o \
- bn_mp_get_mag_ul.o bn_mp_grow.o bn_mp_init.o \
+ bn_mp_get_mag_u64.o \
+ bn_mp_grow.o bn_mp_init.o \
bn_mp_init_copy.o bn_mp_init_multi.o bn_mp_init_set.o \
- bn_mp_init_size.o bn_mp_init_ul.o bn_s_mp_karatsuba_mul.o \
- bn_mp_init_l.o bn_mp_init_ll.o bn_mp_init_ull.o \
+ bn_mp_init_size.o bn_s_mp_karatsuba_mul.o \
+ bn_mp_init_i64.o bn_mp_init_u64.o \
bn_s_mp_karatsuba_sqr.o bn_s_mp_balance_mul.o \
bn_mp_lshd.o bn_mp_mod.o bn_mp_mod_2d.o bn_mp_mul.o bn_mp_mul_2.o \
bn_mp_mul_2d.o bn_mp_mul_d.o bn_mp_neg.o bn_mp_or.o \
- bn_mp_radix_size.o bn_mp_radix_smap.o \
- bn_mp_read_radix.o bn_mp_rshd.o bn_mp_set.o bn_mp_set_ul.o \
- bn_mp_shrink.o bn_mp_set_l.o \
+ bn_mp_radix_size.o bn_mp_radix_smap.o bn_mp_set_i64.o \
+ bn_mp_read_radix.o bn_mp_rshd.o \
+ bn_mp_set_u64.o bn_mp_shrink.o \
bn_mp_sqr.o bn_mp_sqrt.o bn_mp_sub.o bn_mp_sub_d.o \
bn_mp_signed_rsh.o \
bn_mp_to_ubin.o \
@@ -369,7 +371,7 @@ ZLIB_OBJS = Zadler32.o Zcompress.o Zcrc32.o Zdeflate.o Zinfback.o \
TCL_OBJS = ${GENERIC_OBJS} ${UNIX_OBJS} ${NOTIFY_OBJS} ${COMPAT_OBJS} \
${OO_OBJS} @DL_OBJS@ @PLAT_OBJS@
-OBJS = ${TCL_OBJS} ${TOMMATH_OBJS} @DTRACE_OBJ@ @ZLIB_OBJS@
+OBJS = ${TCL_OBJS} @DTRACE_OBJ@ @ZLIB_OBJS@ @TOMMATH_OBJS@
TCL_DECLS = \
$(GENERIC_DIR)/tcl.decls \
@@ -712,8 +714,8 @@ ZLIB_SRCS = \
# won't compile on the current machine, and they will cause problems for
# things like "make depend".
-SRCS = $(GENERIC_SRCS) $(TOMMATH_SRCS) $(UNIX_SRCS) $(NOTIFY_SRCS) \
- $(OO_SRCS) $(STUB_SRCS) @PLAT_SRCS@ @ZLIB_SRCS@
+SRCS = $(GENERIC_SRCS) $(UNIX_SRCS) $(NOTIFY_SRCS) \
+ $(OO_SRCS) $(STUB_SRCS) @PLAT_SRCS@ @ZLIB_SRCS@ @TOMMATH_SRCS@
###
# Tip 430 - ZipFS Modifications
@@ -1215,7 +1217,7 @@ TCLREHDRS = $(GENERIC_DIR)/tclRegexp.h
COMPILEHDR = $(GENERIC_DIR)/tclCompile.h
FSHDR = $(GENERIC_DIR)/tclFileSystem.h
IOHDR = $(GENERIC_DIR)/tclIO.h
-MATHHDRS = $(GENERIC_DIR)/tommath.h $(GENERIC_DIR)/tclTomMath.h
+MATHHDRS = $(GENERIC_DIR)/tclTomMath.h $(GENERIC_DIR)/tclTomMathDecls.h
PARSEHDR = $(GENERIC_DIR)/tclParse.h
NREHDR = $(GENERIC_DIR)/tclInt.h
TRIMHDR = $(GENERIC_DIR)/tclStringTrim.h
@@ -1618,8 +1620,8 @@ bn_mp_exch.o: $(TOMMATH_DIR)/bn_mp_exch.c $(MATHHDRS)
bn_mp_expt_u32.o: $(TOMMATH_DIR)/bn_mp_expt_u32.c $(MATHHDRS)
$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_expt_u32.c
-bn_mp_get_mag_ul.o: $(TOMMATH_DIR)/bn_mp_get_mag_ul.c $(MATHHDRS)
- $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_get_mag_ul.c
+bn_mp_get_mag_u64.o: $(TOMMATH_DIR)/bn_mp_get_mag_u64.c $(MATHHDRS)
+ $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_get_mag_u64.c
bn_mp_grow.o: $(TOMMATH_DIR)/bn_mp_grow.c $(MATHHDRS)
$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_grow.c
@@ -1630,11 +1632,8 @@ bn_mp_init.o: $(TOMMATH_DIR)/bn_mp_init.c $(MATHHDRS)
bn_mp_init_copy.o: $(TOMMATH_DIR)/bn_mp_init_copy.c $(MATHHDRS)
$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_init_copy.c
-bn_mp_init_l.o:$(TOMMATH_DIR)/bn_mp_init_l.c $(MATHHDRS)
- $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_init_l.c
-
-bn_mp_init_ll.o:$(TOMMATH_DIR)/bn_mp_init_ll.c $(MATHHDRS)
- $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_init_ll.c
+bn_mp_init_i64.o:$(TOMMATH_DIR)/bn_mp_init_i64.c $(MATHHDRS)
+ $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_init_i64.c
bn_mp_init_multi.o: $(TOMMATH_DIR)/bn_mp_init_multi.c $(MATHHDRS)
$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_init_multi.c
@@ -1645,11 +1644,8 @@ bn_mp_init_set.o: $(TOMMATH_DIR)/bn_mp_init_set.c $(MATHHDRS)
bn_mp_init_size.o:$(TOMMATH_DIR)/bn_mp_init_size.c $(MATHHDRS)
$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_init_size.c
-bn_mp_init_ul.o:$(TOMMATH_DIR)/bn_mp_init_ul.c $(MATHHDRS)
- $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_init_ul.c
-
-bn_mp_init_ull.o:$(TOMMATH_DIR)/bn_mp_init_ull.c $(MATHHDRS)
- $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_init_ull.c
+bn_mp_init_u64.o:$(TOMMATH_DIR)/bn_mp_init_u64.c $(MATHHDRS)
+ $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_init_u64.c
bn_s_mp_karatsuba_mul.o: $(TOMMATH_DIR)/bn_s_mp_karatsuba_mul.c $(MATHHDRS)
$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_s_mp_karatsuba_mul.c
@@ -1699,14 +1695,11 @@ bn_mp_read_radix.o: $(TOMMATH_DIR)/bn_mp_read_radix.c $(MATHHDRS)
bn_mp_rshd.o: $(TOMMATH_DIR)/bn_mp_rshd.c $(MATHHDRS)
$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_rshd.c
-bn_mp_set.o: $(TOMMATH_DIR)/bn_mp_set.c $(MATHHDRS)
- $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_set.c
+bn_mp_set_i64.o: $(TOMMATH_DIR)/bn_mp_set_i64.c $(MATHHDRS)
+ $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_set_i64.c
-bn_mp_set_l.o: $(TOMMATH_DIR)/bn_mp_set_l.c $(MATHHDRS)
- $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_set_l.c
-
-bn_mp_set_ul.o: $(TOMMATH_DIR)/bn_mp_set_ul.c $(MATHHDRS)
- $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_set_ul.c
+bn_mp_set_u64.o: $(TOMMATH_DIR)/bn_mp_set_u64.c $(MATHHDRS)
+ $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_set_u64.c
bn_mp_shrink.o: $(TOMMATH_DIR)/bn_mp_shrink.c $(MATHHDRS)
$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_shrink.c
@@ -2100,14 +2093,6 @@ gendate:
# <y.tab.c >$(GENERIC_DIR)/tclDate.c
# rm y.tab.c
-# The following target generates the file generic/tclTomMath.h. It needs to be
-# run (and the results checked) after updating to a new release of libtommath.
-
-gentommath_h:
- $(NATIVE_TCLSH) "$(TOOL_DIR)/fix_tommath_h.tcl" \
- "$(TOMMATH_DIR)/tommath.h" \
- > "$(GENERIC_DIR)/tclTomMath.h"
-
#
# Target to regenerate header files and stub files from the *.decls tables.
#
diff --git a/unix/configure b/unix/configure
index d653b98..dfbd8a8 100755
--- a/unix/configure
+++ b/unix/configure
@@ -705,6 +705,9 @@ TCL_LIBS
LIBOBJS
AR
RANLIB
+TOMMATH_INCLUDE
+TOMMATH_SRCS
+TOMMATH_OBJS
ZLIB_INCLUDE
ZLIB_SRCS
ZLIB_OBJS
@@ -768,6 +771,7 @@ enable_man_compression
enable_man_suffix
with_encoding
enable_shared
+with_system_libtommath
enable_64bit
enable_64bit_vis
enable_rpath
@@ -1427,6 +1431,9 @@ Optional Packages:
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-encoding encoding for configuration values (default:
iso8859-1)
+ --with-system-libtommath
+ use external libtommath (default: true if available,
+ false otherwise)
--with-tzdata install timezone data (default: autodetect)
Some influential environment variables:
@@ -4644,6 +4651,115 @@ fi
$as_echo "#define HAVE_ZLIB 1" >>confdefs.h
+#------------------------------------------------------------------------
+# Add stuff for libtommath
+
+libtommath_ok=yes
+
+# Check whether --with-system-libtommath was given.
+if test "${with_system_libtommath+set}" = set; then :
+ withval=$with_system_libtommath; libtommath_ok=${withval}
+fi
+
+if test x"${libtommath_ok}" == x -o x"${libtommath_ok}" != xno; then
+ ac_fn_c_check_header_mongrel "$LINENO" "tommath.h" "ac_cv_header_tommath_h" "$ac_includes_default"
+if test "x$ac_cv_header_tommath_h" = xyes; then :
+
+ ac_fn_c_check_type "$LINENO" "mp_int" "ac_cv_type_mp_int" "#include <tommath.h>
+"
+if test "x$ac_cv_type_mp_int" = xyes; then :
+
+else
+ libtommath_ok=no
+fi
+
+else
+
+ libtommath_ok=no
+fi
+
+
+ if test $libtommath_ok = yes; then :
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing mp_log_u32" >&5
+$as_echo_n "checking for library containing mp_log_u32... " >&6; }
+if ${ac_cv_search_mp_log_u32+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char mp_log_u32 ();
+int
+main ()
+{
+return mp_log_u32 ();
+ ;
+ return 0;
+}
+_ACEOF
+for ac_lib in '' tommath; do
+ if test -z "$ac_lib"; then
+ ac_res="none required"
+ else
+ ac_res=-l$ac_lib
+ LIBS="-l$ac_lib $ac_func_search_save_LIBS"
+ fi
+ if ac_fn_c_try_link "$LINENO"; then :
+ ac_cv_search_mp_log_u32=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext
+ if ${ac_cv_search_mp_log_u32+:} false; then :
+ break
+fi
+done
+if ${ac_cv_search_mp_log_u32+:} false; then :
+
+else
+ ac_cv_search_mp_log_u32=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_mp_log_u32" >&5
+$as_echo "$ac_cv_search_mp_log_u32" >&6; }
+ac_res=$ac_cv_search_mp_log_u32
+if test "$ac_res" != no; then :
+ test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+else
+
+ libtommath_ok=no
+
+fi
+
+fi
+fi
+if test $libtommath_ok = yes; then :
+
+
+$as_echo "#define TCL_WITH_EXTERNAL_TOMMATH 1" >>confdefs.h
+
+
+else
+
+ TOMMATH_OBJS=\${TOMMATH_OBJS}
+
+ TOMMATH_SRCS=\${TOMMATH_SRCS}
+
+ TOMMATH_INCLUDE=-I\${TOMMATH_DIR}
+
+
+fi
+
#--------------------------------------------------------------------
# The statements below define a collection of compile flags. This
# macro depends on the value of SHARED_BUILD, and should be called
@@ -6895,9 +7011,6 @@ fi
if test "${tcl_cv_type_64bit}" = none ; then
-$as_echo "#define MP_32BIT 1" >>confdefs.h
-
-
$as_echo "#define TCL_WIDE_INT_IS_LONG 1" >>confdefs.h
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
diff --git a/unix/configure.ac b/unix/configure.ac
index c791df4..a5cb12b 100644
--- a/unix/configure.ac
+++ b/unix/configure.ac
@@ -167,6 +167,31 @@ AS_IF([test $zlib_ok = no], [
])
AC_DEFINE(HAVE_ZLIB, 1, [Is there an installed zlib?])
+#------------------------------------------------------------------------
+# Add stuff for libtommath
+
+libtommath_ok=yes
+AC_ARG_WITH(system-libtommath,
+AC_HELP_STRING([--with-system-libtommath],
+ [use external libtommath (default: true if available, false otherwise)]),
+ libtommath_ok=${withval})
+if test x"${libtommath_ok}" == x -o x"${libtommath_ok}" != xno; then
+ AC_CHECK_HEADER([tommath.h],[
+ AC_CHECK_TYPE([mp_int],[],[libtommath_ok=no],[#include <tommath.h>])],[
+ libtommath_ok=no])
+ AS_IF([test $libtommath_ok = yes], [
+ AC_SEARCH_LIBS([mp_log_u32],[tommath],[],[
+ libtommath_ok=no
+ ])])
+fi
+AS_IF([test $libtommath_ok = yes], [
+ AC_DEFINE(TCL_WITH_EXTERNAL_TOMMATH, 1, [Tcl with external libtommath])
+], [
+ AC_SUBST(TOMMATH_OBJS,[\${TOMMATH_OBJS}])
+ AC_SUBST(TOMMATH_SRCS,[\${TOMMATH_SRCS}])
+ AC_SUBST(TOMMATH_INCLUDE,[-I\${TOMMATH_DIR}])
+])
+
#--------------------------------------------------------------------
# The statements below define a collection of compile flags. This
# macro depends on the value of SHARED_BUILD, and should be called
diff --git a/unix/tcl.m4 b/unix/tcl.m4
index 1ee1617..a38ae92 100644
--- a/unix/tcl.m4
+++ b/unix/tcl.m4
@@ -2370,7 +2370,6 @@ AC_DEFUN([SC_TCL_EARLY_FLAGS],[
# HAVE_STRUCT_DIRENT64, HAVE_DIR64
# HAVE_STRUCT_STAT64
# HAVE_TYPE_OFF64_T
-# MP_32BIT
#
#--------------------------------------------------------------------
@@ -2388,7 +2387,6 @@ AC_DEFUN([SC_TCL_64BIT_FLAGS], [
case 1: case (sizeof(]${tcl_type_64bit}[)==sizeof(long)): ;
}],tcl_cv_type_64bit=${tcl_type_64bit})])
if test "${tcl_cv_type_64bit}" = none ; then
- AC_DEFINE(MP_32BIT, 1, [Use 'MP_32BIT' for libtommath])
AC_DEFINE(TCL_WIDE_INT_IS_LONG, 1, [Do 'long' and 'long long' have the same size (64-bit)?])
AC_MSG_RESULT([yes])
else
diff --git a/unix/tclConfig.h.in b/unix/tclConfig.h.in
index 574c920..fb29a32 100644
--- a/unix/tclConfig.h.in
+++ b/unix/tclConfig.h.in
@@ -307,12 +307,6 @@
/* No Compiler support for module scope symbols */
#undef MODULE_SCOPE
-/* Use 'MP_32BIT' for libtommath */
-#undef MP_32BIT
-
-/* Default libtommath precision. */
-#undef MP_PREC
-
/* Is no debugging enabled? */
#undef NDEBUG
diff --git a/unix/tclUnixPort.h b/unix/tclUnixPort.h
index db38fd3..d7005db 100644
--- a/unix/tclUnixPort.h
+++ b/unix/tclUnixPort.h
@@ -155,6 +155,8 @@ typedef off_t Tcl_SeekOffset;
#include <limits.h>
#ifdef HAVE_STDINT_H
# include <stdint.h>
+#else
+# include "../compat/stdint.h"
#endif
#include <unistd.h>