genmod.sh.in 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.gold-version -R .note.GNU-stack \
  49. -R .note -R .comment -R .ARM.exidx $tmpfile || exit 1
  50. fi
  51. if ! test -z "${TARGET_OBJ2ELF}"; then
  52. "${TARGET_OBJ2ELF}" $tmpfile || exit 1
  53. fi
  54. else
  55. tmpfile2=${outfile}.tmp2
  56. t1=${outfile}.t1.c
  57. t2=${outfile}.t2.c
  58. # remove old files if any
  59. rm -f $t1 $t2
  60. cp $infile $tmpfile
  61. # Attach .modname and .moddeps sections
  62. echo "char modname[] __attribute__ ((section(\"_modname, _modname\"))) = \"$modname\";" >$t1
  63. for dep in $deps; do echo "char moddep_$dep[] __attribute__ ((section(\"_moddeps, _moddeps\"))) = \"$dep\";" >>$t2; done
  64. if test -n "$deps"; then
  65. @TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib -o $tmpfile2 $t1 $t2 $tmpfile -Wl,-r,-d
  66. else
  67. @TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib -o $tmpfile2 $t1 $tmpfile -Wl,-r,-d
  68. fi
  69. rm -f $t1 $t2 $tmpfile
  70. mv $tmpfile2 $tmpfile
  71. cp $tmpfile $tmpfile.bin
  72. @TARGET_OBJCONV@ -f@TARGET_MODULE_FORMAT@ \
  73. -nr:_grub_mod_init:grub_mod_init \
  74. -nr:_grub_mod_fini:grub_mod_fini \
  75. -wd1106 -nu -nd $tmpfile.bin $tmpfile || exit 1
  76. rm -f $tmpfile.bin
  77. fi
  78. if test x@platform@ != xemu; then
  79. ./build-grub-module-verifier@BUILD_EXEEXT@ $tmpfile @target_cpu@ @platform@
  80. fi
  81. mv $tmpfile $outfile