build 3.1 KB

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