summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 8c659af67011cadb140c9ae7861f44c73ef5d6f1 (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
# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=xq
pkgver=1.1.1
pkgrel=1
pkgdesc='Command-line XML and HTML beautifier and content extractor'
arch=('x86_64')
url='https://github.com/sibprogrammer/xq'
license=('MIT')
depends=('glibc')
makedepends=('git' 'go')
conflicts=('yq')
options=('!lto')
_commit='f0c2fb2fb0dcc90e9422a219ffdf437113777388'
source=(
  "$pkgname::git+$url#commit=$_commit"
  'manpage-template.patch'
)
b2sums=('SKIP'
        'f2448e22798e018d6962016dc800ff96ae9c23b776742348a7036d613efa8c37e5c8c7a539804f2daebc4c152495cc1cbbcb2635fcf223e958596333cab1b843')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # create directory for build output
  mkdir build

  # download dependencies
  go mod download

  # turn man page into a template
  patch -p1 -i "$srcdir/manpage-template.patch"
}

build() {
  cd "$pkgname"

  # set Go flags
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"

  # commit date for binary & man page
  local _commit_date=$(git show --no-patch --format=%cd --date=format:%Y-%m-%d)

  go build -v \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -ldflags "-linkmode external -extldflags ${LDFLAGS} \
    -X main.commit=$_commit \
    -X main.date=$_commit_date \
    -X main.version=$pkgver" \
    -o build \
    .

  # template-ify man page
  sed \
    -e "s/@DATE@/$_commit_date/" \
    -e "s/@VERSION@/$pkgver/" \
    -i docs/xq.man
}

check() {
  cd "$pkgname"

  go test -v ./...
}

package() {
  cd "$pkgname"

  # binary
  install -vDm755 -t "$pkgdir/usr/bin" build/xq

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md
  cp -vr assets "$pkgdir/usr/share/doc/$pkgname"

  # man
  install -vDm644 docs/xq.man "$pkgdir/usr/share/man/man1/$pkgname.1"

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}