diff mbox series

[3/4] libffi: Integrate with GCC

Message ID 20210831153659.3756892-4-hjl.tools@gmail.com
State New
Headers show
Series libffi: Sync with upstream | expand

Commit Message

H.J. Lu Aug. 31, 2021, 3:36 p.m. UTC
1. Integrate with GCC.
2. Support multilib.

	* Makefile.am (AUTOMAKE_OPTIONS): Add info-in-builddir.
	(ACLOCAL_AMFLAGS): Set to -I .. -I ../config.
	(SUBDIRS): Don't add doc.
	(TEXINFO_TEX): New.
	(MAKEINFOFLAGS): Likewise.
	(info_TEXINFOS): Likewise.
	(STAMP_GENINSRC): Likewise.
	(STAMP_BUILD_INFO): Likewise.
	(all-local): Likewise.
	(stamp-geninsrc): Likewise.
	(doc/libffi.info): Likewise.
	(stamp-build-info:): Likewise.
	(CLEANFILES): Likewise.
	(MAINTAINERCLEANFILES): Likewise.
	(AM_MAKEFLAGS): Likewise.
	(all-recursive): Likewise.
	(install-recursive): Likewise.
	(mostlyclean-recursive): Likewise.
	(clean-recursive): Likewise.
	(distclean-recursive): Likewise.
	(maintainer-clean-recursive): Likewise.
	(LTLDFLAGS): Replace libtool-ldflags with ../libtool-ldflags.
	(AM_CFLAGS): Add -g -fexceptions.
	(libffi.map-sun): Replace make_sunver.pl with
	../contrib/make_sunver.pl.
	(dist-hook): Removed.
	Include $(top_srcdir)/../multilib.am.
	* configure.ac: Add AM_ENABLE_MULTILIB.
	Remove the frv*-elf check.
	(AX_ENABLE_BUILDDIR): Removed.
	(AM_INIT_AUTOMAKE): Add [no-dist].
	Add --enable-generated-files-in-srcdir.
	(C_CONFIG_MACRO_DIR): Removed.
	(AX_COMPILER_VENDOR): Likewise.
	(AX_CC_MAXOPT): Likewise.
	(AX_CFLAGS_WARN_ALL): Likewise.
	Remove the GCC check.
	(SYMBOL_UNDERSCORE): Removed.
	(AX_CHECK_COMPILE_FLAG): Likewise.
	Remove --disable-docs.
	(ACX_CHECK_PROG_VER): Check makeinfo.
	(BUILD_DOCS): Updated.
	Remove --disable-multi-os-directory.
	(GCC_WITH_TOOLEXECLIBDIR): New.
	Support cross host.
	Support --enable-multilib.
	* include/Makefile.am (nodist_include_HEADERS): Removed.
	(gcc_version): New.
	(toollibffidir): Likewise.
	(toollibffi_HEADERS): Likewise.
	* Makefile.in: Regenerate.
	(GCC_BASE_VER): New.
	(AC_CONFIG_FILES): Remove doc/Makefile.
	(AC_CONFIG_LINKS): New.
	* aclocal.m4: Likewise.
	* configure: Likewise.
	* fficonfig.h.in: Likewise.
	* mdate-sh: Likewise.
	* include/Makefile.in: Likewise.
	* man/Makefile.in: Likewise.
	* testsuite/Makefile.in: Likewise.
---
 libffi/Makefile.am           |   116 +-
 libffi/Makefile.in           |  1963 ++++
 libffi/aclocal.m4            |  1202 ++
 libffi/configure             | 19584 +++++++++++++++++++++++++++++++++
 libffi/configure.ac          |   126 +-
 libffi/fficonfig.h.in        |   227 +
 libffi/include/Makefile.am   |     6 +-
 libffi/include/Makefile.in   |   566 +
 libffi/man/Makefile.in       |   516 +
 libffi/mdate-sh              |   224 +
 libffi/testsuite/Makefile.in |   606 +
 11 files changed, 25052 insertions(+), 84 deletions(-)
 create mode 100644 libffi/Makefile.in
 create mode 100644 libffi/aclocal.m4
 create mode 100755 libffi/configure
 create mode 100644 libffi/fficonfig.h.in
 create mode 100644 libffi/include/Makefile.in
 create mode 100644 libffi/man/Makefile.in
 create mode 100755 libffi/mdate-sh
 create mode 100644 libffi/testsuite/Makefile.in
diff mbox series

Patch

