From bdcad6f2513bce70da425e4c883d35c716571a60 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jeremy@system76.com>
Date: Wed, 23 Dec 2020 21:22:59 -0700
Subject: [PATCH] Update mesa to use meson

---
 recipes/mesa/recipe.sh | 73 +++++++++++++++++++++++++++++-------------
 1 file changed, 51 insertions(+), 22 deletions(-)

diff --git a/recipes/mesa/recipe.sh b/recipes/mesa/recipe.sh
index e62c40406..853b582eb 100644
--- a/recipes/mesa/recipe.sh
+++ b/recipes/mesa/recipe.sh
@@ -17,27 +17,57 @@ function recipe_build {
     sysroot="$(realpath ../sysroot)"
     export CFLAGS="-I$sysroot/include -DHAVE_PTHREAD=1"
     export CPPFLAGS="-I$sysroot/include -DHAVE_PTHREAD=1"
-    export LDFLAGS="-L$sysroot/lib --static"
+    export LDFLAGS="-L$sysroot/lib --static $("${TARGET}-llvm-config" --libfiles all)"
     #export LLVM_CONFIG="x86_64-unknown-redox-llvm-config"
-    NOCONFIGURE=1 ./autogen.sh
-    ./configure \
-        --build=${BUILD} \
-        --host="${HOST}" \
-        --prefix=/ \
-        --disable-dri \
-        --disable-dri3 \
-        --disable-driglx-direct \
-        --disable-egl \
-        --disable-glx \
-        --disable-gbm \
-        --disable-llvm-shared-libs \
-        --disable-shared \
-        --enable-llvm \
-        --enable-gallium-osmesa \
-        --enable-static \
-        --with-gallium-drivers=swrast \
-        --with-platforms=surfaceless
-    "$REDOX_MAKE" V=1 -j"$($NPROC)"
+
+    # TODO: Fix this annoying shite
+    echo "[binaries]" > cross_file.txt
+    echo "c = '${CC}'" >> cross_file.txt
+    echo "cpp = '${CXX}'" >> cross_file.txt
+    echo "ar = '${AR}'" >> cross_file.txt
+    echo "strip = '${STRIP}'" >> cross_file.txt
+    echo "pkgconfig = '${PKG_CONFIG}'" >> cross_file.txt
+    echo "llvm-config = '${TARGET}-llvm-config'" >> cross_file.txt
+
+    echo "[host_machine]" >> cross_file.txt
+    echo "system = 'redox'" >> cross_file.txt
+    echo "cpu_family = 'x86_64'" >> cross_file.txt
+    echo "cpu = 'x86_64'" >> cross_file.txt
+    echo "endian = 'little'" >> cross_file.txt
+
+    echo "[paths]" >> cross_file.txt
+    echo "prefix = '/'" >> cross_file.txt
+    echo "libdir = 'lib'" >> cross_file.txt
+    echo "bindir = 'bin'" >> cross_file.txt
+
+    unset AR
+    unset AS
+    unset CC
+    unset CXX
+    unset LD
+    unset NM
+    unset OBJCOPY
+    unset OBJDUMP
+    unset PKG_CONFIG
+    unset PKG_CONFIG_PATH
+    unset RANLIB
+    unset READELF
+    unset STRIP
+
+    meson . _build \
+        --cross-file cross_file.txt \
+        --buildtype release \
+        --strip \
+        -Ddefault_library=static \
+        -Dglx=disabled \
+        -Dllvm=enabled \
+        -Dosmesa=gallium \
+        -Dplatforms= \
+        -Dshader-cache=disabled \
+        -Dshared-llvm=disabled \
+        -Dshared-glapi=disabled
+
+    ninja -C _build -v
     skip=1
 }
 
@@ -52,9 +82,8 @@ function recipe_clean {
 }
 
 function recipe_stage {
-    #export LLVM_CONFIG="x86_64-unknown-redox-llvm-config"
     dest="$(realpath $1)"
-    "$REDOX_MAKE" DESTDIR="$dest" install
+    DESTDIR="$dest" ninja -C _build install
     rm -f "$dest/lib/"*.la
     skip=1
 }
-- 
GitLab