diff --git a/bin/mangohud.in b/bin/mangohud.in new file mode 100755 index 00000000..0d4f5cdc --- /dev/null +++ b/bin/mangohud.in @@ -0,0 +1,21 @@ +#!/bin/sh + +MANGOHUD_LIB_NAME="libMangoHud.so" +if [ "$MANGOHUD_NODLSYM" = "1" ]; then + MANGOHUD_LIB_NAME="libMangoHud_nodlsym.so" +fi + +if [ "$#" -eq 0 ]; then + programname=`basename "$0"` + echo "ERROR: No program supplied" + echo + echo "Usage: $programname " + exit 1 +fi + +# Execute the program under a clean environment +# pass through the overriden LD_PRELOAD environment variables +LD_PRELOAD="${LD_PRELOAD}:${MANGOHUD_LIB_NAME}" +LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:@libdir_mangohud@" + +exec env MANGOHUD=1 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" LD_PRELOAD="${LD_PRELOAD}" "$@" diff --git a/build.sh b/build.sh index 3560661e..311ed6bf 100755 --- a/build.sh +++ b/build.sh @@ -109,14 +109,14 @@ configure() { dependencies git submodule update --init --depth 50 if [[ ! -f "build/meson64/build.ninja" ]]; then - meson build/meson64 --libdir lib64 --prefix "$PWD/build/release/usr" + meson build/meson64 --libdir lib/mangohud/lib64 --prefix /usr -Dusing_build_sh=true fi if [[ ! -f "build/meson32/build.ninja" ]]; then export CC="gcc -m32" export CXX="g++ -m32" export PKG_CONFIG_PATH="/usr/lib32/pkgconfig:/usr/lib/i386-linux-gnu/pkgconfig:/usr/lib/pkgconfig:${PKG_CONFIG_PATH_32}" export LLVM_CONFIG="/usr/bin/llvm-config32" - meson build/meson32 --libdir lib32 --prefix "$PWD/build/release/usr" + meson build/meson32 --libdir lib/mangohud/lib32 --prefix /usr -Dmangohud_prefix=lib32- -Dusing_build_sh=true fi } @@ -124,30 +124,18 @@ build() { if [[ ! -f "build/meson64/build.ninja" ]]; then configure fi - ninja -C build/meson32 install - ninja -C build/meson64 install + DESTDIR="$PWD/build/release" ninja -C build/meson32 install + DESTDIR="$PWD/build/release" ninja -C build/meson64 install } package() { - LIB="build/release/usr/lib64/mangohud/libMangoHud.so" - LIB32="build/release/usr/lib32/mangohud/libMangoHud.so" + LIB="build/release/usr/lib/mangohud/lib64/libMangoHud.so" + LIB32="build/release/usr/lib/mangohud/lib32/libMangoHud.so" if [[ ! -f "$LIB" || "$LIB" -ot "build/meson64/src/libMangoHud.so" ]]; then build fi - mkdir -p "$INSTALL_DIR/usr/bin" - mkdir -p "$INSTALL_DIR/usr/lib/MangoHud" - mkdir -p "$INSTALL_DIR/usr/lib/MangoHud/"{lib32,lib64} - mkdir -p "$INSTALL_DIR/usr/share/vulkan/implicit_layer.d" - mkdir -p "$INSTALL_DIR/etc/ld.so.conf.d" - - cp libmangohud.conf "$INSTALL_DIR/etc/ld.so.conf.d/libmangohud.conf" - cp "$LIB" "$INSTALL_DIR/usr/lib/MangoHud/lib64/libMangoHud.so" - cp "$LIB32" "$INSTALL_DIR/usr/lib/MangoHud/lib32/libMangoHud.so" - cp "$LAYER" "$INSTALL_DIR/usr/share/vulkan/implicit_layer.d/" - cp --preserve=mode "build/release/usr/bin/mangohud" "$INSTALL_DIR/usr/bin/mangohud" - tar --numeric-owner --owner=0 --group=0 \ - -C build/package -cvf "build/MangoHud-package.tar" . + -C build/release -cvf "build/MangoHud-package.tar" . } release() { @@ -179,9 +167,10 @@ clean() { uninstall() { [ "$UID" -eq 0 ] || exec sudo bash "$0" uninstall - rm -rfv "/usr/lib/MangoHud" + rm -rfv "/usr/lib/mangohud" rm -fv "/usr/share/vulkan/implicit_layer.d/mangohud.json" rm -fv "/etc/ld.so.conf.d/libmangohud.conf" + rm -fv "/etc/ld.so.conf.d/lib32-libmangohud.conf" rm -fv "/usr/bin/mangohud" } diff --git a/libmangohud.conf.in b/libmangohud.conf.in new file mode 100644 index 00000000..4a68d757 --- /dev/null +++ b/libmangohud.conf.in @@ -0,0 +1 @@ +@libdir_mangohud@ diff --git a/meson.build b/meson.build index 3ab015bb..78c1d568 100644 --- a/meson.build +++ b/meson.build @@ -30,6 +30,12 @@ cpp = meson.get_compiler('cpp') prog_python = import('python').find_installation('python3') null_dep = dependency('', required : false) +# Needs prefix for configure_file() +libdir_mangohud = join_paths(get_option('prefix'), get_option('libdir'), 'mangohud') +if get_option('using_build_sh') + libdir_mangohud = join_paths(get_option('prefix'), get_option('libdir')) +endif + pre_args = [ '-D__STDC_CONSTANT_MACROS', '-D__STDC_FORMAT_MACROS', @@ -207,6 +213,12 @@ vk_enum_to_str = custom_target( ], ) +configure_file(input : 'libmangohud.conf.in', + output : get_option('mangohud_prefix') + 'libmangohud.conf', + configuration : { 'libdir_mangohud' : libdir_mangohud }, + install_dir : join_paths(get_option('sysconfdir'), 'ld.so.conf.d'), +) + util_files = files( 'src/mesa/util/os_socket.c', 'src/mesa/util/os_time.c', diff --git a/meson_options.txt b/meson_options.txt index 9d1d8279..a2e30de2 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,2 +1,4 @@ option('glibcxx_asserts', type : 'boolean', value : false) option('use_system_vulkan', type : 'feature', value : 'disabled', description: 'Use system vulkan headers instead of the provided ones') +option('mangohud_prefix', type : 'string', value : '', description: 'Add prefix to cross-compiled library, like "lib32-".') +option('using_build_sh', type : 'boolean', value : false, description: 'Add "mangohud" suffix to libdir or not.') diff --git a/src/mangohud.json.in b/src/mangohud.json.in new file mode 100644 index 00000000..0ad12267 --- /dev/null +++ b/src/mangohud.json.in @@ -0,0 +1,22 @@ +{ + "file_format_version" : "1.0.0", + "layer" : { + "name": "MangoHud", + "type": "GLOBAL", + "api_version": "1.1.125", + "library_path": "@libdir_mangohud@/libMangoHud.so", + "implementation_version": "1", + "description": "Vulkan Hud Overlay", + "functions": { + "vkGetInstanceProcAddr": "overlay_GetInstanceProcAddr", + "vkGetDeviceProcAddr": "overlay_GetDeviceProcAddr" + }, + "enable_environment": { + "MANGOHUD": "1" + }, + "disable_environment": { + "DISABLE_MANGOHUD": "1" + } + } +} + \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index b3acc230..c7434a99 100644 --- a/src/meson.build +++ b/src/meson.build @@ -83,10 +83,16 @@ vklayer_mesa_overlay = shared_library( dep_vulkan], include_directories : [inc_common, inc_opengl], link_args : cc.get_supported_link_arguments(['-Wl,-Bsymbolic-functions', '-Wl,-z,relro']), - install_dir : join_paths(get_option('libdir'), 'mangohud'), + install_dir : libdir_mangohud, install : true ) +#configure_file(input : 'mangohud.json.in', +# output : 'mangohud.json', +# configuration : { 'libdir_mangohud' : libdir_mangohud }, +# install_dir : join_paths(get_option('datadir'), 'vulkan', 'implicit_layer.d'), +#) + install_data( files('mangohud.json'), install_dir : join_paths(get_option('datadir'), 'vulkan', 'implicit_layer.d'),