build 4.3 KB

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