1bf215546Sopenharmony_ci#!/bin/bash
2bf215546Sopenharmony_ci# -*- mode: sh -*-
3bf215546Sopenharmony_ci
4bf215546Sopenharmony_cifunction show_help() {
5bf215546Sopenharmony_ci    cat <<EOF
6bf215546Sopenharmony_ciUsage: intel_stub_gpu [OPTION]... [--] COMMAND ARGUMENTS
7bf215546Sopenharmony_ci
8bf215546Sopenharmony_ciRun COMMAND with ARGUMENTS faking a particular device.
9bf215546Sopenharmony_ci
10bf215546Sopenharmony_ci  -g, --gdb           Launch GDB
11bf215546Sopenharmony_ci
12bf215546Sopenharmony_ci  -p, --platform=NAME Override PCI ID using a platform name
13bf215546Sopenharmony_ci
14bf215546Sopenharmony_ci      --help          Display this help message and exit
15bf215546Sopenharmony_ci
16bf215546Sopenharmony_ciEOF
17bf215546Sopenharmony_ci
18bf215546Sopenharmony_ci    exit 0
19bf215546Sopenharmony_ci}
20bf215546Sopenharmony_ci
21bf215546Sopenharmony_cigdb=""
22bf215546Sopenharmony_ciplatform="skl"
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ciwhile true; do
25bf215546Sopenharmony_ci    case "$1" in
26bf215546Sopenharmony_ci        --gdb)
27bf215546Sopenharmony_ci            gdb=1
28bf215546Sopenharmony_ci            shift
29bf215546Sopenharmony_ci            ;;
30bf215546Sopenharmony_ci        -g)
31bf215546Sopenharmony_ci            gdb=1
32bf215546Sopenharmony_ci            shift
33bf215546Sopenharmony_ci            ;;
34bf215546Sopenharmony_ci        -p)
35bf215546Sopenharmony_ci            platform=$2
36bf215546Sopenharmony_ci            shift 2
37bf215546Sopenharmony_ci            ;;
38bf215546Sopenharmony_ci        -p*)
39bf215546Sopenharmony_ci            platform=${1##-p}
40bf215546Sopenharmony_ci            shift
41bf215546Sopenharmony_ci            ;;
42bf215546Sopenharmony_ci        --platform=*)
43bf215546Sopenharmony_ci            platform=${1##--platform=}
44bf215546Sopenharmony_ci            shift
45bf215546Sopenharmony_ci            ;;
46bf215546Sopenharmony_ci        --help)
47bf215546Sopenharmony_ci            show_help
48bf215546Sopenharmony_ci            ;;
49bf215546Sopenharmony_ci        --)
50bf215546Sopenharmony_ci            shift
51bf215546Sopenharmony_ci            break
52bf215546Sopenharmony_ci            ;;
53bf215546Sopenharmony_ci        -*)
54bf215546Sopenharmony_ci            echo "intel_stub_gpu: invalid option: $1"
55bf215546Sopenharmony_ci            echo
56bf215546Sopenharmony_ci            show_help
57bf215546Sopenharmony_ci            ;;
58bf215546Sopenharmony_ci        *)
59bf215546Sopenharmony_ci            break
60bf215546Sopenharmony_ci            ;;
61bf215546Sopenharmony_ci    esac
62bf215546Sopenharmony_cidone
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci[ -z $1 ] && show_help
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_ciINTEL_STUB_GPU_PLATFORM=$platform
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_cild_preload="@install_libdir@/libintel_noop_drm_shim.so${LD_PRELOAD:+:$LD_PRELOAD}"
69bf215546Sopenharmony_ciif [ -z $gdb ]; then
70bf215546Sopenharmony_ci    LD_PRELOAD=$ld_preload INTEL_STUB_GPU_PLATFORM=$platform exec "$@"
71bf215546Sopenharmony_cielse
72bf215546Sopenharmony_ci    gdb -iex "set exec-wrapper env LD_PRELOAD=$ld_preload INTEL_STUB_GPU_PLATFORM=$platform" --args "$@"
73bf215546Sopenharmony_cifi
74