# Description: an open-source systems monitoring and alerting toolkit
# URL: https://prometheus.io
# Maintainer: Tim Biermann, tbier at posteo dot de
# Depends on: go typescript yamllint yarn

name=prometheus
version=2.46.0
release=1
source=(https://github.com/prometheus/prometheus/archive/v$version/$name-$version.tar.gz
  prometheus.conf prometheus.service)

build() {
  # setup build env {{{
  ## Node Setup
  export NPM_CONFIG_PREFIX="$SRC/npm"
  export PATH+=":$NPM_CONFIG_PREFIX/bin"

  ## Go Setup
  export CGO_LDFLAGS="${LDFLAGS}"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -modcacherw"

  mkdir "$PKGMK_SOURCE_DIR/gopath" || true
  export GOPATH="$PKGMK_SOURCE_DIR/gopath"

  LDFLAGS="-X github.com/prometheus/common/version.Version=$version \
    -X github.com/prometheus/common/version.Revision=CRUX \
    -X github.com/prometheus/common/version.Branch=master \
    -X github.com/prometheus/common/version.BuildUser=$USER@$HOSTNAME \
    -X github.com/prometheus/common/version.BuildDate=$(date -u +%Y%m%d-%H:%M:%S)"
  # }}}
  cd $name-$version

  make build -j1

  install -Dm755 -t $PKG/usr/bin prometheus promtool
  install -Dm640 -g prometheus -t $PKG/etc/prometheus documentation/examples/prometheus.yml
  install -dm750 -o prometheus -g prometheus $PKG/var/lib/prometheus
  install -dm755 $PKG/usr/share/prometheus/web/ui
  cp -R web/ui/static $PKG/usr/share/prometheus/web/ui/

  install -Dm644 $SRC/prometheus.conf $PKG/etc/conf.d/prometheus
  install -Dm 755 $SRC/prometheus.service $PKG/etc/rc.d/prometheus
}

# vim: foldmethod=marker foldlevelstart=1
