summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 3946afc3821b2e685edbbf85fe262f01c4455524 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# Contributor: katt <magunasu.b97@gmail.com>

## options
: ${i_swear_to_never_bother_the_developer_about_this_package:=false}
: ${forbidden_versions_file_path:=/dev/null}

pkgname=duckstation-git
_pkgname=duckstation
pkgver=0.1.r9727.g66bef3e3e
pkgdesc='A Sony PlayStation (PSX) emulator, focusing on playability, speed, and long-term maintainability (git version)'
pkgrel=1
arch=(x86_64 aarch64)
url=https://github.com/stenzek/duckstation
license=(CC-BY-NC-ND-4.0)
depends=(
    sh
    glibc
    gcc-libs
    sdl3
    qt6-base
    libbacktrace.so
    libwebp.so
    libjpeg.so
    libpng16.so
    libxcb
    libx11
    freetype2 libfreetype.so
    libzstd.so
    libz.so
    libzip.so
    libdbus-1.so
    libcurl.so
    systemd-libs libudev.so
    hicolor-icon-theme
)
makedepends=(
    git
    yq
    cmake
    clang
    lld
    llvm
    extra-cmake-modules
    qt6-tools
    qt6-wayland
    libdrm
    libpulse
    alsa-lib
    sndio
    ninja
    jack
    python
    spirv-headers
    patchelf
)
optdepends=(
    'qt6-wayland: Wayland support'
    'libpulse: Pulseaudio support'
    'sndio: Small audio support'
    'alsa-lib: ALSA support'
    'jack: JACK support'
    'ffmpeg: Video capture support'
)
options=(lto)
provides=(duckstation)
conflicts=(duckstation)
source=(
    git+"$url".git
    stenzek.shaderc::git+https://github.com/stenzek/shaderc.git
    spirv-cross::git+https://github.com/KhronosGroup/SPIRV-Cross.git
    stenzek.cpuinfo::git+https://github.com/stenzek/cpuinfo.git
    stenzek.discord-rpc::git+https://github.com/stenzek/discord-rpc.git
    stenzek.soundtouch::git+https://github.com/stenzek/soundtouch.git
    stenzek.plutosvg::git+https://github.com/stenzek/plutosvg.git
    https://github.com/duckstation/chtdb/releases/download/latest/cheats.zip
    https://github.com/duckstation/chtdb/releases/download/latest/patches.zip
    duckstation-qt.desktop
    duckstation-qt.sh)
sha256sums=('SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'ec2d7358f81598390a8ceca2d1974be3e5f7c45602b550c89a1e9323ab45474b'
            '221a8fc0d1f0cebdf281acc26484e98ebbb59f876e12fdef3f03cf91380e31f5')
noextract=(
    cheats.zip
    patches.zip
)

_source_var=(
    "stenzek.shaderc:SHADERC"
    "spirv-cross:SPIRV_CROSS:SPIRV-Cross"
    "stenzek.cpuinfo:CPUINFO"
    "stenzek.discord-rpc:DISCORD_RPC"
    "stenzek.soundtouch:SOUNDTOUCH"
    "stenzek.plutosvg:PLUTOSVG"
)

pkgver() {
    cd "$srcdir/$_pkgname"
    git describe | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
    # checkout correct versions of deps
    if [[ "$forbidden_versions_file_path" == "/dev/null" ]]; then
        cat <<EOF
Stenzek prohibits using the versions file in this build script.
Set the path to the dependencies versions file (from scripts/)
in the forbidden_versions_file_path variable, relative to the project root.
EOF
        exit 1
    fi

    deps_script=$srcdir/duckstation/$forbidden_versions_file_path

    # unbreak the build
    sed -i 's/3ebbfd45645650c4940bf0f3b4d25ab913466bb0/cdcd4afba44326d12206493620b3e0aa4935f311/g' "$deps_script"

    for src in "${source[@]}"; do
        local src_name=${src%%::*}
        for dep in "${_source_var[@]}"; do
            local dep_name dep_var
            IFS=':' read dep_name dep_var _ <<< "$dep"
            if [ "$src_name" = "$dep_name" ]; then
                local dep_ver
                dep_ver=$(grep -Po "(?<=^$dep_var=).+" "$deps_script" )
                echo "Checking out $dep_ver for $src_name..."
                git -C "$srcdir/$src_name" checkout -q "$dep_ver"
            fi
        done
    done

    # bundle additional resources
    cp "$srcdir/cheats.zip" "$srcdir/patches.zip" "$srcdir/duckstation/data/resources"

    # unbreak the build
    if [ "$i_swear_to_never_bother_the_developer_about_this_package" = "true" ]; then
        cd "$srcdir/duckstation"
        sed -i 's/archlinux/marchlinux/g' CMakeModules/DuckStationBuildSummary.cmake
        sed -i '/#ifdef __linux__/,/#endif/d' src/core/system.cpp
        sed -i '/CMAKE_FIND_ROOT_PATH/d' CMakeModules/DuckStationDependencies.cmake
        sed -i 's/NOT Qt6_DIR MATCHES/Qt6_DIR MATCHES/' CMakeModules/DuckStationDependencies.cmake
    fi

}

