genmod.sh.in 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #! @BUILD_SHEBANG@
  2. set -e
  3. # Copyright (C) 2010 Free Software Foundation, Inc.
  4. #
  5. # This gensymlist.sh is free software; the author
  6. # gives unlimited permission to copy and/or distribute it,
  7. # with or without modifications, as long as this notice is preserved.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
  11. # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  12. # PARTICULAR PURPOSE.
  13. #
  14. # Example:
  15. #
  16. # genmod.sh moddep.lst normal.module build-grub-module-verifier normal.mod
  17. #
  18. moddep=$1
  19. infile=$2
  20. outfile=$4
  21. tmpfile=${outfile}.tmp
  22. modname=`echo $infile | sed -e 's@\.module.*$@@'`
  23. if ! grep ^$modname: $moddep >/dev/null; then
  24. echo "warning: moddep.lst has no dependencies for $modname" >&2
  25. exit 0
  26. fi
  27. deps=`grep ^$modname: $moddep | sed s@^.*:@@`
  28. # remove old files if any
  29. rm -f $tmpfile $outfile
  30. if test x@TARGET_APPLE_LINKER@ != x1; then
  31. # stripout .modname and .moddeps sections from input module
  32. @TARGET_OBJCOPY@ -R .modname -R .moddeps $infile $tmpfile
  33. # Attach .modname and .moddeps sections
  34. t1=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
  35. printf "$modname\0" >$t1
  36. t2=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
  37. for dep in $deps; do printf "$dep\0" >> $t2; done
  38. if test -n "$deps"; then
  39. @TARGET_OBJCOPY@ --add-section .modname=$t1 --add-section .moddeps=$t2 $tmpfile
  40. else
  41. @TARGET_OBJCOPY@ --add-section .modname=$t1 $tmpfile
  42. fi
  43. rm -f $t1 $t2
  44. if test x@platform@ != xemu; then
  45. @TARGET_STRIP@ --strip-unneeded \
  46. -K grub_mod_init -K grub_mod_fini \
  47. -K _grub_mod_init -K _grub_mod_fini \
  48. -R .note.GNU-stack \
  49. -R .note.gnu.gold-version \
  50. -R .note.gnu.property \
  51. -R .gnu.build.attributes \
  52. -R '.llvm*' \
  53. -R .rel.gnu.build.attributes \
  54. -R .rela.gnu.build.attributes \
  55. -R .eh_frame -R .rela.eh_frame -R .rel.eh_frame \
  56. -R .note -R .comment -R .ARM.exidx $tmpfile || exit 1
  57. fi
  58. if ! test -z "${TARGET_OBJ2ELF}"; then
  59. "${TARGET_OBJ2ELF}" $tmpfile || exit 1
  60. fi
  61. else
  62. tmpfile2=${outfile}.tmp2
  63. t1=${outfile}.t1.c
  64. t2=${outfile}.t2.c
  65. # remove old files if any
  66. rm -f $t1 $t2
  67. cp $infile $tmpfile
  68. # Attach .modname and .moddeps sections
  69. echo "char modname[] __attribute__ ((section(\"_modname, _modname\"))) = \"$modname\";" >$t1
  70. for dep in $deps; do echo "char moddep_$dep[] __attribute__ ((section(\"_moddeps, _moddeps\"))) = \"$dep\";" >>$t2; done
  71. if test -n "$deps"; then
  72. @TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib -o $tmpfile2 $t1 $t2 $tmpfile -Wl,-r
  73. else
  74. @TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib -o $tmpfile2 $t1 $tmpfile -Wl,-r
  75. fi
  76. rm -f $t1 $t2 $tmpfile
  77. mv $tmpfile2 $tmpfile
  78. cp $tmpfile $tmpfile.bin
  79. @TARGET_OBJCONV@ -f@TARGET_MODULE_FORMAT@ \
  80. -nr:_grub_mod_init:grub_mod_init \
  81. -nr:_grub_mod_fini:grub_mod_fini \
  82. -wd1106 -nu -nd $tmpfile.bin $tmpfile || exit 1
  83. rm -f $tmpfile.bin
  84. fi
  85. if test x@platform@ != xemu; then
  86. ./build-grub-module-verifier@BUILD_EXEEXT@ $tmpfile @target_cpu@ @platform@
  87. fi
  88. mv $tmpfile $outfile