]>
Commit | Line | Data |
---|---|---|
5626056f CW |
1 | #! /bin/sh |
2 | set -e | |
3 | ||
6b5f780f BC |
4 | # Copyright (C) 2010 Free Software Foundation, Inc. |
5 | # | |
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. | |
9 | # | |
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 | |
13 | # PARTICULAR PURPOSE. | |
14 | ||
15 | # | |
16 | # Example: | |
17 | # | |
3572f2b6 | 18 | # genmod.sh moddep.lst normal.module normal.mod |
6b5f780f BC |
19 | # |
20 | ||
21 | moddep=$1 | |
22 | infile=$2 | |
23 | outfile=$3 | |
24 | ||
25 | tmpfile=${outfile}.tmp | |
26 | modname=`echo $infile | sed -e 's@\.module.*$@@'` | |
27 | ||
28 | if ! grep ^$modname: $moddep >/dev/null; then | |
29 | echo "warning: moddep.lst has no dependencies for $modname" >&2 | |
30 | exit 0 | |
31 | fi | |
32 | ||
33 | deps=`grep ^$modname: $moddep | sed s@^.*:@@` | |
34 | ||
35 | # remove old files if any | |
36 | rm -f $tmpfile $outfile | |
37 | ||
a9f25a08 | 38 | if test x@TARGET_APPLE_LINKER@ != x1; then |
31a12124 | 39 | # stripout .modname and .moddeps sections from input module |
fc97214f | 40 | @TARGET_OBJCOPY@ -R .modname -R .moddeps $infile $tmpfile |
6b5f780f | 41 | |
31a12124 VS |
42 | # Attach .modname and .moddeps sections |
43 | t1=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 | |
44 | printf "$modname\0" >$t1 | |
6b5f780f | 45 | |
31a12124 VS |
46 | t2=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 |
47 | for dep in $deps; do printf "$dep\0" >> $t2; done | |
6b5f780f | 48 | |
31a12124 | 49 | if test -n "$deps"; then |
fc97214f | 50 | @TARGET_OBJCOPY@ --add-section .modname=$t1 --add-section .moddeps=$t2 $tmpfile |
31a12124 | 51 | else |
fc97214f | 52 | @TARGET_OBJCOPY@ --add-section .modname=$t1 $tmpfile |
31a12124 VS |
53 | fi |
54 | rm -f $t1 $t2 | |
6b5f780f | 55 | |
6b5f780f | 56 | if test x@platform@ != xemu; then |
fc97214f | 57 | @TARGET_STRIP@ --strip-unneeded \ |
6b5f780f BC |
58 | -K grub_mod_init -K grub_mod_fini \ |
59 | -K _grub_mod_init -K _grub_mod_fini \ | |
0f021838 VS |
60 | -R .note.gnu.gold-version -R .note.GNU-stack \ |
61 | -R .note -R .comment $tmpfile || exit 1 | |
6b5f780f | 62 | fi |
23d2abc3 VS |
63 | if ! test -z "${TARGET_OBJ2ELF}"; then |
64 | "${TARGET_OBJ2ELF}" $tmpfile || exit 1 | |
65 | fi | |
6b5f780f | 66 | else |
31a12124 VS |
67 | tmpfile2=${outfile}.tmp2 |
68 | t1=${outfile}.t1.c | |
69 | t2=${outfile}.t2.c | |
70 | ||
71 | # remove old files if any | |
72 | rm -f $t1 $t2 | |
73 | ||
74 | cp $infile $tmpfile | |
75 | ||
76 | # Attach .modname and .moddeps sections | |
77 | echo "char modname[] __attribute__ ((section(\"_modname, _modname\"))) = \"$modname\";" >$t1 | |
78 | ||
85a730ca | 79 | for dep in $deps; do echo "char moddep_$dep[] __attribute__ ((section(\"_moddeps, _moddeps\"))) = \"$dep\";" >>$t2; done |
31a12124 VS |
80 | |
81 | if test -n "$deps"; then | |
82 | @TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib -o $tmpfile2 $t1 $t2 $tmpfile -Wl,-r,-d | |
83 | else | |
84 | @TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib -o $tmpfile2 $t1 $tmpfile -Wl,-r,-d | |
85 | fi | |
86 | rm -f $t1 $t2 $tmpfile | |
87 | mv $tmpfile2 $tmpfile | |
88 | ||
6b5f780f | 89 | cp $tmpfile $tmpfile.bin |
fc97214f | 90 | @TARGET_OBJCONV@ -f@TARGET_MODULE_FORMAT@ \ |
6b5f780f BC |
91 | -nr:_grub_mod_init:grub_mod_init \ |
92 | -nr:_grub_mod_fini:grub_mod_fini \ | |
7284143a | 93 | -wd1106 -nu -nd $tmpfile.bin $tmpfile || exit 1 |
6b5f780f BC |
94 | rm -f $name.bin |
95 | fi | |
96 | mv $tmpfile $outfile |