build 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/sh
  2. [% c("var/set_default_env") -%]
  3. [% c("var/setarch") -%]
  4. [% IF c("var/linux") -%]
  5. # Config options for hardening-wrapper
  6. export DEB_BUILD_HARDENING=1
  7. export DEB_BUILD_HARDENING_STACKPROTECTOR=1
  8. export DEB_BUILD_HARDENING_FORTIFY=1
  9. # Since r223796 landed on GCC master enforcing PIE breaks GCC compilation.
  10. # The compiler gets built with `-fno-PIE` and linked with `-no-pie` as not
  11. # doing so would make precompiled headers (PCH) fail.
  12. # It is okay for us to omit this right now as it does not change any hardening
  13. # flags in the resulting bundles.
  14. export DEB_BUILD_HARDENING_PIE=0
  15. # We need to disable `-Werror=format-security` as GCC does not build with it
  16. # anymore. It seems it got audited for those problems already:
  17. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48817.
  18. export DEB_BUILD_HARDENING_FORMAT=0
  19. [% END -%]
  20. distdir=/var/tmp/dist/[% project %]
  21. mkdir /var/tmp/build
  22. # Install binutils when cross-compiling
  23. mkdir /var/tmp/dist
  24. cd /var/tmp/dist
  25. tar xf $rootdir/[% c('input_files_by_name/binutils') %]
  26. mv binutils $distdir
  27. export PATH="$distdir/bin:$PATH"
  28. # Install Linux headers, see Step 2 of
  29. # https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
  30. # Doing this before gcc configure is intended to solve a limits.h issue
  31. cd /var/tmp/build
  32. mkdir linux
  33. cd linux
  34. tar -xJf $rootdir/linux-[% c("var/linux_version") %].tar.xz
  35. cd linux-[% c("var/linux_version") %]
  36. make ARCH=[% c("arch") %] INSTALL_HDR_PATH=$distdir/[% c("var/crosstarget") %] headers_install
  37. #cd $rootdir
  38. cd /var/tmp/build
  39. mkdir gcc
  40. cd gcc
  41. tar -xJf $rootdir/gcc-[% c("version") %].tar.xz
  42. #cd /var/tmp/build/[% project %]-[% c("version") %]
  43. # --with-headers is intended to solve a limits.h issue
  44. gcc-[% c("version") %]/configure --prefix=$distdir --with-headers=$distdir/[% c("var/crosstarget") %]/include/linux [% c("var/configure_opt") %]
  45. # When cross-compiling, we need to partially build GCC, then build glibc, then come back to finish GCC.
  46. # Build only the components of GCC that don't need glibc, see Step 3 of
  47. # https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
  48. cd /var/tmp/build/gcc
  49. make -j[% c("buildconf/num_procs") %] all-gcc
  50. make install-gcc
  51. # Removing sys-include is intended to solve a limits.h issue
  52. rm --recursive --force $distdir/[% c("var/crosstarget") %]/sys-include
  53. # Build glibc headers and startup files, see Step 4 of
  54. # https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
  55. # TODO: this part is untested
  56. cd /var/tmp/build
  57. mkdir glibc
  58. cd glibc
  59. tar -xJf $rootdir/glibc-[% c("var/glibc_version") %].tar.xz
  60. glibc-[% c("var/glibc_version") %]/configure --prefix=$distdir/[% c("var/crosstarget") %] --build=$MACHTYPE --host=[% c("var/crosstarget") %] --target=[% c("var/crosstarget") %] --with-headers=$distdir/[% c("var/crosstarget") %]/include --disable-multilib libc_cv_forced_unwind=yes
  61. make install-bootstrap-headers=yes install-headers
  62. make -j[% c("buildconf/num_procs") %] csu/subdir_lib
  63. install csu/crt1.o csu/crti.o csu/crtn.o $distdir/[% c("var/crosstarget") %]/lib
  64. [% c("var/crosstarget") %]-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $distdir/[% c("var/crosstarget") %]/lib/libc.so
  65. # stdio_lim.h is intended to solve a limits.h issue
  66. touch $distdir/[% c("var/crosstarget") %]/include/gnu/stubs.h $distdir/[% c("var/crosstarget") %]/include/bits/stdio_lim.h
  67. # Build compiler support library, see Step 5 of
  68. # https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
  69. # TODO: this part is untested
  70. cd /var/tmp/build/gcc
  71. make -j[% c("buildconf/num_procs") %] all-target-libgcc
  72. make install-target-libgcc
  73. # finish building glibc, see Step 6 of
  74. # https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
  75. # TODO: this part is untested
  76. cd /var/tmp/build/glibc
  77. make -j[% c("buildconf/num_procs") %]
  78. make install
  79. # We're done with glibc, we can now finish building gcc...
  80. cd /var/tmp/build/gcc
  81. make -j[% c("buildconf/num_procs") %]
  82. make install
  83. cd /var/tmp/dist
  84. [% c('tar', {
  85. tar_src => [ project ],
  86. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  87. }) %]