diff --git a/libffi/Makefile.am b/libffi/Makefile.am
index 1b18198ad18..02e36176c67 100644
--- a/libffi/Makefile.am
+++ b/libffi/Makefile.am
@@ -1,18 +1,10 @@ 
 ## Process this with automake to create Makefile.in
 
-AUTOMAKE_OPTIONS = foreign subdir-objects
+AUTOMAKE_OPTIONS = foreign subdir-objects info-in-builddir
 
-ACLOCAL_AMFLAGS = -I m4
+ACLOCAL_AMFLAGS = -I .. -I ../config
 
 SUBDIRS = include testsuite man
-if BUILD_DOCS
-## This hack is needed because it doesn't seem possible to make a
-## conditional info_TEXINFOS in Automake.  At least Automake 1.14
-## either gives errors -- if this attempted in the most
-## straightforward way -- or simply unconditionally tries to build the
-## info file.
-SUBDIRS += doc
-endif
 
 EXTRA_DIST = LICENSE ChangeLog.old					\
 	m4/libtool.m4 m4/lt~obsolete.m4					\
@@ -26,6 +18,90 @@  EXTRA_DIST = LICENSE ChangeLog.old					\
 # local.exp is generated by configure
 DISTCLEANFILES = local.exp
 
+# Automake Documentation:
+# If your package has Texinfo files in many directories, you can use the
+# variable TEXINFO_TEX to tell Automake where to find the canonical
+# `texinfo.tex' for your package. The value of this variable should be
+# the relative path from the current `Makefile.am' to `texinfo.tex'.
+TEXINFO_TEX   = ../gcc/doc/include/texinfo.tex
+
+# Defines info, dvi, pdf and html targets
+MAKEINFOFLAGS = -I $(srcdir)/../gcc/doc/include
+info_TEXINFOS = doc/libffi.texi
+
+# AM_CONDITIONAL on configure option --generated-files-in-srcdir
+if GENINSRC
+STAMP_GENINSRC = stamp-geninsrc
+else
+STAMP_GENINSRC =
+endif
+
+# AM_CONDITIONAL on configure check ACX_CHECK_PROG_VER([MAKEINFO])
+if BUILD_DOCS
+STAMP_BUILD_INFO = stamp-build-info
+else
+STAMP_BUILD_INFO =
+endif
+
+all-local: $(STAMP_GENINSRC)
+
+stamp-geninsrc: doc/libffi.info
+	cp -p $(top_builddir)/doc/libffi.info $(srcdir)/doc/libffi.info
+	@touch $@
+
+doc/libffi.info: $(STAMP_BUILD_INFO)
+
+stamp-build-info: doc/libffi.texi $(srcdir)/doc/version.texi doc/$(am__dirstamp)
+	$(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) -I $(srcdir)/doc -o doc/libffi.info $(srcdir)/doc/libffi.texi
+	@touch $@
+
+CLEANFILES = $(STAMP_GENINSRC) $(STAMP_BUILD_INFO)
+MAINTAINERCLEANFILES = $(srcdir)/doc/libffi.info
+
+## ################################################################
+
+##
+## This section is for make and multilib madness.
+##
+
+# Work around what appears to be a GNU make bug handling MAKEFLAGS
+# values defined in terms of make variables, as is the case for CC and
+# friends when we are called from the top level Makefile.
+AM_MAKEFLAGS = \
+	"AR_FLAGS=$(AR_FLAGS)" \
+	"CC_FOR_BUILD=$(CC_FOR_BUILD)" \
+	"CFLAGS=$(CFLAGS)" \
+	"CXXFLAGS=$(CXXFLAGS)" \
+	"CFLAGS_FOR_BUILD=$(CFLAGS_FOR_BUILD)" \
+	"CFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)" \
+	"INSTALL=$(INSTALL)" \
+	"INSTALL_DATA=$(INSTALL_DATA)" \
+	"INSTALL_PROGRAM=$(INSTALL_PROGRAM)" \
+	"INSTALL_SCRIPT=$(INSTALL_SCRIPT)" \
+	"JC1FLAGS=$(JC1FLAGS)" \
+	"LDFLAGS=$(LDFLAGS)" \
+	"LIBCFLAGS=$(LIBCFLAGS)" \
+	"LIBCFLAGS_FOR_TARGET=$(LIBCFLAGS_FOR_TARGET)" \
+	"MAKE=$(MAKE)" \
+	"MAKEINFO=$(MAKEINFO) $(MAKEINFOFLAGS)" \
+	"PICFLAG=$(PICFLAG)" \
+	"PICFLAG_FOR_TARGET=$(PICFLAG_FOR_TARGET)" \
+	"RUNTESTFLAGS=$(RUNTESTFLAGS)" \
+	"SHELL=$(SHELL)" \
+	"exec_prefix=$(exec_prefix)" \
+	"infodir=$(infodir)" \
+	"libdir=$(libdir)" \
+	"mandir=$(mandir)" \
+	"prefix=$(prefix)" \
+	"AR=$(AR)" \
+	"AS=$(AS)" \
+	"CC=$(CC)" \
+	"CXX=$(CXX)" \
+	"LD=$(LD)" \
+	"NM=$(NM)" \
+	"RANLIB=$(RANLIB)" \
+	"DESTDIR=$(DESTDIR)"
+
 # Subdir rules rely on $(FLAGS_TO_PASS)
 FLAGS_TO_PASS = $(AM_MAKEFLAGS)
 
