build 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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/[% c("var/distdir") %]
  21. mkdir /var/tmp/build
  22. [% IF c("var/linux-cross") -%]
  23. # Install binutils (needed for cross-compiling)
  24. mkdir /var/tmp/dist
  25. cd /var/tmp/dist
  26. tar xf $rootdir/[% c('input_files_by_name/binutils') %]
  27. mv binutils $distdir
  28. export PATH="$distdir/bin:$PATH"
  29. # Install Linux headers, see Step 2 of
  30. # https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
  31. # Doing this before gcc configure is intended to solve a limits.h issue
  32. cd /var/tmp/build
  33. mkdir linux
  34. cd linux
  35. tar -xJf $rootdir/linux-[% c("var/linux_version") %].tar.xz
  36. cd linux-[% c("var/linux_version") %]
  37. make ARCH=[% c("arch") %] INSTALL_HDR_PATH=$distdir/[% c("var/crosstarget") %] headers_install
  38. cd /var/tmp/build
  39. mkdir gcc
  40. cd gcc
  41. tar -xJf $rootdir/gcc-[% c("version") %].tar.xz
  42. # --with-headers is intended to solve a limits.h issue
  43. gcc-[% c("version") %]/configure --prefix=$distdir --with-headers=$distdir/[% c("var/crosstarget") %]/include/linux [% c("var/configure_opt") %]
  44. # For cross-compiling to work, we need to partially build GCC, then build
  45. # 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. # TODO: Remove --disable-werror once glibc is upgraded to a version that's
  61. # designed to work with the GCC version we're using.
  62. 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
  63. make install-bootstrap-headers=yes install-headers
  64. make -j[% c("buildconf/num_procs") %] csu/subdir_lib
  65. install csu/crt1.o csu/crti.o csu/crtn.o $distdir/[% c("var/crosstarget") %]/lib
  66. [% c("var/crosstarget") %]-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o $distdir/[% c("var/crosstarget") %]/lib/libc.so
  67. # stdio_lim.h is intended to solve a limits.h issue
  68. touch $distdir/[% c("var/crosstarget") %]/include/gnu/stubs.h $distdir/[% c("var/crosstarget") %]/include/bits/stdio_lim.h
  69. # Build compiler support library, see Step 5 of
  70. # https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
  71. # TODO: this part is untested
  72. cd /var/tmp/build/gcc
  73. make -j[% c("buildconf/num_procs") %] all-target-libgcc
  74. make install-target-libgcc
  75. # finish building glibc, see Step 6 of
  76. # https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/
  77. # TODO: this part is untested
  78. cd /var/tmp/build/glibc
  79. make -j[% c("buildconf/num_procs") %]
  80. make install
  81. # We're done with glibc, we can now finish building gcc...
  82. cd /var/tmp/build/gcc
  83. [% ELSE -%]
  84. tar -C /var/tmp/build -xf [% project %]-[% c("version") %].tar.xz
  85. cd /var/tmp/build/[% project %]-[% c("version") %]
  86. ./configure --prefix=$distdir [% c("var/configure_opt") %]
  87. [% END -%]
  88. make -j[% c("buildconf/num_procs") %]
  89. make install
  90. cd /var/tmp/dist
  91. [% c('tar', {
  92. tar_src => [ c('distdir') ],
  93. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  94. }) %]