summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 8a077b046720589056763cd860975352066c1fbb (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
# Maintainer:
# Contributor: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>

## links
# https://desmume.org
# https://github.com/TASVideos/desmume

## options
: ${_build_level:=1}
: ${_build_git:=true}

unset _pkgtype
[[ "${_build_level::1}" == "2" ]] && _pkgtype+="-x64v2"
[[ "${_build_level::1}" == "3" ]] && _pkgtype+="-x64v3"
[[ "${_build_level::1}" == "4" ]] && _pkgtype+="-x64v4"
[[ "${_build_git::1}" == "t" ]] && _pkgtype+="-git"

_pkgname="desmume"
pkgname="$_pkgname${_pkgtype:-}"
pkgver=0.9.14.r271.g60714f6
pkgrel=2
pkgdesc="Nintendo DS emulator"
url="https://github.com/TASVideos/desmume"
license=('GPL-2.0-or-later')
arch=('aarch64' 'x86_64' 'x86_64_v2' 'x86_64_v3' 'x86_64_v4')

depends=(
  'gtk3'
  'libopenal.so'
  'libpcap'
  'sdl2'
  'soundtouch'
  'zlib'
)
makedepends=(
  'clang'
  'git'
  'intltool'
  'lld'
  'mesa'
  'meson'
)

case "$CARCH" in
  x86_64_v2)
    _build_level=2
    ;;
  x86_64_v3)
    _build_level=3
    ;;
  x86_64_v4)
    _build_level=4
    ;;
  *) # no changes; may be user defined
    ;;
esac

if [ "${_build_git::1}" == "t" ]; then
  provides=("$_pkgname")
  conflicts=("$_pkgname")
  _commit="master"

  pkgver() {
    cd "$_pkgsrc"
    local _file _hash _ver _rev
    _file="desmume/src/version.cpp"
    read -r _hash _ver < <(
      NL=$(awk '/^#define DESMUME_VERSION_STRING /{n=NR}END{print n}' "$_file")

      git blame -L "$NL,+1" -- "$_file" \
        | awk '{print $1" "$(NF-5) }' \
        | sed -E -e 's&"&&g'
    )
    _rev=$(git rev-list --count --cherry-pick "$_hash"...HEAD)

    printf "%s.r%s.g%s" "${_ver:?}" "${_rev:?}" "${_hash::7}"
  }
fi

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

build() {
  export CC CXX CFLAGS CXXFLAGS LDFLAGS
  CC=clang
  CXX=clang++

  local _ldflags=(${LDFLAGS})
  LDFLAGS="${_ldflags[@]//*fuse-ld*/} -fuse-ld=lld"

  if [[ ${_build_level::1} =~ ^[2-4]$ ]]; then
    local _cflags _cxxflags
    _cflags=(
      -march=x86-64-v${_build_level::1} -mtune=generic -O3
      $(sed -E -e 's&-(march|mtune)=\S+\b&&g' -e 's&-O[0-9]+\b&&g' <<< "${CFLAGS}")
    )
    CFLAGS="${_cflags[@]}"

    _cxxflags=(
      -march=x86-64-v${_build_level::1} -mtune=generic -O3
      $(sed -E -e 's&-(march|mtune)=\S+\b&&g' -e 's&-O[0-9]+\b&&g' <<< "${CXXFLAGS}")
    )
    CXXFLAGS="${_cxxflags[@]}"
  fi

  local _pkgsrc="$_pkgsrc/desmume/src/frontend/posix"

  local _meson_args=(
    -Dopengl=true
    -Dglx=true
    -Dopenal=true
    -Dwifi=true
  )

  arch-meson "${_meson_args[@]}" "$_pkgsrc" build
  meson compile -C build
}

package() {
  meson install -C build --destdir "$pkgdir"
}