[PATCH 03/20] Build and include gmp-rename.h

Richard Henderson rth at twiddle.net
Mon Mar 4 19:41:33 CET 2013


Placeholder commit.  The defines are still in gmp-h.in, so the
generated file contains lots of self-defines of ABI to ABI name,
which the script actually removes, creating an empty file.

But the makefile rule works...
---
 Makefile.am    |  7 +++++--
 gen-rename.awk | 34 ++++++++++++++++++++++++++++++++++
 gen-rename.c   | 30 ++++++++++++++++++++++++++++++
 gmp-h.in       | 54 +++++++++++++++++++++++++++++++-----------------------
 4 files changed, 100 insertions(+), 25 deletions(-)
 create mode 100644 gen-rename.awk
 create mode 100644 gen-rename.c

diff --git a/Makefile.am b/Makefile.am
index 89cce40..c68c62a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -114,10 +114,10 @@ EXTRA_DIST += gmpxx.h
 #
 includeexecdir = $(exec_prefix)/include
 include_HEADERS = $(GMPXX_HEADERS_OPTION)
-nodist_includeexec_HEADERS = gmp.h
+nodist_includeexec_HEADERS = gmp.h gmp-rename.h
 lib_LTLIBRARIES = libgmp.la $(GMPXX_LTLIBRARIES_OPTION)
 
-BUILT_SOURCES = gmp.h
+BUILT_SOURCES = gmp.h gmp-rename.h
 
 DISTCLEANFILES = $(BUILT_SOURCES) config.m4 @gmp_srclinks@
 
@@ -317,6 +317,9 @@ install-data-hook:
 
 EXTRA_DIST += bootstrap.c
 
+gmp-rename.h: gen-rename.c gen-rename.awk gmp.h
+	$(COMPILE) -E $< | $(AWK) -f $(srcdir)/gen-rename.awk > $@ || (rm -f $@; exit 1)
+
 fac_table.h: gen-fac$(EXEEXT_FOR_BUILD)
 	./gen-fac $(GMP_LIMB_BITS) $(GMP_NAIL_BITS) >fac_table.h || (rm -f fac_table.h; exit 1)
 BUILT_SOURCES += fac_table.h
diff --git a/gen-rename.awk b/gen-rename.awk
new file mode 100644
index 0000000..9745634
--- /dev/null
+++ b/gen-rename.awk
@@ -0,0 +1,34 @@
+BEGIN			{ FPAT = "[A-Za-z_0-9]+"; state = 0; }
+
+/^#/			{ next }
+NF == 0			{ next }
+
+$1 == "__GMP_XYZZY"	{
+			  if (NF == 3) {
+			    if ($2 != $3) print "#define " $2 " " $3
+			    state = 0
+			  } else if (NF == 2) {
+			    first = $2
+			    state = 2
+			  } else {
+			    state = 1
+			  }
+			  next
+			}
+
+state == 1		{
+			  if (NF == 2) {
+			    if ($1 != $2) print "#define " $1 " " $2
+			    state = 0
+			  } else if (NF == 1) {
+			    first = $1
+			    state = 2
+			  }
+			  next
+			}
+
+state == 2		{
+			  if (first != $1) print "#define " first " " $1
+			  state = 0;
+			  next
+			}
diff --git a/gen-rename.c b/gen-rename.c
new file mode 100644
index 0000000..0ff4ea5
--- /dev/null
+++ b/gen-rename.c
@@ -0,0 +1,30 @@
+/* Generate preprocessor defines for renaming symbols.
+   Copyright 2013 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
+
+#include "config.h"
+#include <stdio.h>
+#include <stdarg.h>
+#ifdef HAVE_OBSTACK_VPRINTF
+# include <obstack.h>
+#endif
+
+#define __GMP_WITHIN_CONFIGURE
+#define __GMP_PUBLIC_FULL(TYPE, API_NAME, ARGS, NT, ATTRS, ABI_NAME) \
+  __GMP_XYZZY API_NAME ABI_NAME
+
+#include "gmp.h"
diff --git a/gmp-h.in b/gmp-h.in
index 6a19652..7e14b23 100644
--- a/gmp-h.in
+++ b/gmp-h.in
@@ -128,29 +128,6 @@ along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
 #define __GMP_DECLSPEC
 #endif
 
-/* __GMP_PUBLIC defines the GMP API and ABI.  It comes in several variants
-   to make the usage less arduous:
-     __GMP_PUBLIC	- for normal functions
-     __GMP_PUBLIC_A	- for functions with attributes
-     __GMP_PUBLIC_NT	- for "no-throw" functions
-     __GMP_PUBLIC_NT_A	- for "no-throw" functions with attributes
-     __GMP_PUBLIC_DATA	- for declaring data variables
-*/
-#define __GMP_PUBLIC_FULL(TYPE, API_NAME, ARGS, NT, ATTRS) \
-  __GMP_DECLSPEC TYPE API_NAME ARGS NT ATTRS
-
-#define __GMP_PUBLIC_NT_A(TYPE, API_NAME, ARGS, ATTRS) \
-  __GMP_PUBLIC_FULL(TYPE, API_NAME, ARGS, __GMP_NOTHROW, ATTRS)
-#define __GMP_PUBLIC_A(TYPE, API_NAME, ARGS, ATTRS) \
-  __GMP_PUBLIC_FULL(TYPE, API_NAME, ARGS, , ATTRS)
-#define __GMP_PUBLIC_NT(TYPE, API_NAME, ARGS) \
-  __GMP_PUBLIC_FULL(TYPE, API_NAME, ARGS, __GMP_NOTHROW, )
-#define __GMP_PUBLIC(TYPE, API_NAME, ARGS) \
-  __GMP_PUBLIC_FULL(TYPE, API_NAME, ARGS, , )
-   
-#define __GMP_PUBLIC_DATA(TYPE, API_NAME) \
-  __GMP_DECLSPEC extern TYPE API_NAME
-
 #ifdef __GMP_SHORT_LIMB
 typedef unsigned int		mp_limb_t;
 typedef int			mp_limb_signed_t;