@@ -104,9 +180,9 @@  libffi_convenience_la_LIBADD = $(libffi_la_LIBADD)
 libffi_convenience_la_DEPENDENCIES = $(libffi_la_DEPENDENCIES)
 nodist_libffi_convenience_la_SOURCES = $(nodist_libffi_la_SOURCES)
 
-LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/libtool-ldflags $(LDFLAGS))
+LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS))
 
-AM_CFLAGS =
+AM_CFLAGS = -Wall -g -fexceptions
 if FFI_DEBUG
 # Build debug. Define FFI_DEBUG on the commandline so that, when building with
 # MSVC, it can link against the debug CRT.
@@ -121,9 +197,9 @@  endif
 if LIBFFI_BUILD_VERSIONED_SHLIB_SUN
 libffi_version_script = -Wl,-M,libffi.map-sun
 libffi_version_dep = libffi.map-sun
-libffi.map-sun : libffi.map $(top_srcdir)/make_sunver.pl \
+libffi.map-sun : libffi.map $(top_srcdir)/../contrib/make_sunver.pl \
 		 $(libffi_la_OBJECTS) $(libffi_la_LIBADD)
-	perl $(top_srcdir)/make_sunver.pl libffi.map \
+	perl $(top_srcdir)/../contrib/make_sunver.pl libffi.map \
 	 `echo $(libffi_la_OBJECTS) $(libffi_la_LIBADD) | \
 	    sed 's,\([^/        ]*\)\.l\([ao]\),.libs/\1.\2,g'` \
 	 > $@ || (rm -f $@ ; exit 1)
@@ -144,8 +220,12 @@  libffi_la_DEPENDENCIES = $(libffi_la_LIBADD) $(libffi_version_dep)
 AM_CPPFLAGS = -I. -I$(top_srcdir)/include -Iinclude -I$(top_srcdir)/src
 AM_CCASFLAGS = $(AM_CPPFLAGS)
 
-dist-hook:
-	d=`(cd $(distdir); pwd)`; (cd doc; make pdf; cp *.pdf $$d/doc)
-	if [ -d $(top_srcdir)/.git ] ; then (cd $(top_srcdir); git log --no-decorate) ; else echo 'See git log for history.' ; fi > $(distdir)/ChangeLog
-	s=`awk '/was released on/{ print NR; exit}' $(top_srcdir)/README.md`; tail -n +$$(($$s-1)) $(top_srcdir)/README.md > $(distdir)/README.md
+# Multilib support.  Automake should provide these on its own.
+all-recursive: all-multi
+install-recursive: install-multi
+mostlyclean-recursive: mostlyclean-multi
+clean-recursive: clean-multi
+distclean-recursive: distclean-multi
+maintainer-clean-recursive: maintainer-clean-multi
 
