summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2013-01-26 08:02:42 +0000
committerSimon Marlow <marlowsd@gmail.com>2013-01-26 08:02:42 +0000
commit916be615048cc844498319f4a21cc62bec162cd8 (patch)
treed8b09e4d6e8c0eb0f72be25f4d6179dbdae9f2c1
parent52f554582339d14c28a3cc91385f9cb0343f6779 (diff)
downloadhaskell-916be615048cc844498319f4a21cc62bec162cd8.tar.gz
Revert "integer-gmp: improve cross-compiling support GmpDerivedConstants.h"
This reverts commit 860f2fa9a1f1ca4f8d94388723687f90d122ae81. People reported problems with it on the mailing list, so reverting until we can figure out the cause.
-rw-r--r--libraries/integer-gmp/.gitignore1
-rw-r--r--libraries/integer-gmp/cbits/GmpDerivedConstants.h.in10
-rw-r--r--libraries/integer-gmp/cbits/mkGmpDerivedConstants.c74
-rw-r--r--libraries/integer-gmp/configure.ac28
-rw-r--r--libraries/integer-gmp/gmp/ghc.mk8
5 files changed, 87 insertions, 34 deletions
diff --git a/libraries/integer-gmp/.gitignore b/libraries/integer-gmp/.gitignore
index 56857e958e..012224d539 100644
--- a/libraries/integer-gmp/.gitignore
+++ b/libraries/integer-gmp/.gitignore
@@ -8,3 +8,4 @@ ghc.mk
gmp/config.mk
integer-gmp.buildinfo
cbits/GmpDerivedConstants.h
+cbits/mkGmpDerivedConstants
diff --git a/libraries/integer-gmp/cbits/GmpDerivedConstants.h.in b/libraries/integer-gmp/cbits/GmpDerivedConstants.h.in
deleted file mode 100644
index 241372f10d..0000000000
--- a/libraries/integer-gmp/cbits/GmpDerivedConstants.h.in
+++ /dev/null
@@ -1,10 +0,0 @@
-#define SIZEOF_MP_INT @SIZEOF_MP_INT@
-#define OFFSET_MP_INT__mp_alloc @OFFSET_MP_INT__mp_alloc@
-#define REP_MP_INT__mp_alloc b@REP_MP_INT__mp_alloc@
-#define MP_INT__mp_alloc(__ptr__) REP_MP_INT__mp_alloc[__ptr__+OFFSET_MP_INT__mp_alloc]
-#define OFFSET_MP_INT__mp_size @OFFSET_MP_INT__mp_size@
-#define REP_MP_INT__mp_size b@REP_MP_INT__mp_size@
-#define MP_INT__mp_size(__ptr__) REP_MP_INT__mp_size[__ptr__+OFFSET_MP_INT__mp_size]
-#define OFFSET_MP_INT__mp_d @OFFSET_MP_INT__mp_d@
-#define REP_MP_INT__mp_d b@REP_MP_INT__mp_d@
-#define MP_INT__mp_d(__ptr__) REP_MP_INT__mp_d[__ptr__+OFFSET_MP_INT__mp_d]
diff --git a/libraries/integer-gmp/cbits/mkGmpDerivedConstants.c b/libraries/integer-gmp/cbits/mkGmpDerivedConstants.c
new file mode 100644
index 0000000000..ed07111e06
--- /dev/null
+++ b/libraries/integer-gmp/cbits/mkGmpDerivedConstants.c
@@ -0,0 +1,74 @@
+/* --------------------------------------------------------------------------
+ *
+ * (c) The GHC Team, 1992-2004
+ *
+ * mkDerivedConstants.c
+ *
+ * Basically this is a C program that extracts information from the C
+ * declarations in the header files (primarily struct field offsets)
+ * and generates a header file that can be #included into non-C source
+ * containing this information.
+ *
+ * ------------------------------------------------------------------------*/
+
+#include <stdio.h>
+#include "gmp.h"
+
+
+#define str(a,b) #a "_" #b
+
+#define OFFSET(s_type, field) ((size_t)&(((s_type*)0)->field))
+
+/* struct_size(TYPE)
+ *
+ */
+#define def_size(str, size) \
+ printf("#define SIZEOF_" str " %lu\n", (unsigned long)size);
+
+#define struct_size(s_type) \
+ def_size(#s_type, sizeof(s_type));
+
+
+
+/* struct_field(TYPE, FIELD)
+ *
+ */
+#define def_offset(str, offset) \
+ printf("#define OFFSET_" str " %d\n", (int)(offset));
+
+#define field_offset_(str, s_type, field) \
+ def_offset(str, OFFSET(s_type,field));
+
+#define field_offset(s_type, field) \
+ field_offset_(str(s_type,field),s_type,field);
+
+#define field_type_(str, s_type, field) \
+ printf("#define REP_" str " b"); \
+ printf("%lu\n", (unsigned long)sizeof (__typeof__(((((s_type*)0)->field)))) * 8);
+
+#define field_type(s_type, field) \
+ field_type_(str(s_type,field),s_type,field);
+
+/* An access macro for use in C-- sources. */
+#define struct_field_macro(str) \
+ printf("#define " str "(__ptr__) REP_" str "[__ptr__+OFFSET_" str "]\n");
+
+/* Outputs the byte offset and MachRep for a field */
+#define struct_field(s_type, field) \
+ field_offset(s_type, field); \
+ field_type(s_type, field); \
+ struct_field_macro(str(s_type,field))
+
+
+int
+main(int argc, char *argv[])
+{
+ printf("/* This file is created automatically. Do not edit by hand.*/\n\n");
+
+ struct_size(MP_INT);
+ struct_field(MP_INT,_mp_alloc);
+ struct_field(MP_INT,_mp_size);
+ struct_field(MP_INT,_mp_d);
+
+ return 0;
+}
diff --git a/libraries/integer-gmp/configure.ac b/libraries/integer-gmp/configure.ac
index c99f9883e6..d7c0b3e9ac 100644
--- a/libraries/integer-gmp/configure.ac
+++ b/libraries/integer-gmp/configure.ac
@@ -1,5 +1,8 @@
AC_INIT([Haskell integer (GMP)], [0.1], [libraries@haskell.org], [integer])
+# Safety check: Ensure that we are in the correct source directory.
+AC_CONFIG_SRCDIR([cbits/mkGmpDerivedConstants.c])
+
AC_CANONICAL_TARGET
AC_ARG_WITH([cc],
@@ -63,30 +66,7 @@ AC_SUBST(GMP_FRAMEWORK)
AC_SUBST(HaveLibGmp)
AC_SUBST(HaveFrameworkGMP)
-dnl GMP_INT_TO_CONST(int_expr, var_name)
-AC_DEFUN([GMP_INT_TO_VAR],
-[
- AC_MSG_CHECKING([for $1 size])
- AC_COMPUTE_INT([$2], [$1],[[#include <stdio.h>
-#include <stddef.h>
-#include "gmp.h"
-
-#define FIELD_OFFSET(s_type, field) offsetof(s_type, field)
-#define FIELD_SIZE_BITS(s_type, field) (unsigned long)sizeof (__typeof__(((((s_type*)0)->field)))) * 8
-]], AC_MSG_ERROR([Failed to compute size of $1]))
- AC_MSG_RESULT($$2)
- AC_SUBST($2)
-])
-
-GMP_INT_TO_VAR([[sizeof (MP_INT)]], [SIZEOF_MP_INT])
-GMP_INT_TO_VAR([[FIELD_OFFSET(MP_INT,_mp_alloc)]], [OFFSET_MP_INT__mp_alloc])
-GMP_INT_TO_VAR([[FIELD_SIZE_BITS(MP_INT,_mp_alloc)]], [REP_MP_INT__mp_alloc])
-GMP_INT_TO_VAR([[FIELD_OFFSET(MP_INT,_mp_size)]], [OFFSET_MP_INT__mp_size])
-GMP_INT_TO_VAR([[FIELD_SIZE_BITS(MP_INT,_mp_size)]], [REP_MP_INT__mp_size])
-GMP_INT_TO_VAR([[FIELD_OFFSET(MP_INT,_mp_d)]], [OFFSET_MP_INT__mp_d])
-GMP_INT_TO_VAR([[FIELD_SIZE_BITS(MP_INT,_mp_d)]], [REP_MP_INT__mp_d])
-
-AC_CONFIG_FILES([integer-gmp.buildinfo gmp/config.mk cbits/GmpDerivedConstants.h])
+AC_CONFIG_FILES([integer-gmp.buildinfo gmp/config.mk])
dnl--------------------------------------------------------------------
dnl * Generate the header cbits/GmpDerivedConstants.h
diff --git a/libraries/integer-gmp/gmp/ghc.mk b/libraries/integer-gmp/gmp/ghc.mk
index 78c6683936..b39f36afdf 100644
--- a/libraries/integer-gmp/gmp/ghc.mk
+++ b/libraries/integer-gmp/gmp/ghc.mk
@@ -46,6 +46,12 @@ endif
libraries/integer-gmp_CC_OPTS += $(addprefix -I,$(GMP_INCLUDE_DIRS))
libraries/integer-gmp_CC_OPTS += $(addprefix -L,$(GMP_LIB_DIRS))
+libraries/integer-gmp/cbits/mkGmpDerivedConstants$(exeext): libraries/integer-gmp/cbits/mkGmpDerivedConstants.c
+ "$(CC_STAGE1)" $(SRC_CC_OPTS) $(CONF_CC_OPTS_STAGE1) $(libraries/integer-gmp_CC_OPTS) $< -o $@
+
+libraries/integer-gmp/cbits/GmpDerivedConstants.h: libraries/integer-gmp/cbits/mkGmpDerivedConstants$(exeext)
+ $< > $@
+
# Compile GMP only if we don't have it already
#
# We use GMP's own configuration stuff, because it's all rather hairy
@@ -80,6 +86,8 @@ ifneq "$(HaveLibGmp)" "YES"
ifneq "$(HaveFrameworkGMP)" "YES"
$(libraries/integer-gmp_dist-install_depfile_c_asm): libraries/integer-gmp/gmp/gmp.h
+libraries/integer-gmp/cbits/mkGmpDerivedConstants$(exeext): libraries/integer-gmp/gmp/gmp.h
+
libraries/integer-gmp_CC_OPTS += -I$(TOP)/libraries/integer-gmp/gmp
libraries/integer-gmp_dist-install_EXTRA_OBJS += libraries/integer-gmp/gmp/objs/*.o