#!/usr/bin/env -S v run import imp // one architecture per build: vab links every ABI against the same -L path, and // lld stops at the first libmpv.so it finds (libvendetta/mpv/android/README.md) const android_arch = 'arm64-v8a' const android_kit = 'libvendetta/mpv/android' const android_lib = '${android_kit}/lib' // libplayer.so also ships in the kit, but is mpv-android's and is not needed const android_libs = ['libmpv.so', 'libavcodec.so', 'libavdevice.so', 'libavfilter.so', 'libavformat.so', 'libavutil.so', 'libc++_shared.so', 'libswresample.so', 'libswscale.so'] const android_headers = ['client.h', 'render.h', 'render_gl.h'] mut ctx := imp.new() android := ctx.flag(id: 'android', help: 'build an apk') target_exe := if android { 'vendetta.apk' } else { $if windows { 'vendetta.exe' } $else { 'vendetta' } } ctx.default(['build']) ctx.add_target(target_exe) ctx.add_flow( id: 'check' help: 'check external dependencies' flow: fn (self imp.Flow) ! { mut missing := []string{} if !imp.check_v_modules(['ui2']) { missing << 'ui2' } if self.flag('android') { if !imp.check_binary(['vab']) { missing << 'vab' } for lib in android_libs { path := '${android_lib}/${android_arch}/${lib}' if !exists(path) { missing << path } } for header in android_headers { path := '${android_kit}/include/mpv/${header}' if !exists(path) { missing << path } } } else { if !imp.check_system_c_links(['mpv/client.h', 'mpv/render.h', 'mpv/render_gl.h'], flags: ['-lmpv']) { missing << 'libmpv headers' } if !imp.check_system_c_links(['X11/Xlib.h', 'X11/Xutil.h', 'X11/keysym.h', 'X11/Xatom.h'], flags: ['-lX11']) { missing << 'libX11 headers' } if !imp.check_system_c_links(['X11/extensions/Xrandr.h'], flags: ['-lXrandr']) { missing << 'libXrandr headers' } if !imp.check_system_c_links(['X11/extensions/XInput2.h'], flags: ['-lXi']) { missing << 'libXi headers' } if !imp.check_system_c_links(['X11/Xcursor/Xcursor.h'], flags: ['-lXcursor']) { missing << 'libXcursor headers' } if !imp.check_system_c_links(['GL/gl.h'], flags: ['-lGL', '-I/usr/include', '-I/usr/local/include', '-w']) { missing << 'libGL headers' } if !imp.check_system_c_links(['dlfcn.h'], flags: ['-ldl']) { missing << 'dlfcn.h' } if !imp.check_system_c_links(['pthread.h'], flags: ['-lpthread']) { missing << 'pthread.h' } if !imp.check_system_c_links(['math.h'], flags: ['-lm']) { missing << 'math.h' } } if missing.len > 0 { println('could not find:') println(missing.join('\n')) if self.flag('android') { println('see ${android_kit}/README.md for the mpv-android build') } println('check failed, exiting...') exit(1) } } ) ctx.add_flow( id: 'build' help: 'build the release binary' takes: if android { ['src', 'libvendetta', 'java'] } else { ['src', 'libvendetta'] } gives: [target_exe] check: .mtime pre: if android { [imp.FlowDep{id: 'check'}] } else { []imp.FlowDep{} } flags: [ imp.Flag{id: 'prod', help: 'optimised desktop build'}, imp.Flag{id: 'mpris', help: 'enable mpris support'}, ] flow: fn [target_exe] (self imp.Flow) ! { mut args := []string{} if self.flag('android') { flat_link := '${android_lib}/libmpv.so' if real_path(flat_link) != real_path('${android_lib}/${android_arch}/libmpv.so') { rm(flat_link) or {} symlink('${android_arch}/libmpv.so', flat_link)! } args << [ 'vab', '--archs', android_arch, '--name', 'Vendetta', '--package-id', 'vorelabs.vendetta', '--libs', abs_path(android_lib), '--package-overrides', abs_path('java'), '-f', '-d sokol_gles3', 'src', ] } else { args << 'v' $if darwin { args << ['-d', 'darwin_sokol_glcore33'] } if self.flag('mpris') { args << ['-d', 'mpris'] } if self.flag('prod') { args << '-prod' } args << ['-d', 'ui2_custom_rendering', '-o', target_exe, 'src'] } imp.system_args(args)! } ) ctx.add_auto_flow(.clean) if !android { ctx.add_auto_flow(.run) } ctx.flow()