From 1d216756d038c9472c177cf293cdfb258258e64e Mon Sep 17 00:00:00 2001 From: diviocity Date: Sun, 29 Nov 2026 23:48:10 +0100 Subject: [PATCH] Configure Autotools and Meson builds against the installed target SDK --- libxcvt/PKGBUILD.vile | 25 +++++++++++++++++++++ tools/vinix-configure.v | 47 +++++++++++++++++++++++++++++++++++++++ tools/vinix-meson.v | 49 +++++++++++++++++++++++++++++++++++++++++ tools/vinix-run.v | 39 ++++++++++++++++++++++++++++++++ xorgproto/PKGBUILD.vile | 6 +---- 5 files changed, 161 insertions(+), 5 deletions(-) create mode 100644 libxcvt/PKGBUILD.vile create mode 100644 tools/vinix-configure.v create mode 100644 tools/vinix-meson.v create mode 100644 tools/vinix-run.v diff --git a/libxcvt/PKGBUILD.vile b/libxcvt/PKGBUILD.vile new file mode 100644 index 0000000..8231a95 --- /dev/null +++ b/libxcvt/PKGBUILD.vile @@ -0,0 +1,25 @@ +defpkgbuild(libxcvt, + #:pkgname, "libxcvt", + #:pkgver, "0.1.2", + #:pkgrel, 1, + #:pkgdesc, "xorg xcvt library and cvt program", + #:arch, [#:x86-64, #:aarch64], + #:license, "MIT", + #:url, "https://www.x.org/", + #:depends, ["musl"], + #:source, ["https://xorg.freedesktop.org/archive/individual/lib/libxcvt-0.1.2.tar.xz"], + #:sha256sums, ["0561690544796e25cfbd71806ba1b0d797ffe464e9796411123e79450f71db38"], + + #:build, fn() { + run("vinix-meson", "libxcvt-0.1.2", "build") + run("meson", "compile", "-C", "build", "-j2") + }, + #:check, fn() { + run("readelf", "-d", "build/lib/libxcvt.so") + run("vinix-run", "--library-path", "build/lib", "build/cvt/cvt", "640", "480", "60") + }, + #:package, fn() { + run("meson", "install", "--no-rebuild", "-C", "build", "--destdir", pkgdir()) + run("install", "-Dm644", "libxcvt-0.1.2/COPYING", + string-append(pkgdir(), "/usr/share/licenses/libxcvt/COPYING")) + }) diff --git a/tools/vinix-configure.v b/tools/vinix-configure.v new file mode 100644 index 0000000..808dd25 --- /dev/null +++ b/tools/vinix-configure.v @@ -0,0 +1,47 @@ +// Configure an Autotools release for an installed Vinix SDK with host build tools. +module main + +import os + +fn configure(args []string) ! { + if args.len == 0 { + return error('usage: vinix-configure SOURCE/configure [CONFIGURE_OPTION ...]') + } + root := os.getenv('VPAC_MAKEPKG_ROOT') + arch := os.getenv_opt('VPAC_TARGET_ARCH') or { os.uname().machine } + if arch !in ['x86_64', 'aarch64'] || !os.is_abs_path(root) + || !os.is_file(os.join_path(root, 'lib', 'ld-musl-' + arch + '.so.1')) { + return error('vinix-configure requires a matching ${arch} musl SDK in VPAC_MAKEPKG_ROOT') + } + for name in ['CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH', 'LIBRARY_PATH', 'PKG_CONFIG_PATH'] { + os.unsetenv(name) + } + build_cc := os.getenv_opt('CC_FOR_BUILD') or { 'cc' } + build_machine := os.execute(os.quoted_path(build_cc) + ' -dumpmachine') + if build_machine.exit_code != 0 { + return error('${build_cc} -dumpmachine failed: ${build_machine.output}') + } + os.setenv('CC_FOR_BUILD', build_cc, true) + os.setenv('CC', 'vinix-cc', true) + os.setenv('CXX', 'vinix-c++', true) + prefix := os.getenv('CROSS_COMPILE') + if prefix != '' { + for name in ['ar', 'as', 'ld', 'nm', 'objcopy', 'objdump', 'ranlib', 'strip'] { + os.setenv(name.to_upper(), prefix + name, false) + } + } + os.setenv('PKG_CONFIG_SYSROOT_DIR', root, true) + os.setenv('PKG_CONFIG_LIBDIR', os.join_path(root, 'usr/lib/pkgconfig') + ':' + + os.join_path(root, 'usr/share/pkgconfig'), true) + mut options := ['--build=' + build_machine.output.trim_space(), '--host=' + arch + '-linux-musl', + '--prefix=/usr', '--sysconfdir=/etc'] + options << args[1..] + os.execvp(args[0], options)! +} + +fn main() { + configure(os.args[1..]) or { + eprintln(err) + exit(1) + } +} diff --git a/tools/vinix-meson.v b/tools/vinix-meson.v new file mode 100644 index 0000000..3ec93d0 --- /dev/null +++ b/tools/vinix-meson.v @@ -0,0 +1,49 @@ +// Set up a Meson cross build against an installed Vinix SDK. +module main + +import os + +fn quoted(value string) string { + return "'" + value.replace('\\', '\\\\').replace("'", "\\'") + "'" +} + +fn setup(args []string) ! { + if args.len < 2 { + return error('usage: vinix-meson SOURCE_DIR BUILD_DIR [MESON_OPTION ...]') + } + host := os.uname().machine + arch := os.getenv_opt('VPAC_TARGET_ARCH') or { host } + root := os.getenv('VPAC_MAKEPKG_ROOT') + if arch !in ['x86_64', 'aarch64'] || !os.is_abs_path(root) + || !os.is_file(os.join_path(root, 'lib', 'ld-musl-' + arch + '.so.1')) { + return error('vinix-meson requires a matching ${arch} musl SDK in VPAC_MAKEPKG_ROOT') + } + prefix := os.getenv('CROSS_COMPILE') + mut machine := ['[binaries]', "c = 'vinix-cc'", "cpp = 'vinix-c++'", + "pkg-config = 'pkg-config'", "exe_wrapper = 'vinix-run'"] + for name in ['ar', 'ranlib', 'strip', 'nm', 'objcopy', 'objdump'] { + machine << '${name} = ' + quoted(prefix + name) + } + machine << ['', '[properties]', 'needs_exe_wrapper = true', 'sys_root = ' + quoted(root), + 'pkg_config_libdir = [' + quoted(os.join_path(root, 'usr/lib/pkgconfig')) + ', ' + + quoted(os.join_path(root, 'usr/share/pkgconfig')) + ']', '', '[host_machine]', + "system = 'linux'", 'cpu_family = ' + quoted(arch), 'cpu = ' + quoted(arch), "endian = 'little'"] + file := os.abs_path(args[1]) + '.vinix-cross.ini' + os.write_file(file, machine.join('\n') + '\n')! + for name in ['CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH', 'LIBRARY_PATH', 'PKG_CONFIG_PATH', + 'PKG_CONFIG_LIBDIR', 'PKG_CONFIG_SYSROOT_DIR'] { + os.unsetenv(name) + } + mut options := ['setup', '--cross-file', file, '--prefix=/usr', '--sysconfdir=/etc', + '--libdir=lib', '--buildtype=release'] + options << args[2..] + options << [args[1], args[0]] + os.execvp('meson', options)! +} + +fn main() { + setup(os.args[1..]) or { + eprintln(err) + exit(1) + } +} diff --git a/tools/vinix-run.v b/tools/vinix-run.v new file mode 100644 index 0000000..ad08d4c --- /dev/null +++ b/tools/vinix-run.v @@ -0,0 +1,39 @@ +// Run a dynamically linked target program against the installed musl libraries. +module main + +import os + +fn run(args []string) ! { + root := os.getenv('VPAC_MAKEPKG_ROOT') + host := os.uname().machine + arch := os.getenv_opt('VPAC_TARGET_ARCH') or { host } + if arch !in ['x86_64', 'aarch64'] || !os.is_abs_path(root) { + return error('vinix-run requires a target musl SDK in VPAC_MAKEPKG_ROOT') + } + mut libraries := [os.join_path(root, 'usr/lib'), os.join_path(root, 'lib')] + mut start := 0 + if args.len >= 2 && args[0] == '--library-path' { + libraries.prepend(args[1].split(':')) + start = 2 + } + if args.len <= start { + return error('usage: vinix-run [--library-path DIRS] PROGRAM [ARG ...]') + } + loader := os.join_path(root, 'lib', 'ld-musl-' + arch + '.so.1') + if !os.is_file(loader) { + return error('missing installed loader: ${loader}') + } + mut cmd := [loader, '--library-path', libraries.join(':')] + cmd << args[start..] + if arch != host { + cmd.prepend('qemu-' + arch) + } + os.execvp(cmd[0], cmd[1..])! +} + +fn main() { + run(os.args[1..]) or { + eprintln(err) + exit(1) + } +} diff --git a/xorgproto/PKGBUILD.vile b/xorgproto/PKGBUILD.vile index 264281d..495ea54 100644 --- a/xorgproto/PKGBUILD.vile +++ b/xorgproto/PKGBUILD.vile @@ -11,11 +11,7 @@ defpkgbuild(xorgproto, #:sha256sums, ["4f6b9b4faf91e5df8265b71843a91fc73dc895be6210c84117a996545df296ce"], #:build, fn() { - root := get-environment-variable("VPAC_MAKEPKG_ROOT") - run("env", "-u", "CPATH", "-u", "C_INCLUDE_PATH", "-u", "LIBRARY_PATH", "CC=vinix-cc", - "PKG_CONFIG_PATH=", string-append("PKG_CONFIG_LIBDIR=", root, "/usr/lib/pkgconfig:", root, "/usr/share/pkgconfig"), - string-append("PKG_CONFIG_SYSROOT_DIR=", root), - "xorgproto-2024.1/configure", "--build=x86_64-pc-linux-gnu", "--host=x86_64-linux-musl", "--prefix=/usr", "--enable-legacy", "--disable-specs") + run("vinix-configure", "xorgproto-2024.1/configure", "--enable-legacy", "--disable-specs") run("make") }, #:check, fn() { -- 2.56.1