+include $(top_srcdir)/../multilib.am
diff --git a/libffi/configure.ac b/libffi/configure.ac
index 70f6d2c2ea4..d67b205ea92 100644
--- a/libffi/configure.ac
+++ b/libffi/configure.ac
@@ -5,18 +5,30 @@  AC_PREREQ(2.68)
 AC_INIT([libffi], [3.4.2], [http://github.com/libffi/libffi/issues])
 AC_CONFIG_HEADERS([fficonfig.h])
 
+AM_ENABLE_MULTILIB(, ..)
+
 AC_CANONICAL_SYSTEM
 target_alias=${target_alias-$host_alias}
 
-case "${host}" in
-  frv*-elf)
-    LDFLAGS=`echo $LDFLAGS | sed "s/\-B[^ ]*libgloss\/frv\///"`\ -B`pwd`/../libgloss/frv/
-    ;;
-esac
-
-AX_ENABLE_BUILDDIR
-
-AM_INIT_AUTOMAKE
+AM_INIT_AUTOMAKE([no-dist])
+
+# We would like our source tree to be readonly. However when releases or
+# pre-releases are generated, the flex/bison generated files as well as the
+# various formats of manuals need to be included along with the rest of the
+# sources.  Therefore we have --enable-generated-files-in-srcdir to do
+# just that.
+AC_MSG_CHECKING(generated-files-in-srcdir)
+AC_ARG_ENABLE(generated-files-in-srcdir,
+AS_HELP_STRING([--enable-generated-files-in-srcdir],
+ [put copies of generated files in source dir intended for creating source tarballs for users without texinfo bison or flex]),
+[case "$enableval" in
+ yes) enable_generated_files_in_srcdir=yes ;;
+ no)  enable_generated_files_in_srcdir=no ;;
+ *)   AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
+ esac],
+[enable_generated_files_in_srcdir=no])
+AC_MSG_RESULT($enable_generated_files_in_srcdir)
+AM_CONDITIONAL(GENINSRC, test "$enable_generated_files_in_srcdir" = yes)
 
 # The same as in boehm-gc and libstdc++. Have to borrow it from there.
 # We must force CC to /not/ be precious variables; otherwise
@@ -39,25 +51,12 @@  AC_SUBST(CFLAGS)
 AM_PROG_AS
 AM_PROG_CC_C_O
 AC_PROG_LIBTOOL
-AC_CONFIG_MACRO_DIR([m4])
 
 AC_CHECK_TOOL(READELF, readelf)
 
 # Test for 64-bit build.
 AC_CHECK_SIZEOF([size_t])
 
-AX_COMPILER_VENDOR
-AX_CC_MAXOPT
-# The AX_CFLAGS_WARN_ALL macro doesn't currently work for sunpro
-# compiler.
-if test "$ax_cv_c_compiler_vendor" != "sun"; then
-  AX_CFLAGS_WARN_ALL
-fi
-
-if test "x$GCC" = "xyes"; then
-  CFLAGS="$CFLAGS -fexceptions"
-fi
-
 cat > local.exp <<EOF
 set CC_FOR_TARGET "$CC"
 set CXX_FOR_TARGET "$CXX"
@@ -212,11 +211,6 @@  AC_ARG_ENABLE(pax_emutramp,
       [Define this if you want to enable pax emulated trampolines])
   fi)
 
-LT_SYS_SYMBOL_USCORE
-if test "x$sys_symbol_underscore" = xyes; then
-    AC_DEFINE(SYMBOL_UNDERSCORE, 1, [Define if symbols are underscored.])
-fi
-
 FFI_EXEC_TRAMPOLINE_TABLE=0
 case "$target" in
      *arm*-apple-* | aarch64-apple-*)
@@ -266,13 +260,11 @@  EOF
 fi
 
 if test "x$GCC" = "xyes"; then
