Configure Autotools and Meson builds against the installed target SDK
@@ -0,0 +1,25 @@
1+defpkgbuild(libxcvt,
2+ #:pkgname, "libxcvt",
3+ #:pkgver, "0.1.2",
4+ #:pkgrel, 1,
5+ #:pkgdesc, "xorg xcvt library and cvt program",
6+ #:arch, [#:x86-64, #:aarch64],
7+ #:license, "MIT",
8+ #:url, "https://www.x.org/",
9+ #:depends, ["musl"],
10+ #:source, ["https://xorg.freedesktop.org/archive/individual/lib/libxcvt-0.1.2.tar.xz"],
11+ #:sha256sums, ["0561690544796e25cfbd71806ba1b0d797ffe464e9796411123e79450f71db38"],
12+
13+ #:build, fn() {
14+ run("vinix-meson", "libxcvt-0.1.2", "build")
15+ run("meson", "compile", "-C", "build", "-j2")
16+ },
17+ #:check, fn() {
18+ run("readelf", "-d", "build/lib/libxcvt.so")
19+ run("vinix-run", "--library-path", "build/lib", "build/cvt/cvt", "640", "480", "60")
20+ },
21+ #:package, fn() {
22+ run("meson", "install", "--no-rebuild", "-C", "build", "--destdir", pkgdir())
23+ run("install", "-Dm644", "libxcvt-0.1.2/COPYING",
24+ string-append(pkgdir(), "/usr/share/licenses/libxcvt/COPYING"))
25+ })
@@ -0,0 +1,47 @@
1+// Configure an Autotools release for an installed Vinix SDK with host build tools.
2+module main
3+
4+import os
5+
6+fn configure(args []string) ! {
7+ if args.len == 0 {
8+ return error('usage: vinix-configure SOURCE/configure [CONFIGURE_OPTION ...]')
9+ }
10+ root := os.getenv('VPAC_MAKEPKG_ROOT')
11+ arch := os.getenv_opt('VPAC_TARGET_ARCH') or { os.uname().machine }
12+ if arch !in ['x86_64', 'aarch64'] || !os.is_abs_path(root)
13+ || !os.is_file(os.join_path(root, 'lib', 'ld-musl-' + arch + '.so.1')) {
14+ return error('vinix-configure requires a matching ${arch} musl SDK in VPAC_MAKEPKG_ROOT')
15+ }
16+ for name in ['CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH', 'LIBRARY_PATH', 'PKG_CONFIG_PATH'] {
17+ os.unsetenv(name)
18+ }
19+ build_cc := os.getenv_opt('CC_FOR_BUILD') or { 'cc' }
20+ build_machine := os.execute(os.quoted_path(build_cc) + ' -dumpmachine')
21+ if build_machine.exit_code != 0 {
22+ return error('${build_cc} -dumpmachine failed: ${build_machine.output}')
23+ }
24+ os.setenv('CC_FOR_BUILD', build_cc, true)
25+ os.setenv('CC', 'vinix-cc', true)
26+ os.setenv('CXX', 'vinix-c++', true)
27+ prefix := os.getenv('CROSS_COMPILE')
28+ if prefix != '' {
29+ for name in ['ar', 'as', 'ld', 'nm', 'objcopy', 'objdump', 'ranlib', 'strip'] {
30+ os.setenv(name.to_upper(), prefix + name, false)
31+ }
32+ }
33+ os.setenv('PKG_CONFIG_SYSROOT_DIR', root, true)
34+ os.setenv('PKG_CONFIG_LIBDIR', os.join_path(root, 'usr/lib/pkgconfig') + ':' +
35+ os.join_path(root, 'usr/share/pkgconfig'), true)
36+ mut options := ['--build=' + build_machine.output.trim_space(), '--host=' + arch + '-linux-musl',
37+ '--prefix=/usr', '--sysconfdir=/etc']
38+ options << args[1..]
39+ os.execvp(args[0], options)!
40+}
41+
42+fn main() {
43+ configure(os.args[1..]) or {
44+ eprintln(err)
45+ exit(1)
46+ }
47+}
@@ -0,0 +1,49 @@
1+// Set up a Meson cross build against an installed Vinix SDK.
2+module main
3+
4+import os
5+
6+fn quoted(value string) string {
7+ return "'" + value.replace('\\', '\\\\').replace("'", "\\'") + "'"
8+}
9+
10+fn setup(args []string) ! {
11+ if args.len < 2 {
12+ return error('usage: vinix-meson SOURCE_DIR BUILD_DIR [MESON_OPTION ...]')
13+ }
14+ host := os.uname().machine
15+ arch := os.getenv_opt('VPAC_TARGET_ARCH') or { host }
16+ root := os.getenv('VPAC_MAKEPKG_ROOT')
17+ if arch !in ['x86_64', 'aarch64'] || !os.is_abs_path(root)
18+ || !os.is_file(os.join_path(root, 'lib', 'ld-musl-' + arch + '.so.1')) {
19+ return error('vinix-meson requires a matching ${arch} musl SDK in VPAC_MAKEPKG_ROOT')
20+ }
21+ prefix := os.getenv('CROSS_COMPILE')
22+ mut machine := ['[binaries]', "c = 'vinix-cc'", "cpp = 'vinix-c++'",
23+ "pkg-config = 'pkg-config'", "exe_wrapper = 'vinix-run'"]
24+ for name in ['ar', 'ranlib', 'strip', 'nm', 'objcopy', 'objdump'] {
25+ machine << '${name} = ' + quoted(prefix + name)
26+ }
27+ machine << ['', '[properties]', 'needs_exe_wrapper = true', 'sys_root = ' + quoted(root),
28+ 'pkg_config_libdir = [' + quoted(os.join_path(root, 'usr/lib/pkgconfig')) + ', ' +
29+ quoted(os.join_path(root, 'usr/share/pkgconfig')) + ']', '', '[host_machine]',
30+ "system = 'linux'", 'cpu_family = ' + quoted(arch), 'cpu = ' + quoted(arch), "endian = 'little'"]
31+ file := os.abs_path(args[1]) + '.vinix-cross.ini'
32+ os.write_file(file, machine.join('\n') + '\n')!
33+ for name in ['CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH', 'LIBRARY_PATH', 'PKG_CONFIG_PATH',
34+ 'PKG_CONFIG_LIBDIR', 'PKG_CONFIG_SYSROOT_DIR'] {
35+ os.unsetenv(name)
36+ }
37+ mut options := ['setup', '--cross-file', file, '--prefix=/usr', '--sysconfdir=/etc',
38+ '--libdir=lib', '--buildtype=release']
39+ options << args[2..]
40+ options << [args[1], args[0]]
41+ os.execvp('meson', options)!
42+}
43+
44+fn main() {
45+ setup(os.args[1..]) or {
46+ eprintln(err)
47+ exit(1)
48+ }
49+}
@@ -0,0 +1,39 @@
1+// Run a dynamically linked target program against the installed musl libraries.
2+module main
3+
4+import os
5+
6+fn run(args []string) ! {
7+ root := os.getenv('VPAC_MAKEPKG_ROOT')
8+ host := os.uname().machine
9+ arch := os.getenv_opt('VPAC_TARGET_ARCH') or { host }
10+ if arch !in ['x86_64', 'aarch64'] || !os.is_abs_path(root) {
11+ return error('vinix-run requires a target musl SDK in VPAC_MAKEPKG_ROOT')
12+ }
13+ mut libraries := [os.join_path(root, 'usr/lib'), os.join_path(root, 'lib')]
14+ mut start := 0
15+ if args.len >= 2 && args[0] == '--library-path' {
16+ libraries.prepend(args[1].split(':'))
17+ start = 2
18+ }
19+ if args.len <= start {
20+ return error('usage: vinix-run [--library-path DIRS] PROGRAM [ARG ...]')
21+ }
22+ loader := os.join_path(root, 'lib', 'ld-musl-' + arch + '.so.1')
23+ if !os.is_file(loader) {
24+ return error('missing installed loader: ${loader}')
25+ }
26+ mut cmd := [loader, '--library-path', libraries.join(':')]
27+ cmd << args[start..]
28+ if arch != host {
29+ cmd.prepend('qemu-' + arch)
30+ }
31+ os.execvp(cmd[0], cmd[1..])!
32+}
33+
34+fn main() {
35+ run(os.args[1..]) or {
36+ eprintln(err)
37+ exit(1)
38+ }
39+}
@@ -11,11 +11,7 @@ defpkgbuild(xorgproto,
1111 #:sha256sums, ["4f6b9b4faf91e5df8265b71843a91fc73dc895be6210c84117a996545df296ce"],
1212
1313 #:build, fn() {
14- root := get-environment-variable("VPAC_MAKEPKG_ROOT")
15- run("env", "-u", "CPATH", "-u", "C_INCLUDE_PATH", "-u", "LIBRARY_PATH", "CC=vinix-cc",
16- "PKG_CONFIG_PATH=", string-append("PKG_CONFIG_LIBDIR=", root, "/usr/lib/pkgconfig:", root, "/usr/share/pkgconfig"),
17- string-append("PKG_CONFIG_SYSROOT_DIR=", root),
18- "xorgproto-2024.1/configure", "--build=x86_64-pc-linux-gnu", "--host=x86_64-linux-musl", "--prefix=/usr", "--enable-legacy", "--disable-specs")
14+ run("vinix-configure", "xorgproto-2024.1/configure", "--enable-legacy", "--disable-specs")
1915 run("make")
2016 },
2117 #:check, fn() {