summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: d653b6932cd5225cb17fd09b3fb8f9b42434190d (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
# Maintainer: AltoXorg <machinademoniko AT gmail DOT com>

# For package compiling issues, comment at the AUR package comments section or PM me on Discord @AltoXorg
# and I will try my best to resolve your problem if possible.

# An N64 Banjo-Kazooie NTSC-U 1.0 ROM must be provided in order to build this package.
# Rename it to following baserom name and place it right to where this PKGBUILD resides.

_reponame=BanjoRecomp
_baserom="baserom.us.rev0.z64"    # <-- Rename your rom file to this
_rom_uncompressed="banjo.us.v10.decompressed.z64"
_bin_name=BanjoRecompiled

_recomp_dir="${_reponame}"
_pkgname=${_reponame,,}
pkgname=${_pkgname}
pkgver=1.0.1
pkgrel=1
arch=("x86_64" "aarch64")
depends=("sdl2" "freetype2" "gtk3" "vulkan-driver" "vulkan-icd-loader" "hicolor-icon-theme")
makedepends=("git" "cmake" "ninja" "make" "clang20" "lld20" "mold" "rust")
pkgdesc="A static recompiled port of N64 Banjo-Kazooie for PC"
license=("GPL-3.0-only")
url="https://github.com/${_reponame}/${_reponame}"
source=("git+${url}.git#tag=v${pkgver}"

        # main dependencies
        "git+https://github.com/N64Recomp/N64ModernRuntime.git"
        "git+https://github.com/rt64/rt64.git"
        "bk-decomp::git+https://gitlab.com/banjo.decomp/banjo-kazooie.git"
        "git+https://github.com/${_reponame}/${_reponame}Syms.git"
        "git+https://github.com/N64Recomp/RecompFrontend.git"

        # RT64 dependencies
        "git+https://github.com/epezent/implot.git"
        "git+https://github.com/redorav/hlslpp.git"
        #"git+https://github.com/mupen64plus/mupen64plus-win32-deps.git"
        #"git+https://github.com/mupen64plus/mupen64plus-core.git"
        "git+https://github.com/Cyan4973/xxHash.git"
        "git+https://github.com/zeux/volk.git"
        "git+https://github.com/KhronosGroup/Vulkan-Headers.git"
        "git+https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git"
        "git+https://github.com/ocornut/imgui.git"
        "git+https://github.com/john-chapman/im3d.git"
        #"git+https://github.com/GPUOpen-LibrariesAndSDKs/D3D12MemoryAllocator.git"
        "dxc::git+https://github.com/rt64/dxc-bin.git"
        "git+https://github.com/nothings/stb.git"
        "git+https://github.com/btzy/nativefiledialog-extended.git"
        "git+https://github.com/redorav/ddspp.git"
        "git+https://github.com/facebook/zstd.git"
        "git+https://github.com/rt64/re-spirv.git"
        "git+https://github.com/renderbag/plume.git"

        # N64ModernRuntime dependencies
        "git+https://github.com/richgel999/miniz.git"
        "git+https://github.com/N64Recomp/o1heap.git"

        # RecompFrontend dependencies
        "git+https://github.com/sammycage/lunasvg.git"
        "git+https://github.com/mikke89/RmlUi.git"
        #"git+https://github.com/ubawurinna/freetype-windows-binaries"

        # re-spirv dependencies
        "git+https://github.com/KhronosGroup/SPIRV-Headers.git"

        # Tools for generating static recomps
        "git+https://github.com/MittenzHugg/bk_rom_compressor.git"
        "git+https://github.com/N64Recomp/N64Recomp.git"

        # N64Recomp dependencies
        "git+https://github.com/Decompollaborate/rabbitizer.git"
        "git+https://github.com/serge1/ELFIO.git"
        "git+https://github.com/fmtlib/fmt.git"
        "git+https://github.com/marzer/tomlplusplus.git"
        "git+https://github.com/zherczeg/sljit.git"

        # bk_rom_compressor dependencies
        "git+https://github.com/MittenzHugg/rarezip.git"

        # Misc. patches and the rom requirement
        "${_pkgname}.desktop"
        "file://${_baserom}")
sha256sums=('93d06738a06c190da7c0b4bfad74908748c7bd8ea3e307614c94bf3b2d73bb2e'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            '231b48ef3b38bb06b4412ec911c13d5938f29b511ea0a814c364182fa112c01b'
            '59875835b9a5128bb0054315a7f929e2071c2001e528d70bf543e1d6680e6eff')

PKG_PREFIX="/opt/${_pkgname}"


# -- Print helpers
_msg_info() {
  echo "${BOLD}>> ${GREEN}$@${ALL_OFF}"
}

_msg_warn() {
  echo "${BOLD}>> ${YELLOW}$@${ALL_OFF}"
}

_is_debug() {
  for opt in "${OPTIONS[@]}"; do
    if [ "$opt" = debug ]; then
      return 0
    fi
  done

  return 1
}

_walk_submodules() {
    absdir="$(pwd | sed "s|^${srcdir}/||")"
    _msg_info "Entering directory <${absdir}>"

    local submodules="$(git ls-tree -r HEAD | awk '$2 == "commit"')"

    if [ -z "$submodules" ]; then
      return
    fi

    local mode type hash dir
    while ifs=" " read -r mode type hash dir; do
        local basedir="$(basename "$dir")"
        local submodule_url="$(git config -f .gitmodules "submodule.${dir}.url")"

        if [ ! -e "${srcdir}/${basedir}" ]; then
            _msg_warn "Local repository ${basedir} (${submodule_url}) is missing. ${dir} is ignored for init!"
            continue
        fi

        _msg_info "Initializing submodule ${dir}"

        # Check if this specific commit exists locally within the repo
        (
            cd "${srcdir}/${basedir}"
            if ! git branch -a --contains "$hash" > /dev/null; then
                _msg_warn "Commit ${hash} of repo ${basedir} didn't get pulled from remote (${submodule_url}). Fetching now..."
                git fetch "$submodule_url" "$hash"
            fi
        )

        # Initialize and update submodule
        git submodule init "${dir}"
        git config "submodule.${dir}.url" "${srcdir}/${basedir}"
        git -c protocol.file.allow=always submodule update "${dir}"

        ( cd "$dir"; _walk_submodules; )
    done <<< "$submodules"

    _msg_info "Leaving directory <${absdir}>"
}


prepare() {
  _msg_info "Setting up the submodules..."

  cd "${srcdir}/${_recomp_dir}"
  _walk_submodules


  #_msg_info "Patching stuff up..."
}

build() {
  export PATH="/usr/lib/llvm20/bin/:${PATH}"

  _msg_info "Building the N64Recomp & RSPRecomp tools..."

  cd "${srcdir}/${_recomp_dir}/lib/N64ModernRuntime/N64Recomp"

  cmake -B build -S . \
    -DCMAKE_BUILD_TYPE=Release . \
    -DCMAKE_MAKE_PROGRAM=ninja \
    -G Ninja
  cmake --build build --config Release --target N64RecompCLI
  cmake --build build --config Release --target RSPRecomp

  cp build/{N64Recomp,RSPRecomp} "${srcdir}/${_recomp_dir}"

  # ------------------------------------------------------------

  _msg_info "Building bk_rom_decompress and decompressing the ROM"

  cd "${srcdir}/${_recomp_dir}/lib/bk-decomp/tools/bk_rom_compressor"

  make -C rarezip CC=clang gzip/librarezip.a
  cargo build --release --all-features --bin bk_rom_decompress
  ./target/release/bk_rom_decompress "${srcdir}/${_baserom}" "${_rom_uncompressed}"
  cp "${_rom_uncompressed}" "${srcdir}/${_recomp_dir}"

  # ------------------------------------------------------------

  cd "${srcdir}/${_recomp_dir}"

  _msg_info "Generating recomp functions..."
  ./RSPRecomp n_aspMain.us.rev0.toml
  ./N64Recomp banjo.us.rev0.toml

  # ------------------------------------------------------------

  _msg_info "Building the game..."

  if _is_debug; then
    BUILD_TYPE=RelWithDebInfo
  else
    BUILD_TYPE=Release
  fi

  export CFLAGS="${CFLAGS/-Werror=format-security/}"
  export CXXFLAGS="${CXXFLAGS/-Werror=format-security/}"
  # Use faster mold linker
  export LDFLAGS="$LDFLAGS -fuse-ld=mold"

  # Use recommended clang compiler
  cmake -B build -S . \
    -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
    -DCMAKE_MAKE_PROGRAM=ninja \
    -G Ninja \
    -DCMAKE_CXX_COMPILER=clang++ \
    -DCMAKE_C_COMPILER=clang \
    -DPATCHES_C_COMPILER=clang \
    -DPATCHES_LD=ld.lld

  cmake --build build $NINJAFLAGS --target "${_bin_name}"
}


package() {
  cd "${srcdir}"

  cat << SHELL > launch.sh
#!/usr/bin/env bash
cd "${PKG_PREFIX}"
exec ./${_bin_name}
SHELL

  install -Dm755 "${_recomp_dir}/build/${_bin_name}" "${pkgdir}/${PKG_PREFIX}/${_bin_name}"

  # Strip the executable whether you like it or not, except for debugging purposes...
  if ! _is_debug; then
    strip --strip-all "${pkgdir}/${PKG_PREFIX}/${_bin_name}"
  fi

  cp -r --preserve=mode "${_recomp_dir}/assets" "${pkgdir}/${PKG_PREFIX}/"
  install -Dm644 "${_recomp_dir}/recompcontrollerdb.txt" "${pkgdir}/${PKG_PREFIX}/"

  install -Dm755 launch.sh "${pkgdir}/usr/bin/${_bin_name}"
  install -Dm644 ${_pkgname}.desktop -t "${pkgdir}/usr/share/applications"
  install -Dm644 "${_recomp_dir}/icons/app.png" "${pkgdir}/usr/share/icons/hicolor/512x512/apps/${_pkgname}.png"

  install -Dm644 "${_recomp_dir}/COPYING" "${pkgdir}/usr/share/licenses/${pkgname}/COPYING"
}