@@ -265,6 +242,37 @@ typedef __mpq_struct *mpq_ptr;
 #define __GMP_DECLSPEC_XX
 #endif
 
+/* __GMP_PUBLIC defines the GMP API and ABI.  It comes in several variants
+   to make the usage less arduous:
+     __GMP_PUBLIC	- for normal functions
+     __GMP_PUBLIC_A	- for functions with attributes
+     __GMP_PUBLIC_NT	- for "no-throw" functions
+     __GMP_PUBLIC_NT_A	- for "no-throw" functions with attributes
+     __GMP_PUBLIC_DATA	- for declaring data variables
+*/
+#if !defined(__GMP_WITHIN_CONFIGURE) || !defined(__GMP_PUBLIC_FULL)
+#define __GMP_PUBLIC_FULL(TYPE, API_NAME, ARGS, NT, ATTRS, ABI_NAME) \
+  __GMP_DECLSPEC TYPE API_NAME ARGS NT ATTRS
+#endif
+
+#define __GMP_PUBLIC_NT_A(TYPE, API_NAME, ARGS, ATTRS) \
+  __GMP_PUBLIC_FULL(TYPE, API_NAME, ARGS, __GMP_NOTHROW, ATTRS, API_NAME)
+#define __GMP_PUBLIC_A(TYPE, API_NAME, ARGS, ATTRS) \
+  __GMP_PUBLIC_FULL(TYPE, API_NAME, ARGS, , ATTRS, API_NAME)
+#define __GMP_PUBLIC_NT(TYPE, API_NAME, ARGS) \
+  __GMP_PUBLIC_FULL(TYPE, API_NAME, ARGS, __GMP_NOTHROW, , API_NAME)
+#define __GMP_PUBLIC(TYPE, API_NAME, ARGS) \
+  __GMP_PUBLIC_FULL(TYPE, API_NAME, ARGS, , , API_NAME)
+   
+#define __GMP_PUBLIC_DATA(TYPE, API_NAME) \
+  __GMP_DECLSPEC extern TYPE API_NAME
+
+/* When using GCC, we'll adjust the API symbol to point to the ABI symbol
+   automatically.  Otherwise, we'll have generated and installed a set of
+   defines that will perform the remapping at the preprocessor level.  */
+#if !defined(__GMP_WITHIN_CONFIGURE)
+# include <gmp-rename.h>
+#endif
 
 #ifndef __MPN
 #define __MPN(x) __gmpn_##x
-- 
1.8.1.2



More information about the gmp-devel mailing list