build 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. [% c("var/set_default_env") -%]
  3. distdir=/var/tmp/dist/[% project %]
  4. mkdir -p /var/tmp/dist
  5. [% IF c("var/linux") %]
  6. # Config options for hardening-wrapper
  7. export DEB_BUILD_HARDENING=1
  8. export DEB_BUILD_HARDENING_STACKPROTECTOR=1
  9. export DEB_BUILD_HARDENING_FORTIFY=1
  10. export DEB_BUILD_HARDENING_FORMAT=1
  11. export DEB_BUILD_HARDENING_PIE=1
  12. [% END %]
  13. mkdir -p /var/tmp/build
  14. # Building go 1.4.x
  15. # This is needed to bootstrap the go that we actually use
  16. # https://golang.org/doc/install/source#go14
  17. tar -C /var/tmp/build --transform='s,^go\>,go1.4,' -xf $rootdir/[% c('input_files_by_name/go14') %]
  18. cd /var/tmp/build/go1.4/src
  19. patch -p2 < $rootdir/go-aarch64.patch
  20. # Disable cgo to avoid conflicts with newer GCC. cgo is not needed for the bootstrap go.
  21. # https://github.com/golang/go/issues/13114#issuecomment-186922245
  22. # Disable CC etc. that are set up for cross builds.
  23. export GOOS=linux
  24. export GOHOSTARCH=[% c("var/GOARCH14") %]
  25. export GOARCH=[% c("var/GOARCH14") %]
  26. CGO_ENABLED=0 CC= CFLAGS= LDFLAGS= ./make.bash
  27. export GOROOT_BOOTSTRAP="/var/tmp/build/go1.4"
  28. cd $rootdir
  29. [% IF ! c("var/linux") %]
  30. [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
  31. [% END %]
  32. # Building go
  33. # http://golang.org/doc/install/source#environment
  34. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/go') %]
  35. export GOROOT="$distdir"
  36. cd /var/tmp/dist/go/src
  37. [% IF c("var/linux") -%]
  38. export GOOS=linux
  39. export GOHOSTARCH=[% c("var/GOARCH") %]
  40. export GOARCH=[% c("var/GOARCH") %]
  41. ./make.bash
  42. [% ELSIF c("var/osx") -%]
  43. unset LDFLAGS
  44. rm -Rf $clangdir/helpers
  45. export CC="$clangdir/bin/clang [% c("var/FLAGS") %]"
  46. # Create a cc-for-target script that closes over CC, CFLAGS, and LDFLAGS.
  47. # Go's CC_FOR_TARGET only allows a command name, not a command with arguments.
  48. # https://github.com/golang/go/issues/15457
  49. CC_FOR_TARGET="$(pwd)/cc-for-target"
  50. echo "#!/bin/sh" > "$CC_FOR_TARGET"
  51. echo "exec $CC $CFLAGS $LDFLAGS \"\$@\"" >> "$CC_FOR_TARGET"
  52. chmod +x "$CC_FOR_TARGET"
  53. # http://golang.org/doc/install/source#environment
  54. export GOOS=darwin
  55. export GOARCH=amd64
  56. # faketime is needed because clang 3.9.1 on Darwin embeds the timestamps of
  57. # certain intermediate object files (including those that arise here while
  58. # compiling the Go runtime itself). Without this, variable timestamps would
  59. # end up in snowflake-client.
  60. # https://github.com/golang/go/issues/9206#issuecomment-310476743
  61. CGO_ENABLED=1 CC_FOR_TARGET="$CC_FOR_TARGET" CC= CFLAGS= LDFLAGS= [% c("var/faketime") %] ./make.bash
  62. [% ELSIF c("var/windows") -%]
  63. # Create a cc-for-target script that closes over CC, CFLAGS, and LDFLAGS.
  64. # Go's CC_FOR_TARGET only allows a command name, not a command with arguments.
  65. # https://github.com/golang/go/issues/15457
  66. CC_FOR_TARGET="$(pwd)/cc-for-target"
  67. echo "#!/bin/sh" > "$CC_FOR_TARGET"
  68. echo "exec [% c("arch") %]-w64-mingw32-gcc [% c("var/CFLAGS") %] [% c("var/LDFLAGS") %] \"\$@\"" >> "$CC_FOR_TARGET"
  69. chmod +x "$CC_FOR_TARGET"
  70. # http://golang.org/doc/install/source#environment
  71. export GOOS=windows
  72. export GOARCH=[% c("var/GOARCH") %]
  73. CGO_ENABLED=1 CC_FOR_TARGET="$CC_FOR_TARGET" CC= CFLAGS= LDFLAGS= ./make.bash
  74. [% END -%]
  75. cd /var/tmp/dist
  76. [% c('tar', {
  77. tar_src => [ project ],
  78. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  79. }) %]