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 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 .note
-R .comment
$tmpfile ||
exit 1
63 if ! test -z "${TARGET_OBJ2ELF}"; then
64 "${TARGET_OBJ2ELF}" $tmpfile ||
exit 1
67 tmpfile2
=${outfile}.tmp2
71 # remove old files if any
76 # Attach .modname and .moddeps sections
77 echo "char modname[] __attribute__ ((section(\"_modname, _modname\"))) = \"$modname\";" >$t1
79 for dep
in $deps; do echo "char moddep_$dep[] __attribute__ ((section(\"_moddeps, _moddeps\"))) = \"$dep\";" >>$t2; done
81 if test -n "$deps"; then
82 @TARGET_CC@ @TARGET_LDFLAGS@
-ffreestanding -nostdlib -o $tmpfile2 $t1 $t2 $tmpfile -Wl,-r,-d
84 @TARGET_CC@ @TARGET_LDFLAGS@
-ffreestanding -nostdlib -o $tmpfile2 $t1 $tmpfile -Wl,-r,-d
86 rm -f $t1 $t2 $tmpfile
89 cp $tmpfile $tmpfile.bin
90 @TARGET_OBJCONV@
-f@TARGET_MODULE_FORMAT@ \
91 -nr:_grub_mod_init
:grub_mod_init \
92 -nr:_grub_mod_fini
:grub_mod_fini \
93 -wd1106 -nu -nd $tmpfile.bin
$tmpfile ||
exit 1