From 1dbac754d82f3008d9bb82d89c1a60706adddde5 Mon Sep 17 00:00:00 2001
From: Filippo Cremonese <filippocremonese@rev.ng>
Date: Mon, 28 Sep 2020 16:48:49 +0200
Subject: [PATCH] Add libffi component, use gold as linker for glib

---
 .orchestra/config/components.yml            |  2 ++
 .orchestra/config/components/glib.lib.yml   |  8 ++---
 .orchestra/config/components/libffi.lib.yml | 36 +++++++++++++++++++++
 3 files changed, 40 insertions(+), 6 deletions(-)
 create mode 100644 .orchestra/config/components/libffi.lib.yml

diff --git a/.orchestra/config/components.yml b/.orchestra/config/components.yml
index 9a45ade..afe0937 100644
--- a/.orchestra/config/components.yml
+++ b/.orchestra/config/components.yml
@@ -12,6 +12,7 @@
 #@ load("/components/llvmcpy.lib.yml", "llvmcpy_component")
 #@ load("/components/clang_release.lib.yml", "clang_release_component")
 #@ load("/components/glib.lib.yml", "glib_component")
+#@ load("/components/libffi.lib.yml", "libffi_component")
 #@ load("/components/qemu.lib.yml", "qemu_component")
 #@ load("/components/boost.lib.yml", "boost_component")
 #@ load("/components/revng.lib.yml", "revng_component")
@@ -55,6 +56,7 @@ components:
   llvmcpy: #@ llvmcpy_component
   clang-release: #@ clang_release_component
   glib: #@ glib_component
+  libffi: #@ libffi_component
   qemu: #@ qemu_component
   boost: #@ boost_component
   revng: #@ revng_component
diff --git a/.orchestra/config/components/glib.lib.yml b/.orchestra/config/components/glib.lib.yml
index 7e35b21..579e6f8 100644
--- a/.orchestra/config/components/glib.lib.yml
+++ b/.orchestra/config/components/glib.lib.yml
@@ -13,9 +13,6 @@ builds:
       find "$BUILD_DIR/source/" -name meson.build -exec sed -i "s|install\s*:\s*|install_rpath : '$RPATH_PLACEHOLDER/lib', \0|" {} \;
       sed -i 's|^.*HAVE_LANGINFO_.*1.*$||' "$BUILD_DIR/source/meson.build"
 
-      export LIBFFI_CFLAGS="-I$ORCHESTRA_ROOT/include"
-      export LIBFFI_LIBS="-L$ORCHESTRA_ROOT/lib64 -lffi"
-
       CC=clang \
       CXX=clang++ \
       meson setup \
@@ -35,18 +32,17 @@ builds:
         -Dinstalled_tests=false \
         -Dnls=disabled \
         -Dc_args="-w" \
-        -Dc_link_args="-Wl,-z,origin -Wl,--enable-new-dtags -Wl,-rpath,$RPATH_PLACEHOLDER/lib -Wl,-rpath-link,$ORCHESTRA_ROOT/lib" \
+        -Dc_link_args="-fuse-ld=gold -Wl,-z,origin -Wl,--enable-new-dtags -Wl,-rpath,$RPATH_PLACEHOLDER/lib" \
         "$BUILD_DIR" \
         "$BUILD_DIR/source"
     install: |
       cd "$BUILD_DIR"
       export LANG=
-      export LIBFFI_CFLAGS="-I$ORCHESTRA_ROOT/include"
-      export LIBFFI_LIBS="-L$ORCHESTRA_ROOT/lib64 -lffi"
       (@= ninja @)
       (@= ninja @) install
     dependencies:
       - clang-release
+      - libffi
 #@ end
 
 ---
diff --git a/.orchestra/config/components/libffi.lib.yml b/.orchestra/config/components/libffi.lib.yml
new file mode 100644
index 0000000..0911a78
--- /dev/null
+++ b/.orchestra/config/components/libffi.lib.yml
@@ -0,0 +1,36 @@
+#@ load("/lib/make.lib.yml", "make")
+#@ load("/global_options.lib.yml", "options")
+
+#@ source_url = "https://github.com/libffi/libffi/releases/download/v3.3/libffi-3.3.tar.gz"
+
+#@yaml/text-templated-strings
+---
+#@ def _libffi_component():
+builds:
+  default:
+    configure: |
+      mkdir -p "$BUILD_DIR/source"
+      extract.sh --into "$BUILD_DIR/source" (@= source_url @)
+
+      cd "$BUILD_DIR"
+      export CC=clang
+      export CXX=clang++
+      "$BUILD_DIR/source/configure" \
+        --disable-multi-os-directory \
+        --disable-static \
+        --disable-pax_emutramp \
+        --disable-debug \
+        --prefix="$ORCHESTRA_ROOT" \
+        LDFLAGS="(@= options["modern_linker_flags"] @) -Wl,-rpath,$RPATH_PLACEHOLDER/lib"
+
+    install: |
+      cd "$BUILD_DIR"
+      (@= make @)
+      (@= make @) install
+    dependencies:
+      - toolchain/host/gcc
+#@ end
+
+---
+
+#@ libffi_component = _libffi_component()
-- 
GitLab