build 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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") || c("var/linux-cross") %]
  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. [% IF c("var/linux-cross") -%]
  36. # Create a cc-for-target script that closes over CC, CFLAGS, and LDFLAGS.
  37. # Go's CC_FOR_TARGET only allows a command name, not a command with arguments.
  38. # https://github.com/golang/go/issues/15457
  39. CC_FOR_TARGET="$(pwd)/cc-for-target"
  40. echo "#!/bin/sh" > "$CC_FOR_TARGET"
  41. echo "exec [% c("var/crosstarget") %]-gcc [% c("var/CFLAGS") %] [% c("var/LDFLAGS") %] \"\$@\"" >> "$CC_FOR_TARGET"
  42. chmod +x "$CC_FOR_TARGET"
  43. # http://golang.org/doc/install/source#environment
  44. export GOOS=[% c("GOOS") %]
  45. export GOARCH=[% c("var/GOARCH") %]
  46. CGO_ENABLED=1 CC_FOR_TARGET="$CC_FOR_TARGET" CC= CFLAGS= LDFLAGS= ./make.bash
  47. [% ELSE -%]
  48. ./make.bash
  49. [% END -%]
  50. [% ELSIF c("var/osx") -%]
  51. unset LDFLAGS
  52. rm -Rf $clangdir/helpers
  53. export CC="$clangdir/bin/clang [% c("var/FLAGS") %]"
  54. # Create a cc-for-target script that closes over CC, CFLAGS, and LDFLAGS.
  55. # Go's CC_FOR_TARGET only allows a command name, not a command with arguments.
  56. # https://github.com/golang/go/issues/15457
  57. CC_FOR_TARGET="$(pwd)/cc-for-target"
  58. echo "#!/bin/sh" > "$CC_FOR_TARGET"
  59. echo "exec $CC $CFLAGS $LDFLAGS \"\$@\"" >> "$CC_FOR_TARGET"
  60. chmod +x "$CC_FOR_TARGET"
  61. # http://golang.org/doc/install/source#environment
  62. export GOOS=darwin
  63. export GOARCH=amd64
  64. # faketime is needed because clang 3.9.1 on Darwin embeds the timestamps of
  65. # certain intermediate object files (including those that arise here while
  66. # compiling the Go runtime itself). Without this, variable timestamps would
  67. # end up in snowflake-client.
  68. # https://github.com/golang/go/issues/9206#issuecomment-310476743
  69. CGO_ENABLED=1 CC_FOR_TARGET="$CC_FOR_TARGET" CC= CFLAGS= LDFLAGS= [% c("var/faketime") %] ./make.bash
  70. [% ELSIF c("var/windows") -%]
  71. # Create a cc-for-target script that closes over CC, CFLAGS, and LDFLAGS.
  72. # Go's CC_FOR_TARGET only allows a command name, not a command with arguments.
  73. # https://github.com/golang/go/issues/15457
  74. CC_FOR_TARGET="$(pwd)/cc-for-target"
  75. echo "#!/bin/sh" > "$CC_FOR_TARGET"
  76. echo "exec [% c("arch") %]-w64-mingw32-gcc [% c("var/CFLAGS") %] [% c("var/LDFLAGS") %] \"\$@\"" >> "$CC_FOR_TARGET"
  77. chmod +x "$CC_FOR_TARGET"
  78. # http://golang.org/doc/install/source#environment
  79. export GOOS=windows
  80. export GOARCH=[% c("var/GOARCH") %]
  81. CGO_ENABLED=1 CC_FOR_TARGET="$CC_FOR_TARGET" CC= CFLAGS= LDFLAGS= ./make.bash
  82. [% END -%]
  83. cd /var/tmp/dist
  84. [% c('tar', {
  85. tar_src => [ project ],
  86. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  87. }) %]