build 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. # http://golang.org/doc/install/source#environment
  32. export GOOS=[% c("var/GOOS") %]
  33. export GOARCH=[% c("var/GOARCH") %]
  34. [% END %]
  35. # Building go
  36. # http://golang.org/doc/install/source#environment
  37. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/go') %]
  38. export GOROOT="$distdir"
  39. cd /var/tmp/dist/go/src
  40. [% IF c("var/linux") -%]
  41. export GOOS=[% c("var/GOOS") %]
  42. export GOARCH=[% c("var/GOARCH") %]
  43. export GOHOSTARCH=[% c("var/GOARCH") %]
  44. ./make.bash
  45. [% ELSIF c("var/macos") -%]
  46. unset LDFLAGS
  47. rm -Rf $clangdir/helpers
  48. export CC="$clangdir/bin/clang [% c("var/FLAGS") %]"
  49. # Create a cc-for-target script that closes over CC, CFLAGS, and LDFLAGS.
  50. # Go's CC_FOR_TARGET only allows a command name, not a command with arguments.
  51. # https://github.com/golang/go/issues/15457
  52. CC_FOR_TARGET="$(pwd)/cc-for-target"
  53. echo "#!/bin/sh" > "$CC_FOR_TARGET"
  54. echo "exec $CC $CFLAGS $LDFLAGS \"\$@\"" >> "$CC_FOR_TARGET"
  55. chmod +x "$CC_FOR_TARGET"
  56. CGO_ENABLED=1 CC_FOR_TARGET="$CC_FOR_TARGET" CC= CFLAGS= LDFLAGS= ./make.bash
  57. [% ELSIF c("var/windows") -%]
  58. # Create a cc-for-target script that closes over CC, CFLAGS, and LDFLAGS.
  59. # Go's CC_FOR_TARGET only allows a command name, not a command with arguments.
  60. # https://github.com/golang/go/issues/15457
  61. CC_FOR_TARGET="$(pwd)/cc-for-target"
  62. echo "#!/bin/sh" > "$CC_FOR_TARGET"
  63. echo "exec [% c("arch") %]-w64-mingw32-cc [% c("var/CFLAGS") %] [% c("var/LDFLAGS") %] \"\$@\"" >> "$CC_FOR_TARGET"
  64. chmod +x "$CC_FOR_TARGET"
  65. CGO_ENABLED=1 CC_FOR_TARGET="$CC_FOR_TARGET" CC= CFLAGS= LDFLAGS= ./make.bash
  66. [% ELSIF c("var/android") -%]
  67. patch -p2 < $rootdir/0001-Use-fixed-go-build-tmp-directory.patch
  68. CGO_ENABLED=1 CC_FOR_TARGET=[% c("var/CC") %] CC= CFLAGS= LDFLAGS= ./make.bash
  69. [% END -%]
  70. # This directory is non-reproducible and doesn't exist in official Go releases,
  71. # so remove it to preserve reproducibility of the output.
  72. rm -rf /var/tmp/dist/go/pkg/obj/go-build/
  73. cd /var/tmp/dist
  74. [% c('tar', {
  75. tar_src => [ project ],
  76. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  77. }) %]