4 # Copyright (C) 2010 Free Software Foundation, Inc.
6 # This gensymlist.sh is free software; the author
7 # gives unlimited permission to copy and/or distribute it,
8 # with or without modifications, as long as this notice is preserved.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
12 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18 # genmod.sh moddep.lst normal.module build-grub-module-verifier normal.mod
25 tmpfile=${outfile}.tmp
26 modname=`echo $infile | sed -e 's@\.module.*$@@'`
28 if ! grep ^$modname: $moddep >/dev/null; then
29 echo "warning: moddep.lst has no dependencies for $modname" >&2
33 deps=`grep ^$modname: $moddep | sed s@^.*:@@`
35 # remove old files if any
36 rm -f $tmpfile $outfile
38 if test x@TARGET_APPLE_LINKER@ != x1; then
39 # stripout .modname and .moddeps sections from input module
40 @TARGET_OBJCOPY@ -R .modname -R .moddeps $infile $tmpfile
42 # Attach .modname and .moddeps sections
43 t1=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
44 printf "$modname\0" >$t1
46 t2=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
47 for dep in $deps; do printf "$dep\0" >> $t2; done
49 if test -n "$deps"; then
50 @TARGET_OBJCOPY@ --add-section .modname=$t1 --add-section .moddeps=$t2 $tmpfile
52 @TARGET_OBJCOPY@ --add-section .modname=$t1 $tmpfile
56 if test x@platform@ != xemu; then
57 @TARGET_STRIP@ --strip-unneeded \
58 -K grub_mod_init -K grub_mod_fini \
59 -K _grub_mod_init -K _grub_mod_fini \
60 -R .note.gnu.gold-version -R .note.GNU-stack \
61 -R .gnu.build.attributes \
62 -R .rel.gnu.build.attributes \
63 -R .rela.gnu.build.attributes \
64 -R .eh_frame -R .rela.eh_frame -R .rel.eh_frame \
65 -R .note -R .comment -R .ARM.exidx $tmpfile || exit 1
67 if ! test -z "${TARGET_OBJ2ELF}"; then
68 "${TARGET_OBJ2ELF}" $tmpfile || exit 1
71 tmpfile2=${outfile}.tmp2
75 # remove old files if any
80 # Attach .modname and .moddeps sections
81 echo "char modname[] __attribute__ ((section(\"_modname, _modname\"))) = \"$modname\";" >$t1
83 for dep in $deps; do echo "char moddep_$dep[] __attribute__ ((section(\"_moddeps, _moddeps\"))) = \"$dep\";" >>$t2; done
85 if test -n "$deps"; then
86 @TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib -o $tmpfile2 $t1 $t2 $tmpfile -Wl,-r,-d
88 @TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib -o $tmpfile2 $t1 $tmpfile -Wl,-r,-d
90 rm -f $t1 $t2 $tmpfile
93 cp $tmpfile $tmpfile.bin
94 @TARGET_OBJCONV@ -f@TARGET_MODULE_FORMAT@ \
95 -nr:_grub_mod_init:grub_mod_init \
96 -nr:_grub_mod_fini:grub_mod_fini \
97 -wd1106 -nu -nd $tmpfile.bin $tmpfile || exit 1
100 if test x@platform@ != xemu; then
101 ./build-grub-module-verifier@BUILD_EXEEXT@ $tmpfile @target_cpu@ @platform@