summaryrefslogtreecommitdiff
path: root/pcr/qemu-user-static-riscv-git/PKGBUILD
blob: 89b83a008d5c454de2cbceaa40885c468626eee5 (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
# Maintainer (Arch:qemu): Tobias Powalowski <tpowa@archlinux.org>
# Contributor (Arch:qemu): Sébastien "Seblu" Luttringer <seblu@seblu.net>
# Maintainer: Luke Shumaker <lukeshu@parabola.nu>
# Contributor: Márcio Silva <coadde@hyperbola.info>

# parabola changes and rationale:
#  - apdapted from ribre/qemu-user-static
#  - changed to build riscv/riscv-qemu on github
#  - checking out submodules in prepare

_pkgbase=qemu
_gitname=riscv-qemu
pkgname=(qemu-user-static-riscv-git qemu-user-static-binfmt-riscv-git)
pkgdesc="A generic and open source machine emulator and virtualizer. Git version with riscv support."
pkgver=2.11.50.r59354.b6e0a38a92
pkgrel=1
arch=(x86_64)
license=(GPL2 LGPL2.1)
url="https://github.com/riscv/riscv-qemu"
makedepends=(git pixman-static glib2-static pcre-static python2)
source=("git+https://github.com/riscv/riscv-qemu.git#tag=riscv-qemu-upstream-v8"
        0001-linux-user-Use-if-to-only-call-validate_guest_space-.patch
        0002-linux-user-Rename-validate_guest_space-init_guest_co.patch
        0003-linux-user-init_guest_space-Clean-up-if-we-can-t-ini.patch
        0004-linux-user-init_guest_space-Correctly-handle-guest_s.patch
        0005-linux-user-init_guest_space-Clarify-page-alignment-l.patch
        0006-linux-user-init_guest_commpage-Add-a-comment-about-s.patch
        0007-linux-user-init_guest_space-Clean-up-control-flow-a-.patch
        0008-linux-user-init_guest_space-Don-t-try-to-align-if-we.patch
        0009-linux-user-init_guest_space-Add-a-comment-about-sear.patch
        0010-linux-user-init_guest_space-Try-to-make-ARM-space-co.patch
        allow_elf64.patch)
sha256sums=('SKIP'
            '9953a8debd9456adb4f5968817fa89da4d4542e44980a5533ccf86371d819845'
            'a977e9295daa14a9c73258cf16399eb5af66382217f8a4e69951ec044131a7ce'
            'dba2cfeb24841d45936091319957ee6f65e481da3c761791d410d3b8e6799998'
            '75b3bda6752c4bf17488489f898767b6772b10ecc5d1f0a5bc1bd831e99a31e3'
            '731895a8ed6f6d322bb60764b01cf09e0ea762d7d53fc01e91c2d2aecfdc8844'
            '69b37040f52ef86b86c7c2952eb3f85f3c67d7adf289c43fdac8c71827c6e5b9'
            '76f88850b0f52450eecb80029ffe16db6f418cec3b58231aca354cc20bbfb16a'
            '76944d84990cc76e47c381849c683a346c5234bcebbe4c24334d0fd8368482db'
            '7845867348fd380def28c7fe023e54cee8ff88cd6754aae3ab3472149cfbde51'
            '1953e7cac58c23526d007d8559410e0042d4a7c1b8cbd5f4c0543f7f876436dd'
            '13a6d9e678bdc9e1f051006cfd0555f5a80582368f54c8a1bb5a78ece3832ac4')
validpgpkeys=('CEACC9E15534EBABB82D3FA03353C9CEF108B584')

case $CARCH in
  i?86) _corearch=i386 ;;
  x86_64) _corearch=x86_64 ;;
esac

pkgver() {
  cd "${srcdir}/${_gitname}"

  printf "%s.r%s.%s" "$(cat VERSION)" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  mkdir build-static
  mkdir -p extra-arch-static/usr/{bin,share/qemu}

  cd "${srcdir}/${_gitname}"
  sed -i 's/vte-2\.90/vte-2.91/g' configure

  # https://bugs.launchpad.net/qemu/+bug/1740219
  # https://lists.nongnu.org/archive/html/qemu-devel/2017-12/msg05237.html
  local patchfile
  for patchfile in ../????-linux-user-*.patch; do
    patch -p1 < "$patchfile"
  done

  patch -p1 < ../allow_elf64.patch

  # update git submodules
  scripts/git-submodule.sh update ui/keycodemapdb dtc
}

build() {
  local flags=(
    --static
    --disable-system # disable building qemu-system-$CPU, we only want qemu-$CPU
    --disable-guest-agent # disable building qemu-ga
    --disable-tools # disable building the qemu-{io,nbd,img} tools
    --disable-blobs # disable installing firmware files used by system
    --disable-docs
    --disable-modules # modules imply dynamic linking

    # jemalloc-static isn't packaged
    --disable-jemalloc

    # These libraries are only used for system or tools, but even
    # though that's disabled, libqemuutil.a still tries to link
    # against them unless we specifically tell it not to (the linkage
    # would be removed at the final linker's tree-shaking).
    --disable-gcrypt
    --disable-nettle
  )
  _build static "${flags[@]}" \
    --audio-drv-list= \
    --disable-bluez \
    --disable-sdl \
    --disable-gtk \
    --disable-vte \
    --disable-opengl \
    --disable-virglrenderer
}

_build() (
  cd build-$1

  # qemu vs. make 4 == bad
  export ARFLAGS=rv

  # http://permalink.gmane.org/gmane.comp.emulators.qemu/238740
  export CFLAGS+=" -fPIC"

  ../${_gitname}/configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --libexecdir=/usr/lib/qemu \
    --python=/usr/bin/python2 \
    --smbd=/usr/bin/smbd \
    --with-gtkabi=3.0 \
    --with-sdlabi=2.0 \
    --enable-modules \
    --enable-jemalloc \
    --disable-git-update \
    "${@:2}"

  make
)

package_qemu-user-static-riscv-git() {
  pkgdesc="QEMU user-mode emulation (static binaries) - Git version with riscv support."

  provides=("qemu-static=$pkgver")
  conflicts=(qemu-static qemu-user-static)

  _package static

  rm -vr -- \
     "$pkgdir"/usr/lib/ \
     "$pkgdir"/usr/share/

  local prog
  for prog in "$pkgdir"/usr/bin/*; do
    mv -nT -- "$prog" "${prog%-static}-static"
  done
}

_package() {
  options=(!strip)

  make -C build-$1 DESTDIR="$pkgdir" install "${@:2}"

  cd "$pkgdir"/usr/bin
  tidy_strip
}

package_qemu-user-static-binfmt-riscv-git() {
  pkgdesc="binfmt registration for QEMU user-mode emulation - Git version with riscv support."
  depends=("qemu-user-static-riscv-git=$pkgver")

  provides=("binfmt-qemu-static=$pkgver")
  conflicts=('binfmt-qemu-static' 'qemu-user-static-binfmt')

  cd ${_gitname}

  install -d "$pkgdir"/usr/lib/binfmt.d

  < scripts/qemu-binfmt-conf.sh \
    sed -e 's/^CHECK=.*/CHECK=qemu_check_systemd/' \
        -e 's/^BINFMT_SET=.*/BINFMT_SET=qemu_generate_systemd/' \
  | sh /dev/stdin \
       --qemu-path /usr/bin \
       --exportdir "$pkgdir"/usr/lib/binfmt.d \
       --credential yes

  # add the "-static" suffix
  sed -i 's/:[^:]*$/-static&/' --  "$pkgdir"/usr/lib/binfmt.d/*.conf
}