build() {
    deps_script=$srcdir/duckstation/scripts/deps/build-dependencies-linux.sh
    for src in "${source[@]}"; do
        local src_name=${src%%::*}
        for dep in "${_source_var[@]}"; do
            local dep_name dep_var dep_dir
            IFS=':' read dep_name dep_var dep_dir <<< "$dep"
            if [ "$src_name" = "$dep_name" ]; then
                [ -z "$dep_dir" ] && dep_dir=$dep_var
                local dep_opts
                dep_opts=$(
                    awk -v dir="$dep_dir" -v var="$dep_var" '
                      $0 ~ "^cd.+\\$" var {in_block=1; next}
                      $0 ~ "^cd.+" dir {in_block=1; next}
                      $0 ~ "^cd \\.\\." && in_block {in_block=0}
                      in_block
                    ' "$deps_script" | tr ' ' '\n' | grep '^-D' | grep -Ev '_COMPILER|_PREFIX_PATH|_INSTALL_PREFIX')

                echo "Building $dep_name..."
                cmake -B "build-$dep_name" -S "$src_name" \
                    -G Ninja \
                    -DCMAKE_C_COMPILER=clang \
                    -DCMAKE_CXX_COMPILER=clang++ \
                    -DCMAKE_EXE_LINKER_FLAGS_INIT="-fuse-ld=lld" \
                    -DCMAKE_MODULE_LINKER_FLAGS_INIT="-fuse-ld=lld" \
                    -DCMAKE_SHARED_LINKER_FLAGS_INIT="-fuse-ld=lld" \
                    -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
                    -DCMAKE_INSTALL_PREFIX=/usr \
                    $dep_opts
                ninja -C "build-$dep_name"
                DESTDIR="$srcdir/deps" ninja -C "build-$dep_name" install
            fi
        done
    done

    echo "Building duckstation..."

    cmake -B build -S duckstation \
        -G Ninja \
        -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_C_COMPILER=clang \
        -DCMAKE_CXX_COMPILER=clang++ \
        -DCMAKE_C_FLAGS="$CFLAGS -Wno-error=format-security" \
        -DCMAKE_CXX_FLAGS="$CXXFLAGS -Wno-error=format-security" \
        -DCMAKE_EXE_LINKER_FLAGS_INIT="-fuse-ld=lld" \
        -DCMAKE_MODULE_LINKER_FLAGS_INIT="-fuse-ld=lld" \
        -DCMAKE_SHARED_LINKER_FLAGS_INIT="-fuse-ld=lld" \
        -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \
        -DCMAKE_PREFIX_PATH="$srcdir/deps/usr" \
        -Dzstd_INCLUDE_DIR="/usr/include/" \
        -Wno-dev
    ninja -C build
}

package() {
    # Install everything into /usr/lib/duckstation
    install -m 755 -d "${pkgdir}/usr/lib"
    cp -drv --no-preserve='ownership' build/bin "${pkgdir}/usr/lib/${_pkgname}"
    # Install bundled libraries
    find "${srcdir}/deps/usr/lib" -name '*.so*' -exec cp -dv --no-preserve='ownership' '{}' "${pkgdir}/usr/lib/${_pkgname}/" \;

    # patch rpath
    patchelf --force-rpath --set-rpath "/usr/lib/${_pkgname}" "${pkgdir}/usr/lib/${_pkgname}/$_pkgname-qt"

    # Install additional license
    install -Dvm644 "${pkgdir}/usr/lib/${_pkgname}/resources/thirdparty.html" "${pkgdir}/usr/share/licenses/${pkgname}/thirdparty.html"

    install -Dvm755 "${srcdir}/duckstation-qt.sh" "${pkgdir}/usr/bin/duckstation-qt"
    install -Dvm644 "${srcdir}/duckstation-qt.desktop" "${pkgdir}/usr/share/applications/duckstation-qt.desktop"
    install -Dvm644 "${pkgdir}/usr/lib/${_pkgname}/resources/images/duck.png" "${pkgdir}/usr/share/icons/hicolor/64x64/apps/duckstation-qt.png"
}