-  AX_CHECK_COMPILE_FLAG(-fno-lto, libffi_cv_no_lto=-fno-lto)
-
   AC_CACHE_CHECK([whether .eh_frame section should be read-only],
       libffi_cv_ro_eh_frame, [
   	libffi_cv_ro_eh_frame=yes
   	echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
-  	if $CC $CFLAGS -c -fpic -fexceptions $libffi_cv_no_lto -o conftest.o conftest.c > /dev/null 2>&1; then
+  	if $CC $CFLAGS -c -fpic -fexceptions -fno-lto -o conftest.o conftest.c > /dev/null 2>&1; then
 	    if $READELF -WS conftest.o | grep -q -n 'eh_frame .* WA'; then
 	        libffi_cv_ro_eh_frame=no
 	    fi
@@ -306,12 +298,12 @@  if test "x$GCC" = "xyes"; then
   fi
 fi
 
-AC_ARG_ENABLE(docs,
-              AC_HELP_STRING([--disable-docs],
-                             [Disable building of docs (default: no)]),
-              [enable_docs=no],
-              [enable_docs=yes])
-AM_CONDITIONAL(BUILD_DOCS, [test x$enable_docs = xyes])
+# See if makeinfo has been installed and is modern enough
+# that we can use it.
+ACX_CHECK_PROG_VER([MAKEINFO], [makeinfo], [--version],
+                   [GNU texinfo.* \([0-9][0-9.]*\)],
+                   [4.[4-9]*|4.[1-9][0-9]*|[5-9]*|[1-9][0-9]*])
+AM_CONDITIONAL(BUILD_DOCS, test $gcc_cv_prog_makeinfo_modern = "yes")
 
 AH_BOTTOM([
 #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
@@ -386,47 +378,51 @@  AC_ARG_ENABLE(purify-safety,
     AC_DEFINE(USING_PURIFY, 1, [Define this if you are using Purify and want to suppress spurious messages.])
   fi)
 
-AC_ARG_ENABLE(multi-os-directory,
-[  --disable-multi-os-directory
-                          disable use of gcc --print-multi-os-directory to change the library installation directory])
-                          
-# These variables are only ever used when we cross-build to X86_WIN32.
-# And we only support this with GCC, so...
-if test "x$GCC" = "xyes"; then
-  if test -n "$with_cross_host" &&
-     test x"$with_cross_host" != x"no"; then
-    toolexecdir='${exec_prefix}'/'$(target_alias)'
-    toolexeclibdir='${toolexecdir}'/lib
-  else
-    toolexecdir='${libdir}'/gcc-lib/'$(target_alias)'
-    toolexeclibdir='${libdir}'
-  fi
-  if test x"$enable_multi_os_directory" != x"no"; then
-    multi_os_directory=`$CC $CFLAGS -print-multi-os-directory`
-    case $multi_os_directory in
-      .) ;; # Avoid trailing /.
-      ../*) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
-    esac
-  fi
-  AC_SUBST(toolexecdir)
+GCC_WITH_TOOLEXECLIBDIR
+
+if test -n "$with_cross_host" &&
+   test x"$with_cross_host" != x"no"; then
+  toolexecdir='$(exec_prefix)/$(target_alias)'
+  case ${with_toolexeclibdir} in
+    no)
+      toolexeclibdir='$(toolexecdir)/lib'
+      ;;
+    *)
+      toolexeclibdir=${with_toolexeclibdir}
+      ;;
+  esac
 else
-  toolexeclibdir='${libdir}'
+  toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
+  toolexeclibdir='$(libdir)'
 fi
+multi_os_directory=`$CC -print-multi-os-directory`
+case $multi_os_directory in
+  .) ;; # Avoid trailing /.
+  *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
+esac
+AC_SUBST(toolexecdir)
 AC_SUBST(toolexeclibdir)
 
+if test "${multilib}" = "yes"; then
+  multilib_arg="--enable-multilib"
+else
+  multilib_arg=
+fi
+
 # Check linker support.
 LIBFFI_ENABLE_SYMVERS
 
+# Determine what GCC version number to use in filesystem paths.
+GCC_BASE_VER
+
 AC_CONFIG_COMMANDS(include, [test -d include || mkdir include])
 AC_CONFIG_COMMANDS(src, [
 test -d src || mkdir src
 test -d src/$TARGETDIR || mkdir src/$TARGETDIR
 ], [TARGETDIR="$TARGETDIR"])
 
-AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile doc/Makefile libffi.pc)
+AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile libffi.pc)
 
-AC_OUTPUT
+AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETDIR/ffitarget.h)
 
-# Copy this file instead of using AC_CONFIG_LINK in order to support
-# compiling with MSVC, which won't understand cygwin style symlinks.
-cp ${srcdir}/src/$TARGETDIR/ffitarget.h include/ffitarget.h
+AC_OUTPUT
diff --git a/libffi/include/Makefile.am b/libffi/include/Makefile.am
index 5f0d4066f4a..d7d1641f00c 100644
--- a/libffi/include/Makefile.am
+++ b/libffi/include/Makefile.am
@@ -6,4 +6,8 @@  DISTCLEANFILES=ffitarget.h
 noinst_HEADERS=ffi_common.h ffi_cfi.h tramp.h
 EXTRA_DIST=ffi.h.in
 
-nodist_include_HEADERS = ffi.h ffitarget.h
+# Where generated headers like ffitarget.h get installed.
+gcc_version   := $(shell @get_gcc_base_ver@ $(top_srcdir)/../gcc/BASE-VER)
+toollibffidir := $(libdir)/gcc/$(target_alias)/$(gcc_version)/include
+
+toollibffi_HEADERS = ffi.h ffitarget.h