summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: b9e87b05015897ac92c0a11706b4601bf4ac349f (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
# Maintainer: Sven Greb <development@svengreb.de>
# Contributor: Arctic Ice Studio <development@arcticicestudio.com>
#
# This package is built according to the AUR Go packaging guidelines:
# https://wiki.archlinux.org/index.php/Go_package_guidelines
pkgname=mage
pkgver=1.11.0
pkgrel=1
pkgdesc="A Make/rake-like build tool using Go"
arch=("x86_64")
url="https://magefile.org"
license=("Apache")
makedepends=("git" "go-pie")
source=("git+https://github.com/magefile/${pkgname}.git")
sha256sums=("SKIP")

build() {
  cd "$pkgname"

  # We're building from source to get metadata information for the binary, but using a stable version tag instead of
  # the latest commit since this is not a `-git` package.
  git checkout "v$pkgver"

  # mage is build with mage itself, therefore we simluate the execution of the provided `bootstrap.go` installation
  # file that is recommended by the author.
  # The file builds mage when mage itself is not installed on the target system yet and included metadata information
  # for the binary.
  #
  # References:
  #   1. https://github.com/magefile/mage/blob/bf7f17a5/bootstrap.go
  #   1. https://github.com/magefile/mage/blob/07afc7d2/magefile.go#L65
  #   2. https://github.com/magefile/mage/blob/07afc7d2/magefile.go#L103
  #   3. https://github.com/magefile/mage/blob/5bc3a8ab/.goreleaser.yml#L28
  local build_date git_commit_hash git_tag
  build_date=$(command date --rfc-3339=seconds)
  git_commit_hash=$(git rev-parse --short HEAD)
  git_tag=$(git describe --tags)
  if [ -z "$git_tag" ]; then
    git_tag="dev"
  fi

  export CGO_ENABLED=0
  go build \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -ldflags "-X \"github.com/magefile/mage/mage.timestamp=$build_date\" \
              -X \"github.com/magefile/mage/mage.commitHash=$git_commit_hash\" \
              -X \"github.com/magefile/mage/mage.gitTag=$git_tag\" \
              -extldflags \"${LDFLAGS}\"" \
    -o build/"$pkgname" .
}

package() {
  cd "$pkgname" || exit 1
  install -Dm755 build/"$pkgname" "$pkgdir"/usr/bin/"$pkgname"
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}