build 3.11 KB
Newer Older
boklm's avatar
boklm committed
1
#!/bin/bash
2
[% c("var/set_default_env") -%]
3
[% c("var/setarch") -%]
boklm's avatar
boklm committed
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
distdir=/var/tmp/dist/[% project %]
mkdir -p /var/tmp/dist

[% IF c("var/linux") %]
  # Config options for hardening-wrapper
  export DEB_BUILD_HARDENING=1
  export DEB_BUILD_HARDENING_STACKPROTECTOR=1
  export DEB_BUILD_HARDENING_FORTIFY=1
  export DEB_BUILD_HARDENING_FORMAT=1
  export DEB_BUILD_HARDENING_PIE=1
[% END %]

mkdir -p /var/tmp/build

# Building go 1.4.x
# This is needed to bootstrap the go that we actually use
# https://golang.org/doc/install/source#go14
tar -C /var/tmp/build --transform='s,^go\>,go1.4,' -xf $rootdir/[% c('input_files_by_name/go14') %]
cd /var/tmp/build/go1.4/src
# Disable cgo to avoid conflicts with newer GCC. cgo is not needed for the bootstrap go.
# https://github.com/golang/go/issues/13114#issuecomment-186922245
# Disable CC etc. that are set up for cross builds.
CGO_ENABLED=0 CC= CFLAGS= LDFLAGS= ./make.bash
export GOROOT_BOOTSTRAP="/var/tmp/build/go1.4"

cd $rootdir
[% IF ! c("var/linux") %]
  [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
[% END %]

# Building go
# http://golang.org/doc/install/source#environment
tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/go') %]
export GOROOT="$distdir"
cd /var/tmp/dist/go/src
[% IF c("var/linux") -%]
  ./make.bash
[% ELSIF c("var/osx") -%]
42
43
44
  unset LDFLAGS
  rm -Rf $clangdir/helpers
  export CC="$clangdir/bin/clang [% c("var/FLAGS") %]"
boklm's avatar
boklm committed
45
46
47
48
49
  # Create a cc-for-target script that closes over CC, CFLAGS, and LDFLAGS.
  # Go's CC_FOR_TARGET only allows a command name, not a command with arguments.
  # https://github.com/golang/go/issues/15457
  CC_FOR_TARGET="$(pwd)/cc-for-target"
  echo "#!/bin/sh" > "$CC_FOR_TARGET"
50
  echo "exec $CC $CFLAGS $LDFLAGS \"\$@\"" >> "$CC_FOR_TARGET"
boklm's avatar
boklm committed
51
52
53
  chmod +x "$CC_FOR_TARGET"
  # http://golang.org/doc/install/source#environment
  export GOOS=darwin
54
  export GOARCH=amd64
boklm's avatar
boklm committed
55
56
57
58
59
60
  # faketime is needed because clang 3.8.0 on Darwin embeds the timestamps of
  # certain intermediate object files (including those that arise here while
  # compiling the Go runtime itself). Without this, variable timestamps would
  # end up in snowflake-client.
  # https://github.com/golang/go/issues/9206#issuecomment-310476743
  CGO_ENABLED=1 CC_FOR_TARGET="$CC_FOR_TARGET" CC= CFLAGS= LDFLAGS= [% c("var/faketime") %] ./make.bash
boklm's avatar
boklm committed
61
62
63
64
65
66
[% ELSIF c("var/windows") -%]
  # Create a cc-for-target script that closes over CC, CFLAGS, and LDFLAGS.
  # Go's CC_FOR_TARGET only allows a command name, not a command with arguments.
  # https://github.com/golang/go/issues/15457
  CC_FOR_TARGET="$(pwd)/cc-for-target"
  echo "#!/bin/sh" > "$CC_FOR_TARGET"
boklm's avatar
boklm committed
67
  echo "exec [% c("arch") %]-w64-mingw32-gcc [% c("var/CFLAGS") %] [% c("var/LDFLAGS") %] \"\$@\"" >> "$CC_FOR_TARGET"
boklm's avatar
boklm committed
68
69
70
  chmod +x "$CC_FOR_TARGET"
  # http://golang.org/doc/install/source#environment
  export GOOS=windows
boklm's avatar
boklm committed
71
  export GOARCH=[% c("var/GOARCH") %]
boklm's avatar
boklm committed
72
73
74
75
76
77
78
79
  CGO_ENABLED=1 CC_FOR_TARGET="$CC_FOR_TARGET" CC= CFLAGS= LDFLAGS= ./make.bash
[% END -%]

cd /var/tmp/dist
[% c('tar', {
        tar_src => [ project ],
        tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
    }) %]