summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: a0f6ee7f2c71c62dd03249ec3e9ab984deb94fb8 (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
# Maintainer:

## useful commands
# LLVM_PROFILE_FILE="default_%9m.profraw" pcsx2-qt
# llvm-profdata merge -output=pcsx2-avx-git.profdata *.profraw

## options
: ${_build_debug:=false}
: ${_build_pgo:=try}

: ${_build_clang:=true}
: ${_build_mold:=true}
: ${_build_git_tools:=false}

: ${_build_instrumented:=false}

: ${_build_avx:=true}
: ${_build_git:=true}

unset _tooltype # clang-git, llvm-git, lld-git, mold-git
[[ "${_build_git_tools::1}" == "t" ]] && _tooltype+="-git"

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

# basic info
_pkgname="pcsx2"
pkgname="$_pkgname${_pkgtype:-}"
pkgver=1.7.5720.r0.g6d8a906
pkgrel=1
pkgdesc='Sony PlayStation 2 emulator'
url="https://github.com/PCSX2/pcsx2"
license=('GPL-3.0-only' 'LGPL-3.0-only')
arch=('x86_64')

# main package
_main_package() {
  depends=(
    alsa-lib
    ffmpeg
    libaio
    libglvnd
    libpcap
    libpng
    libxrandr
    qt6-base
    qt6-svg
    sdl2
    soundtouch
    wayland
    xcb-util-cursor
  )
  makedepends=(
    cmake
    extra-cmake-modules
    git
    libpipewire
    libpulse
    ninja
    p7zip
    qt6-tools
    qt6-wayland
  )
  optdepends=(
    'qt6-wayland: Wayland support'
  )

  if [[ "${_build_clang::1}" == "t" ]]; then
    makedepends+=(
      "clang${_tooltype:-}"
      "llvm${_tooltype:-}"
      "lld${_tooltype:-}"
    )
  fi

  if [[ "${_build_mold::1}" == "t" ]]; then
    makedepends+=(
      "mold${_tooltype:-}"
    )
  fi

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

  install="$_pkgname.install"

  if [[ "${_build_debug::1}" == "t" ]]; then
    options=(debug !lto)
  else
    options=(!debug lto)
  fi

  _pkgsrc="$_pkgname"
  source=(
    "$_pkgsrc"::"git+$url.git"
    "pcsx2_patches"::"git+https://github.com/PCSX2/pcsx2_patches.git"
  )
  sha256sums=(
    'SKIP'
    'SKIP'
  )

  _source_pcsx2

  _source_biojppm_rapidyaml
  _source_biojppm_c4core
}

# submodules
_source_pcsx2() {
  source+=(
    'biojppm.rapidyaml'::'git+https://github.com/biojppm/rapidyaml.git'
    'fmtlib.fmt'::'git+https://github.com/fmtlib/fmt.git'
    'google.googletest'::'git+https://github.com/google/googletest.git'
    'khronosgroup.vulkan-headers'::'git+https://github.com/KhronosGroup/Vulkan-Headers.git'
    'microsoft.wil'::'git+https://github.com/microsoft/wil.git'
  )
  sha256sums+=(
    'SKIP'
    'SKIP'
    'SKIP'
    'SKIP'
    'SKIP'
  )

  _prepare_pcsx2() (
    cd "$_pkgsrc"
    local _submodules=(
      'biojppm.rapidyaml'::'3rdparty/rapidyaml/rapidyaml'
      'fmtlib.fmt'::'3rdparty/fmt/fmt'
      'google.googletest'::'3rdparty/gtest'
      'khronosgroup.vulkan-headers'::'3rdparty/vulkan-headers'
      'microsoft.wil'::'3rdparty/wil'
    )
    _submodule_update
  )
}

_source_biojppm_rapidyaml() {
  source+=(
    'biojppm.c4core'::'git+https://github.com/biojppm/c4core.git'
  )
  sha256sums+=(
    'SKIP'
  )

  _prepare_biojppm_rapidyaml() (
    cd "$_pkgsrc"
    cd '3rdparty/rapidyaml/rapidyaml'
    local _submodules=(
      'biojppm.c4core'::'ext/c4core'
    )
    _submodule_update
  )
}

_source_biojppm_c4core() {
  source+=(
    'biojppm.cmake'::'git+https://github.com/biojppm/cmake.git'
    'biojppm.debugbreak'::'git+https://github.com/biojppm/debugbreak.git'
    'fastfloat.fast_float'::'git+https://github.com/fastfloat/fast_float.git'
  )
  sha256sums+=(
    'SKIP'
    'SKIP'
    'SKIP'
  )

  _prepare_biojppm_c4core() (
    cd "$_pkgsrc"
    cd '3rdparty/rapidyaml/rapidyaml'
    cd 'ext/c4core'
    local _submodules=(
      'biojppm.cmake'::'cmake'
      'biojppm.debugbreak'::'src/c4/ext/debugbreak'
      'fastfloat.fast_float'::'src/c4/ext/fast_float'
    )
    _submodule_update
  )
}

_build_pcsx2() {
  local _cmake_pcsx2

  _cmake_pcsx2+=(
    -S "$_pkgsrc"
    -B build_pcsx2
    -G Ninja
    -DCMAKE_BUILD_TYPE="Release"
  )

  if [[ "${_build_debug::1}" == "t" ]]; then
    _cmake_pcsx2+=(
      -DENABLE_TESTS=ON
      -DUSE_ASAN=ON
    )
  else
    _cmake_pcsx2+=(
      -DENABLE_TESTS=OFF
      -DUSE_ASAN=OFF
      -Wno-dev
    )
  fi

  if [[ "${_build_avx::1}" == "t" ]]; then
    _cmake_pcsx2+=(-DDISABLE_ADVANCE_SIMD=OFF)
  else
    _cmake_pcsx2+=(-DDISABLE_ADVANCE_SIMD=ON)
  fi

  local _pgo_profile_old="${SRCDEST:-$startdir}/$pkgname.profdata"
  local _pgo_profile="$srcdir/$pkgname.profdata"
  if [[ "${_build_instrumented::1}" == "t" ]]; then
    echo "Compiling with instrumentation."
    CFLAGS+=" -fprofile-generate"
    CXXFLAGS+=" -fprofile-generate"
  elif [[ "${_build_pgo::1}" == "t" ]] && [ -e "$_pgo_profile_old" ]; then
    echo "Compiling with profile-guided optimization."
    cp --reflink=auto "$_pgo_profile_old" "$_pgo_profile"

    CFLAGS+=" -fprofile-use='$_pgo_profile'"
    CXXFLAGS+=" -fprofile-use='$_pgo_profile'"
  else
    echo "Compiling with standard optimization."
  fi

  cmake "${_cmake_pcsx2[@]}"
  cmake --build build_pcsx2
}

# common functions
prepare() {
  _submodule_update() {
    local _module
    for _module in "${_submodules[@]}"; do
      git submodule init "${_module##*::}"
      git submodule set-url "${_module##*::}" "$srcdir/${_module%::*}"
      git -c protocol.file.allow=always submodule update "${_module##*::}"
    done
  }

  _prepare_pcsx2

  _prepare_biojppm_rapidyaml
  _prepare_biojppm_c4core

  # prevent march=native
  sed -E -e 's@^(\s*)(add_compile_options\(.*march=native.*\))@\1message("skip: march=native")@' \
    -i "$_pkgsrc/cmake/BuildParameters.cmake"

  # remove shaderc semantic debug
  sed -e '/vk_khr_shader_non_semantic_info/d' \
    -e '/SetEmitNonSemanticDebugInfo/d' \
    -i "$_pkgsrc/pcsx2/GS/Renderers/Vulkan/VKShaderCache.cpp"
}

pkgver() {
  cd "$_pkgsrc"
  git describe --long --tags --abbrev=7 --exclude='*[a-zA-Z][a-zA-Z]*' \
    | sed -E 's/^[^0-9]*//;s/([^-]*-g)/r\1/;s/-/./g'
}

build() {
  export CC CXX CFLAGS CXXFLAGS LDFLAGS

  if [[ "${_build_clang::1}" == "t" ]]; then
    CC=clang
    CXX=clang++
  fi

  if [[ "${_build_mold::1}" == "t" ]]; then
    LDFLAGS+=" -fuse-ld=mold"
  elif [[ "${_build_clang::1}" == "t" ]]; then
    LDFLAGS+=" -fuse-ld=lld"
  fi

  if [[ "${_build_avx::1}" == "t" ]]; then
    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"
    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

  _build_pcsx2

  cd pcsx2_patches
  7z a -mx=9 -r ../patches.zip patches/.
}

package() {
  install -Dm644 patches.zip -t "$pkgdir/opt/$_pkgname/resources/"
  cp --reflink=auto -r build_pcsx2/bin/* "$pkgdir/opt/$_pkgname/"

  install -Dm644 "$_pkgsrc/bin/resources/icons/AppIconLarge.png" \
    "$pkgdir/usr/share/pixmaps/$_pkgname.png"

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

  install -Dm755 /dev/stdin "$pkgdir/usr/share/applications/pcsx2-qt.desktop" << 'END'
[Desktop Entry]
Type=Application
Name=PCSX2
Comment=Sony PlayStation 2 emulator
Exec=/opt/pcsx2/pcsx2-qt
Icon=pcsx2
Terminal=false
StartupNotify=true
Categories=Game;Emulator;
END

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

# execute
_main_package