summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 1736f44512fce3bc35cb7ed226b95781254a5e8b (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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
# Maintainer:

## options
: ${_build_avx:=false}
: ${_build_git:=false}

: ${_commit:=aa955b8ae28314ae061613f0ddf13183a98aca03} # 0.1.r7465
: ${_scripts:=scripts/deps}

unset _pkgtype
[[ "${_build_avx::1}" == "t" ]] && _pkgtype+="-avx"
[[ "${_build_git::1}" == "t" ]] && _pkgtype+="-git"

# basic info
_pkgname="duckstation"
pkgname="$_pkgname${_pkgtype:-}"
pkgver=0.1.7465
pkgrel=1
pkgdesc="Playstation emulator"
url="https://github.com/stenzek/duckstation"
arch=('x86_64')

depends=(
  ## duckstation
  'libwebp'
  'libxrandr'
  'qt6-base'
  'sdl2'
)
makedepends=(
  ## compiler
  'clang'
  'lld'
  'llvm'

  ## build
  'cmake'
  'extra-cmake-modules'
  'git'
  'ninja'

  ## duckstation
  'qt6-tools'
  'qt6-wayland'

  ## fixups
  'patchelf'
  'patchutils' # filterdiff
)

_source_duckstation() {
  license=('GPL-3.0-only')

  _pkgsrc="$_pkgname"
  source=("$_pkgsrc"::"git+$url.git#commit=$_commit")
  sha256sums=('SKIP')

  pkgver() {
    echo "${pkgver:?}"
  }
}

_source_duckstation_git() {
  license=('LicenseRef-Duckstation')

  provides=("$_pkgname")
  conflicts=("$_pkgname")

  _pkgsrc="$_pkgname"
  source=("$_pkgsrc"::"git+$url.git")
  sha256sums=('SKIP')

  pkgver() {
    cd "$_pkgsrc"
    local _tag=$(git tag | sed -E '/^.*[A-Za-z]{2}.*$/d' | sort -rV | head -1)
    local _pkgver=$(sed -E 's/^[^0-9]*//;s/-/./g' <<< "$_tag")
    local _revision=$(git rev-list --count --cherry-pick $_tag...HEAD)
    local _commit=$(git rev-parse --short=7 HEAD)

    printf "%s.r%s.g%s" "${_pkgver:?}" "${_revision:?}" "${_commit:?}"
  }
}

_source_backtrace() {
  source+=(
    "ianlancetaylor.libbacktrace"::"git+https://github.com/ianlancetaylor/libbacktrace.git"
  )
  sha256sums+=(
    'SKIP'
  )
}

_source_cpuinfo() {
  _pkgsrc_cpuinfo="stenzek.cpuinfo"
  source+=(
    "$_pkgsrc_cpuinfo"::"git+https://github.com/stenzek/cpuinfo.git"
  )
  sha256sums+=(
    'SKIP'
  )
}

_source_discord_rpc() {
  _pkgsrc_discord_rpc="stenzek.discord-rpc"
  source+=(
    "$_pkgsrc_discord_rpc"::"git+https://github.com/stenzek/discord-rpc.git"
  )
  sha256sums+=(
    'SKIP'
  )
}

_source_lunasvg() {
  _pkgsrc_lunasvg="stenzek.lunasvg"
  source+=(
    "$_pkgsrc_lunasvg"::"git+https://github.com/stenzek/lunasvg.git"
  )
  sha256sums+=(
    'SKIP'
  )
}

_source_shaderc() {
  depends+=(
    'glslang'
    'spirv-tools'
  )
  makedepends+=(
    'spirv-headers'
  )

  _pkgsrc_shaderc="stenzek.shaderc"
  source+=(
    "$_pkgsrc_shaderc"::"git+https://github.com/stenzek/shaderc.git"
  )
  sha256sums+=(
    'SKIP'
  )
}

_source_soundtouch() {
  _pkgsrc_soundtouch="stenzek.soundtouch"
  source+=(
    "$_pkgsrc_soundtouch"::"git+https://github.com/stenzek/soundtouch.git"
  )
  sha256sums+=(
    'SKIP'
  )
}

_source_spirv_cross() {
  source+=(
    "khronosgroup.spirv-cross"::"git+https://github.com/KhronosGroup/SPIRV-Cross.git"
  )
  sha256sums+=(
    'SKIP'
  )
}

_prepare_backtrace() (
  local _version_backtrace=$(grep -E -m1 'LIBBACKTRACE=' "$_pkgsrc/$_scripts/build-dependencies-linux.sh" | sed -E -e 's&^\s*LIBBACKTRACE=(\S+)$&\1&')
  echo "backtrace = $_version_backtrace"
  git -c advice.detachedHead=false -C "$srcdir/ianlancetaylor.libbacktrace" checkout -f "$_version_backtrace"
)

_prepare_cpuinfo() (
  local _version_cpuinfo=$(grep -E -m1 'CPUINFO=' "$_pkgsrc/$_scripts/build-dependencies-linux.sh" | sed -E -e 's&^\s*CPUINFO=(\S+)$&\1&')
  echo "cpuinfo = $_version_cpuinfo"
  git -c advice.detachedHead=false -C "$srcdir/$_pkgsrc_cpuinfo" checkout -f "$_version_cpuinfo"
)

_prepare_discord_rpc() (
  local _version_discord_rpc=$(grep -E -m1 'DISCORD_RPC=' "$_pkgsrc/$_scripts/build-dependencies-linux.sh" | sed -E -e 's&^\s*DISCORD_RPC=(\S+)$&\1&')
  echo "discord-rpc = $_version_discord_rpc"
  git -c advice.detachedHead=false -C "$srcdir/$_pkgsrc_discord_rpc" checkout -f "$_version_discord_rpc"
)

_prepare_lunasvg() (
  local _version_lunasvg=$(grep -E -m1 'LUNASVG=' "$_pkgsrc/$_scripts/build-dependencies-linux.sh" | sed -E -e 's&^\s*LUNASVG=(\S+)$&\1&')
  echo "lunasvg = $_version_lunasvg"
  git -c advice.detachedHead=false -C "$srcdir/$_pkgsrc_lunasvg" checkout -f "$_version_lunasvg"
)

_prepare_shaderc() (
  local _version_shaderc=$(grep -E -m1 'SHADERC=' "$_pkgsrc/$_scripts/build-dependencies-linux.sh" | sed -E -e 's&^\s*SHADERC=(\S+)$&\1&')
  echo "shaderc = $_version_shaderc"

  git -c advice.detachedHead=false -C "$srcdir/$_pkgsrc_shaderc" checkout -f "$_version_shaderc"

  cd "$srcdir/$_pkgsrc_shaderc"
  sed -E -e '/\(glslc\)/d;/examples/d;/third_party/d' \
    -i CMakeLists.txt
)

_prepare_soundtouch() (
  local _version_soundtouch=$(grep -E -m1 'SOUNDTOUCH=' "$_pkgsrc/$_scripts/build-dependencies-linux.sh" | sed -E -e 's&^\s*SOUNDTOUCH=(\S+)$&\1&')
  echo "soundtouch = $_version_soundtouch"

  git -c advice.detachedHead=false -C "$srcdir/$_pkgsrc_soundtouch" checkout -f "$_version_soundtouch"
)

_prepare_spirv_cross() (
  local _version_spirv_cross=$(grep -E -m1 'SPIRV_CROSS=' "$_pkgsrc/$_scripts/build-dependencies-linux.sh" | sed -E -e 's&^\s*SPIRV_CROSS=(\S+)$&\1&')
  echo "spirv-cross = $_version_spirv_cross"

  git -c advice.detachedHead=false -C "$srcdir/khronosgroup.spirv-cross" checkout -f "$_version_spirv_cross"

  if [ -e "$srcdir/$_pkgsrc/$_scripts/spirv-cross-changes.patch" ]; then
    filterdiff "$srcdir/$_pkgsrc/$_scripts/spirv-cross-changes.patch" \
      > spirv-cross-changes.patch

    cd "khronosgroup.spirv-cross"
    git apply "$srcdir/spirv-cross-changes.patch"
  fi
)

_prepare_duckstation() {
  local _pkgver=$(pkgver)
  _commit=$(git -C "$_pkgsrc" rev-parse HEAD)

  sed -E -e 's@#define AUTO_UPDATER_SUPPORTED@@' \
    -e 's@#if !__has_include\("scmversion/tag.h"\) && !defined\(_DEBUG\)@#if 0@' \
    -i "$_pkgsrc/src/duckstation-qt/autoupdaterdialog.cpp"

  sed -E \
    -e 's&^(\s*).*g_scm_tag_str.*g_scm_branch_str.*$&\1tr("%1").arg(QLatin1StringView(g_scm_tag_str)));&' \
    -e 's! &lt;stenzek@gmail.com&gt;!!' \
    -e 's& \| <a href="https://\S*discord\S+">.*?</a>&&' \
    -e 's&"https://github.com/\S+/CONTRIBUTORS.md"&"'"$url/raw/${_commit}"'/CONTRIBUTORS.md"&' \
    -e 's&"https://github.com/\S+/LICENSE"&"'"$url/raw/${_commit}"'/LICENSE"&' \
    -e 's&"https://github.com/\S+/duckstation"&"'"$url/tree/${_commit}"'"&' \
    -i "$_pkgsrc/src/duckstation-qt/aboutdialog.cpp"

  sed -e '/addaction name="actionIssueTracker"/d' -i "$_pkgsrc/src/duckstation-qt/mainwindow.ui"

  cat > "0000-help-menu.patch" << 'END'
--- a/src/duckstation-qt/mainwindow.ui
+++ b/src/duckstation-qt/mainwindow.ui
@@ -126,11 +126,6 @@
     <property name="title">
      <string>&amp;Help</string>
     </property>
-    <addaction name="actionGitHubRepository"/>
-    <addaction name="actionDiscordServer"/>
-    <addaction name="separator"/>
-    <addaction name="actionCheckForUpdates"/>
-    <addaction name="separator"/>
     <addaction name="actionViewThirdPartyNotices"/>
     <addaction name="actionAboutQt"/>
     <addaction name="actionAbout"/>
END

  patch -Np1 -F100 -d "$_pkgsrc" -i "../0000-help-menu.patch"

  cat >> "$_pkgsrc/src/scmversion/tag.h" << EOF
#pragma once
#define SCM_RELEASE_ASSET "$pkgname"
#define SCM_RELEASE_TAGS {"latest", "preview"}
#define SCM_RELEASE_TAG "latest"
EOF

  install -Dm755 /dev/stdin "$_pkgsrc/src/scmversion/gen_scmversion.sh" << END
#!/bin/sh
HASH="$(git -C "$_pkgsrc" rev-parse HEAD)"
BRANCH=""
TAG="$_pkgver (AUR)"
DATE=$(git -C "$_pkgsrc" log -1 --date=iso8601-strict --format=%cd)

cat > "scmversion.cpp" << EOF
const char* g_scm_hash_str = "\${HASH}";
const char* g_scm_branch_str = "\${BRANCH}";
const char* g_scm_tag_str = "\${TAG}";
const char* g_scm_date_str = "\${DATE}";

EOF
END
}

_build_backtrace() (
  echo "Building libbacktrace..."
  cd "ianlancetaylor.libbacktrace"

  autoreconf -fi
  ./configure
  make

  install -Dm644 .libs/libbacktrace.a -t "$srcdir/deps/"
  install -Dm644 *.h -t "$srcdir/deps/include/"
)

_build_cpuinfo() {
  echo "Building cpuinfo..."
  local _cmake_cpuinfo=(
    -B build_cpuinfo
    -S "$_pkgsrc_cpuinfo"
    -G Ninja
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_INSTALL_PREFIX=/usr
    -DCPUINFO_LIBRARY_TYPE=shared
    -DCPUINFO_RUNTIME_TYPE=shared
    -DCPUINFO_LOG_LEVEL=error
    -DCPUINFO_LOG_TO_STDIO=ON
    -DCPUINFO_BUILD_TOOLS=OFF
    -DCPUINFO_BUILD_UNIT_TESTS=OFF
    -DCPUINFO_BUILD_MOCK_TESTS=OFF
    -DCPUINFO_BUILD_BENCHMARKS=OFF
    -DUSE_SYSTEM_LIBS=ON
    -Wno-dev
  )

  cmake "${_cmake_cpuinfo[@]}"
  cmake --build build_cpuinfo
  DESTDIR="$srcdir/deps" cmake --install build_cpuinfo
}

_build_discord_rpc() {
  echo "Building discord-rpc..."
  local _cmake_discord_rpc=(
    -B build_discord_rpc
    -S "$_pkgsrc_discord_rpc"
    -G Ninja
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_INSTALL_PREFIX=/usr
    -DBUILD_SHARED_LIBS=ON
    -Wno-dev
  )

  cmake "${_cmake_discord_rpc[@]}"
  cmake --build build_discord_rpc
  DESTDIR="$srcdir/deps" cmake --install build_discord_rpc
}

_build_lunasvg() {
  echo "Building lunasvg..."
  local _cmake_lunasvg=(
    -B build_lunasvg
    -S "$_pkgsrc_lunasvg"
    -G Ninja
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_INSTALL_PREFIX=/usr
    -DBUILD_SHARED_LIBS=ON
    -Wno-dev
  )

  cmake "${_cmake_lunasvg[@]}"
  cmake --build build_lunasvg
  DESTDIR="$srcdir/deps" cmake --install build_lunasvg
}

_build_shaderc() {
  echo "Building shaderc..."
  local _cmake_shaderc=(
    -B build_shaderc
    -S "$_pkgsrc_shaderc"
    -G Ninja
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_INSTALL_PREFIX=/usr
    -DSHADERC_SKIP_TESTS=ON
    -DSHADERC_SKIP_EXAMPLES=ON
    -DSHADERC_SKIP_COPYRIGHT_CHECK=ON
    -Dglslang_SOURCE_DIR=/usr/include/glslang
    -Wno-dev
  )

  cmake "${_cmake_shaderc[@]}"
  cmake --build build_shaderc
  DESTDIR="$srcdir/deps" cmake --install build_shaderc
}

_build_soundtouch() {
  echo "Building soundtouch..."

  local _cmake_soundtouch=(
    -B build_soundtouch
    -S "$_pkgsrc_soundtouch"
    -G Ninja
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_INSTALL_PREFIX=/usr
    -DBUILD_SHARED_LIBS=ON
    -Wno-dev
  )

  cmake "${_cmake_soundtouch[@]}"
  cmake --build build_soundtouch
  DESTDIR="$srcdir/deps" cmake --install build_soundtouch
}

_build_spirv_cross() {
  echo "Building spirv-cross..."

  local _cmake_spirv_cross=(
    -B build_spirv_cross
    -S "khronosgroup.spirv-cross"
    -G Ninja
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_INSTALL_PREFIX=/usr
    -DSPIRV_CROSS_SHARED=ON
    -DSPIRV_CROSS_STATIC=OFF
    -DSPIRV_CROSS_CLI=OFF
    -DSPIRV_CROSS_ENABLE_TESTS=OFF
    -DSPIRV_CROSS_ENABLE_GLSL=ON
    -DSPIRV_CROSS_ENABLE_HLSL=OFF
    -DSPIRV_CROSS_ENABLE_MSL=OFF
    -DSPIRV_CROSS_ENABLE_CPP=OFF
    -DSPIRV_CROSS_ENABLE_REFLECT=OFF
    -DSPIRV_CROSS_ENABLE_C_API=ON
    -DSPIRV_CROSS_ENABLE_UTIL=ON
    -Wno-dev
  )

  cmake "${_cmake_spirv_cross[@]}"
  cmake --build build_spirv_cross
  DESTDIR="$srcdir/deps" cmake --install build_spirv_cross
}

_build_duckstation() {
  echo "Building duckstation..."

  local _cmake_options=(
    -B build
    -S "$_pkgsrc"
    -G Ninja
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_SKIP_RPATH=ON
    -DBUILD_NOGUI_FRONTEND=OFF
    -DBUILD_QT_FRONTEND=ON
    -DDiscordRPC_DIR="$srcdir/deps/usr/lib/cmake/DiscordRPC"
    -DLIBBACKTRACE_INCLUDE_DIR="$srcdir/deps/include"
    -DLIBBACKTRACE_LIBRARY="$srcdir/deps/libbacktrace.a"
    -DSHADERC_INCLUDE_DIR="$srcdir/deps/usr/include"
    -DSHADERC_LIBRARY="$srcdir/deps/usr/lib/libshaderc_shared.so"
    -DShaderc_DIR="$srcdir/deps/usr/lib/cmake/Shaderc" # git
    -DSoundTouch_DIR="$srcdir/deps/usr/lib/cmake/SoundTouch"
    -Dcpuinfo_DIR="$srcdir/deps/usr/share/cpuinfo"
    -Dlunasvg_DIR="$srcdir/deps/usr/lib/cmake/lunasvg"
    -Dspirv_cross_c_shared_DIR="$srcdir/deps/usr/share/spirv_cross_c_shared/cmake"
    -Wno-dev
  )

  cmake "${_cmake_options[@]}"
  cmake --build build
}

_build_env() {
  export AR CC CXX CFLAGS CXXFLAGS LDFLAGS
  AR="llvm-ar"
  CC="clang"
  CXX="clang++"
  LDFLAGS+=" -fuse-ld=lld"

  if [[ "${_build_avx::1}" == "t" ]]; then
    export CFLAGS="$(echo "$CFLAGS" | sed -E 's@(\s*-(march|mtune)=\S+\s*)@ @g;s@\s*-O[0-9]\s*@ @g;s@\s+@ @g') -march=x86-64-v3 -mtune=generic -O3"
    export CXXFLAGS="$(echo "$CXXFLAGS" | sed -E 's@(\s*-(march|mtune)=\S+\s*)@ @g;s@\s*-O[0-9]\s*@ @g;s@\s+@ @g') -march=x86-64-v3 -mtune=generic -O3"
  fi
}

prepare() {
  _prepare_backtrace
  _prepare_cpuinfo
  _prepare_discord_rpc
  _prepare_lunasvg
  _prepare_shaderc
  _prepare_soundtouch
  _prepare_spirv_cross

  _prepare_duckstation
}

build() {
  _build_env

  _build_backtrace
  _build_cpuinfo
  _build_discord_rpc
  _build_lunasvg
  _build_shaderc
  _build_soundtouch
  _build_spirv_cross

  _build_duckstation
}

package() {
  install -dm755 "$pkgdir/opt/$_pkgname/"
  cp --reflink=auto -r build/bin/{resources,translations,duckstation-qt} "$pkgdir/opt/$_pkgname/"

  # rpath
  patchelf --force-rpath --set-rpath "/opt/$_pkgname" "$pkgdir/opt/$_pkgname/$_pkgname-qt"

  # libraries
  install -Dm644 "$srcdir/deps/usr/lib"/*.so* -t "$pkgdir/opt/$_pkgname/"

  # icon
  install -Dm644 "$pkgdir/opt/$_pkgname/resources/images/duck.png" "$pkgdir/usr/share/pixmaps/$_pkgname.png"

  # script
  install -Dm755 /dev/stdin "$pkgdir/usr/bin/$_pkgname" << END
#!/usr/bin/env sh
exec /opt/$_pkgname/$_pkgname-qt "\$@"
END

  # launcher
  install -Dm644 /dev/stdin "$pkgdir/usr/share/applications/$_pkgname.desktop" << END
[Desktop Entry]
Type=Application
Name=DuckStation
GenericName=PlayStation Emulator
Comment=PlayStation emulator
Icon=$_pkgname
TryExec=$_pkgname
Exec=$_pkgname %f
Terminal=false
StartupNotify=true
Categories=Game;Emulator;Qt;
END

  # permissions
  chmod -R u+rwX,go+rX,go-w "$pkgdir/"
}

if [[ "${_build_git::1}" == "t" ]]; then
  _source_duckstation_git
else
  _source_duckstation
fi

_source_backtrace
_source_cpuinfo
_source_discord_rpc
_source_lunasvg
_source_shaderc
_source_soundtouch
_source_spirv_cross