# vim: filetype=yaml sw=2
version: 1.12.13
filename: '[% project %]-[% c("version") %]-[% c("var/build_id") %].tar.gz'

var:
  go14_version: 1.4.3
  container:
    use_container: 1

  setup: |
    mkdir -p /var/tmp/dist
    tar -C /var/tmp/dist -xf $rootdir/[% c("go_tarfile") %]
    export GOOS=[% c("var/GOOS") %]
    export GOARCH=[% c("var/GOARCH") %]
    export GOPATH=/var/tmp/dist/gopath
    export PATH=/var/tmp/dist/go/bin:/var/tmp/dist/gopath/bin:"$PATH"
    [% IF c("var/linux") -%]
      export CGO_LDFLAGS_ALLOW="-z|noexecstack"
      export CGO_LDFLAGS="-z noexecstack"
    [% END -%]
    [% IF c("var/linux-i686") -%]
      export CGO_ENABLED=1
    [% END -%]

  # Template build script for building a go library.
  # This can be called as projects/go/var/build_go_lib.
  # You need to define /var/go_lib, and optionally var/go_lib_install as
  # a list of install targets.
  build_go_lib: |
    #!/bin/bash
    [% c("var/set_default_env") -%]
    [% pc('go', 'var/setup', { go_tarfile => c('input_files_by_name/go') }) %]
    distdir=/var/tmp/dist/[% project %]
    mkdir -p /var/tmp/build
    tar -C /var/tmp/build -xf [% project %]-[% c('version') %].tar.gz
    [% FOREACH dep = c("var/go_lib_deps") -%]
      tar -C /var/tmp/dist -xf [% c('input_files_by_name/' _ dep) %]
    [% END -%]
    mkdir -p $(dirname "$GOPATH/src/[% c("var/go_lib") %]")
    mv /var/tmp/build/[% project %]-[% c('version') %] "$GOPATH/src/[% c("var/go_lib") %]"
    cd "$GOPATH/src/[% c("var/go_lib") %]"
    for p in $(ls -1 $rootdir/*.patch 2> /dev/null | sort)
    do
      patch -p1 < $p
    done
    [% IF c("var/build_go_lib_pre"); GET c("var/build_go_lib_pre"); END; -%]
    [% IF c("var/go_lib_install") -%]
      [% FOREACH inst IN c("var/go_lib_install") %]
        go install [% inst %]
      [% END %]
    [% ELSE %]
      go install [% c("var/go_lib") %]
    [% END %]
    cd /var/tmp/dist
    [% c('tar', {
            tar_src => [ 'gopath' ],
            tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
        }) %]

targets:
  windows:
    var:
      GOOS: windows
  windows-i686:
    var:
      GOARCH: 386
  windows-x86_64:
    var:
      GOARCH: amd64
  osx-x86_64:
    var:
      GOOS: darwin
      GOARCH: amd64
      arch_deps:
        - faketime
  linux:
    var:
      GOOS: linux
  linux-x86_64:
    var:
      GOARCH: amd64
  linux-i686:
    var:
      GOARCH: 386

input_files:
  - project: container-image
  - name: '[% c("var/compiler") %]'
    project: '[% c("var/compiler") %]'
    enable: '[% c("var/windows") || c("var/osx") %]'
  - URL: 'https://golang.org/dl/go[% c("version") %].src.tar.gz'
    name: go
    sha256sum: 5383d3b8db4baa48284ffcb14606d9cad6f03e9db843fa6d835b94d63cccf5a7
  - URL: 'https://golang.org/dl/go[% c("var/go14_version") %].src.tar.gz'
    name: go14
    sha256sum: 9947fc705b0b841b5938c48b22dc33e9647ec0752bae66e50278df4f23f64959
