[vlc-devel] [PATCH v4 7/9] contrib: Rework meson crossfile generation
Marvin Scholz
epirat07 at gmail.com
Tue Jun 11 21:46:40 CEST 2019
Previously the crossfile had a lot of hardcoded flags, instead of the
correct CFLAGS/CXXFLAGS, etc.
This replaces the generation in the Makefile with a simple Python script
instead, which should be fine, given that meson anyway needs Python 3
and that the crossfile is only generated when needed.
---
contrib/src/gen-meson-crossfile.py | 52 +++++++++++++++++++++++++++++
contrib/src/main.mak | 53 ++++++++----------------------
2 files changed, 65 insertions(+), 40 deletions(-)
create mode 100755 contrib/src/gen-meson-crossfile.py
diff --git a/contrib/src/gen-meson-crossfile.py b/contrib/src/gen-meson-crossfile.py
new file mode 100755
index 0000000000..000074d950
--- /dev/null
+++ b/contrib/src/gen-meson-crossfile.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python3
+import os
+import argparse
+import shlex
+
+# Argument parsing
+parser = argparse.ArgumentParser(
+ description="Generate a meson crossfile based on environment variables")
+parser.add_argument('file', type=argparse.FileType('w', encoding='UTF-8'),
+ help="output file")
+args = parser.parse_args()
+
+# Helper to add env variable value to crossfile
+def _add_environ_val(meson_key, env_key):
+ env_value = os.environ.get(env_key, '')
+ args.file.write("{} = '{}'\n".format(meson_key, env_value))
+
+# Helper to add env variable array to crossfile
+def _add_environ_arr(meson_key, env_key):
+ env_values = shlex.split(os.environ.get(env_key, ''))
+ arr_string = (', '.join("'" + item + "'" for item in env_values))
+ args.file.write("{} = [{}]\n".format(meson_key, arr_string))
+
+# Generate meson crossfile
+args.file.write("# Automatically generated by contrib makefile\n")
+
+# Binaries section
+args.file.write("\n[binaries]\n")
+_add_environ_val('c', 'CC')
+_add_environ_val('cpp', 'CXX')
+_add_environ_val('ar', 'AR')
+_add_environ_val('strip', 'STRIP')
+_add_environ_val('pkgconfig', 'PKG_CONFIG')
+_add_environ_val('windres', 'WINDRES')
+
+# Properties section
+args.file.write("\n[properties]\n")
+args.file.write("needs_exe_wrapper = true\n")
+_add_environ_arr('c_args', 'CFLAGS')
+_add_environ_arr('c_link_args', 'LDFLAGS')
+_add_environ_arr('cpp_args', 'CXXFLAGS')
+_add_environ_arr('cpp_link_args', 'LDFLAGS')
+
+# Host machine section
+args.file.write("\n[host_machine]\n")
+_add_environ_val('system', 'HOST_SYSTEM')
+_add_environ_val('cpu_family', 'HOST_ARCH')
+args.file.write("endian = 'little'")
+
+# Get first part of triplet
+cpu = os.environ.get('HOST', '').split('-')[0]
+args.file.write("cpu = '{}'\n".format(cpu))
diff --git a/contrib/src/main.mak b/contrib/src/main.mak
index 8944a5a1d7..18d26bbc9d 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.py $@
# Default pattern rules
.sum-%: $(SRC)/%/SHA512SUMS
--
2.20.1 (Apple Git-117)
More information about the vlc-devel
mailing list