diff mbox series

[pushed] Darwin, jit: Fix build [PR100613].

Message ID F33BC8D3-4002-4C0B-900E-0F036C8EC9B4@sandoe.co.uk
State New
Headers show
Series [pushed] Darwin, jit: Fix build [PR100613]. | expand

Commit Message

Iain Sandoe Aug. 18, 2021, 6:54 p.m. UTC
Hi,

The generic unix build is not completely suitable for Darwin
platforms:

 * It is a convention to encode the library versioning in the
   binary and to have only one level of symlink for the installed
   files. This needs to be applied to the installation too.
 * The library needs to be built with its correct install name
   so that two-level library naming works.
 * The extension for shared libraries should be .dylib

tested on i686, powerpc, x86_64-darwin, x86_64, powerpc64-linux
pushed to master, thanks
Iain

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

PR jit/100613 - libgccjit should produce dylib on macOS

	PR jit/100613

gcc/jit/ChangeLog:

	* Make-lang.in: Provide clauses for Darwin hosts.
---
 gcc/jit/Make-lang.in | 63 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 62 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/gcc/jit/Make-lang.in b/gcc/jit/Make-lang.in
index 663772aba63..2a774d7feb1 100644
--- a/gcc/jit/Make-lang.in
+++ b/gcc/jit/Make-lang.in
@@ -53,8 +53,40 @@  jit: $(LIBGCCJIT_FILENAME) \
 
 else
 
-LIBGCCJIT_LINKER_NAME = libgccjit.so
+ifneq (,$(findstring darwin,$(host)))
+
+LIBGCCJIT_AGE = 1
+LIBGCCJIT_BASENAME = libgccjit
+
+LIBGCCJIT_SONAME = \
+  ${libdir}/$(LIBGCCJIT_BASENAME).$(LIBGCCJIT_VERSION_NUM).dylib
+LIBGCCJIT_FILENAME = $(LIBGCCJIT_BASENAME).$(LIBGCCJIT_VERSION_NUM).dylib
+LIBGCCJIT_LINKER_NAME = $(LIBGCCJIT_BASENAME).dylib
+
+# Conditionalize the use of the LD_VERSION_SCRIPT_OPTION and
+# LD_SONAME_OPTION depending if configure found them, using $(if)
+# We have to define a COMMA here, otherwise the commas in the "true"
+# result are treated as separators by the $(if).
+COMMA := ,
+LIBGCCJIT_VERSION_SCRIPT_OPTION = \
+	$(if $(LD_VERSION_SCRIPT_OPTION),\
+	  -Wl$(COMMA)$(LD_VERSION_SCRIPT_OPTION)$(COMMA)$(srcdir)/jit/libgccjit.map)
+
+LIBGCCJIT_SONAME_OPTION = \
+	$(if $(LD_SONAME_OPTION), \
+	     -Wl$(COMMA)$(LD_SONAME_OPTION)$(COMMA)$(LIBGCCJIT_SONAME))
+
+LIBGCCJIT_SONAME_SYMLINK = $(LIBGCCJIT_FILENAME)
+LIBGCCJIT_LINKER_NAME_SYMLINK = $(LIBGCCJIT_LINKER_NAME)
+
+jit: $(LIBGCCJIT_FILENAME) \
+	$(LIBGCCJIT_SYMLINK) \
+	$(LIBGCCJIT_LINKER_NAME_SYMLINK) \
+	$(FULL_DRIVER_NAME)
 
+else
+
+LIBGCCJIT_LINKER_NAME = libgccjit.so
 LIBGCCJIT_SONAME = $(LIBGCCJIT_LINKER_NAME).$(LIBGCCJIT_VERSION_NUM)
 LIBGCCJIT_FILENAME = \
   $(LIBGCCJIT_SONAME).$(LIBGCCJIT_MINOR_NUM).$(LIBGCCJIT_RELEASE_NUM)
@@ -79,6 +111,8 @@  jit: $(LIBGCCJIT_FILENAME) \
 	$(LIBGCCJIT_SYMLINK) \
 	$(LIBGCCJIT_LINKER_NAME_SYMLINK) \
 	$(FULL_DRIVER_NAME)
+
+endif
 endif
 
 jit.serial = $(LIBGCCJIT_FILENAME)
@@ -109,9 +143,19 @@  ifneq (,$(findstring mingw,$(target)))
 # Create import library
 LIBGCCJIT_EXTRA_OPTS = -Wl,--out-implib,$(LIBGCCJIT_IMPORT_LIB)
 else
+
+ifneq (,$(findstring darwin,$(host)))
+# TODO : Construct a Darwin-style symbol export file.
+LIBGCCJIT_EXTRA_OPTS = -Wl,-compatibility_version,$(LIBGCCJIT_VERSION_NUM) \
+	-Wl,-current_version,$(LIBGCCJIT_VERSION_NUM).$(LIBGCCJIT_MINOR_NUM).$(LIBGCCJIT_AGE) \
+	$(LIBGCCJIT_VERSION_SCRIPT_OPTION) \
+	$(LIBGCCJIT_SONAME_OPTION)
+else
+
 LIBGCCJIT_EXTRA_OPTS = $(LIBGCCJIT_VERSION_SCRIPT_OPTION) \
 	$(LIBGCCJIT_SONAME_OPTION)
 endif
+endif
 
 # We avoid using $(BACKEND) from Makefile.in in order to avoid pulling
 # in main.o
@@ -130,8 +174,12 @@  $(LIBGCCJIT_FILENAME): $(jit_OBJS) \
 
 # Create symlinks when not building for Windows
 ifeq (,$(findstring mingw,$(target)))
+
+ifeq (,$(findstring darwin,$(host)))
+# but only one level for Darwin, version info is embedded.
 $(LIBGCCJIT_SONAME_SYMLINK): $(LIBGCCJIT_FILENAME)
 	ln -sf $(LIBGCCJIT_FILENAME) $(LIBGCCJIT_SONAME_SYMLINK)
+endif
 
 $(LIBGCCJIT_LINKER_NAME_SYMLINK): $(LIBGCCJIT_SONAME_SYMLINK)
 	ln -sf $(LIBGCCJIT_SONAME_SYMLINK) $(LIBGCCJIT_LINKER_NAME_SYMLINK)
@@ -319,6 +367,18 @@  jit.install-common: installdirs jit.install-headers
 # Install DLL file
 	$(INSTALL_PROGRAM) $(LIBGCCJIT_FILENAME) \
 	  $(DESTDIR)$(bindir)/$(LIBGCCJIT_FILENAME)
+
+else
+ifneq (,$(findstring darwin,$(host)))
+# but only one level for Darwin
+
+jit.install-common: installdirs jit.install-headers
+	$(INSTALL_PROGRAM) $(LIBGCCJIT_FILENAME) \
+	  $(DESTDIR)$(libdir)/$(LIBGCCJIT_FILENAME)
+	ln -sf \
+	  $(LIBGCCJIT_SONAME_SYMLINK)\
+	  $(DESTDIR)$(libdir)/$(LIBGCCJIT_LINKER_NAME_SYMLINK)
+
 else
 jit.install-common: installdirs jit.install-headers
 	$(INSTALL_PROGRAM) $(LIBGCCJIT_FILENAME) \
@@ -330,6 +390,7 @@  jit.install-common: installdirs jit.install-headers
 	  $(LIBGCCJIT_SONAME_SYMLINK)\
 	  $(DESTDIR)$(libdir)/$(LIBGCCJIT_LINKER_NAME_SYMLINK)
 endif
+endif
 
 jit.install-man: