[vlc-devel] [PATCH v3 7/9] contrib: Fix meson crossfile generation

Marvin Scholz epirat07 at gmail.com
Fri Jun 7 14:52:21 CEST 2019


Previously the crossfile had a lot of hardcoded flags, instead of the
correct CFLAGS/CXXFLAGS, etc.
---
 contrib/src/gen-meson-crossfile.sh | 68 ++++++++++++++++++++++++++++++
 contrib/src/main.mak               | 53 ++++++-----------------
 2 files changed, 81 insertions(+), 40 deletions(-)
 create mode 100755 contrib/src/gen-meson-crossfile.sh

diff --git a/contrib/src/gen-meson-crossfile.sh b/contrib/src/gen-meson-crossfile.sh
new file mode 100755
index 0000000000..2a65c8e80b
--- /dev/null
+++ b/contrib/src/gen-meson-crossfile.sh
@@ -0,0 +1,68 @@
+#! /bin/sh
+
+OUTFILE="$1"
+[ -z "$OUTFILE" ] && echo "Usage: $0 <OUTFILE>" >&2 && exit 1
+exec 3>"$OUTFILE" || exit $?
+
+#
+# Helper functions
+#
+
+add_line()
+{
+    echo "$1" >&3
+}
+
+add_var()
+{
+    echo "$1 = '$2'" >&3
+}
+
+print_array()
+{
+    printf '%s' '['
+    for arg in "$@"; do
+        printf "'%s', " "$arg"
+    done
+    printf '%s' ']'
+}
+
+add_array()
+{
+    arr_key=$1
+    arr_vals=$2
+    add_line "$arr_key = $(eval print_array $arr_vals)"
+}
+
+#
+# Crossfile generation
+#
+
+add_line "# Automatically generated by contrib makefile"
+add_line
+
+# Binaries section
+add_line "[binaries]"
+add_var "c"         "$CC"
+add_var "cpp"       "$CXX"
+add_var "ar"        "$AR"
+add_var "strip"     "$STRIP"
+add_var "pkgconfig" "$PKG_CONFIG"
+add_var "windres"   "$WINDRES"
+add_line
+
+# Properties section
+add_line "[properties]"
+add_line "needs_exe_wrapper = true"
+add_array "c_args"          "$CFLAGS"
+add_array "c_link_args"     "$LDFLAGS"
+add_array "cpp_args"        "$CXXFLAGS"
+add_array "cpp_link_args"   "$LDFLAGS"
+add_line
+
+# Host machine section
+add_line "[host_machine]"
+add_var "system"        "$HOST_SYSTEM"
+add_var "cpu_family"    "$HOST_ARCH"
+add_var "cpu"           "$(echo $HOST | cut -d - -f 1)"
+add_var "endian"        "little"
diff --git a/contrib/src/main.mak b/contrib/src/main.mak
index 8944a5a1d7..044514bc10 100644
--- a/contrib/src/main.mak
+++ b/contrib/src/main.mak
@@ -579,55 +579,28 @@ ifdef HAVE_CROSS_COMPILE
 	echo "set(PKG_CONFIG_EXECUTABLE $(PKG_CONFIG))" >> $@
 endif
 
-crossfile.meson:
-	$(RM) $@
-	echo "[binaries]" >> $@
-	echo "c = '$(CC)'" >> $@
-	echo "cpp = '$(CXX)'" >> $@
-	echo "ar = '$(AR)'" >> $@
-	echo "strip = '$(STRIP)'" >> $@
-	echo "pkgconfig = '$(PKG_CONFIG)'" >> $@
-	echo "windres = '$(WINDRES)'" >> $@
-	echo "[properties]" >> $@
-	echo "needs_exe_wrapper = true" >> $@
-ifdef HAVE_CROSS_COMPILE
-	echo "cpp_args = [ '-I$(PREFIX)/include' ]" >> $@
-	echo "cpp_link_args = [ '-L$(PREFIX)/lib' ]" >> $@
-ifdef HAVE_DARWIN_OS
-ifdef HAVE_IOS
-ifdef HAVE_TVOS
-	echo "c_args = ['-I$(PREFIX)/include', '-isysroot', '$(IOS_SDK)', '-mtvos-version-min=10.2', '-arch', '$(PLATFORM_SHORT_ARCH)', '-fembed-bitcode']" >> $@
-	echo "c_link_args = ['-L$(PREFIX)/lib', '-isysroot', '$(IOS_SDK)', '-arch', '$(PLATFORM_SHORT_ARCH)', '-fembed-bitcode']" >> $@
-else
-	echo "c_args = ['-I$(PREFIX)/include', '-isysroot', '$(IOS_SDK)', '-miphoneos-version-min=8.4', '-arch', '$(PLATFORM_SHORT_ARCH)']" >> $@
-	echo "c_link_args = ['-L$(PREFIX)/lib', '-isysroot', '$(IOS_SDK)', '-arch', '$(PLATFORM_SHORT_ARCH)']" >> $@
-endif
-endif
-ifdef HAVE_MACOSX
-	echo "c_args = ['-I$(PREFIX)/include', '-isysroot', '$(MACOSX_SDK)', '-mmacosx-version-min=10.10', '-arch', '$(ARCH)']" >> $@
-	echo "c_link_args = ['-L$(PREFIX)/lib', '-isysroot', '$(MACOSX_SDK)', '-arch', '$(ARCH)']" >> $@
-endif
-else
-	echo "c_args = [ '-I$(PREFIX)/include' ]" >> $@
-	echo "c_link_args = [ '-L$(PREFIX)/lib' ]" >> $@
-endif
-	echo "[host_machine]" >> $@
+MESON_SYSTEM_NAME =
 ifdef HAVE_WIN32
-	echo "system = 'windows'" >> $@
+	MESON_SYSTEM_NAME = windows
 else
 ifdef HAVE_DARWIN_OS
-	echo "system = 'darwin'" >> $@
+	MESON_SYSTEM_NAME = darwin
 else
 ifdef HAVE_LINUX
 	# android has also system = linux and defines HAVE_LINUX
-	echo "system = 'linux'" >> $@
+	MESON_SYSTEM_NAME = 'linux'
 endif
 endif
 endif
-	echo "cpu_family = '$(subst i386,x86,$(ARCH))'" >> $@
-	echo "cpu = '`echo $(HOST) | cut -d - -f 1`'" >> $@
-	echo "endian = 'little'" >> $@
-endif
+
+crossfile.meson:
+	$(HOSTVARS) \
+	WINDRES="$(WINDRES)" \
+	PKG_CONFIG="$(PKG_CONFIG)" \
+	HOST_SYSTEM="$(MESON_SYSTEM_NAME)" \
+	HOST_ARCH="$(subst i386,x86,$(ARCH))" \
+	HOST="$(HOST)" \
+	$(SRC)/gen-meson-crossfile.sh $@
 
 # Default pattern rules
 .sum-%: $(SRC)/%/SHA512SUMS
-- 
2.20.1 (Apple Git-117)



More information about the vlc-devel mailing list