]> git.proxmox.com Git - grub2.git/blob - grub-core/genmod.sh.in
* grub-core/font/font_cmd.c (loadfont_command): Set grub_errno
[grub2.git] / grub-core / genmod.sh.in
1 #! /bin/sh -e
2 #
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 #
15 # Example:
16 #
17 # genmod.sh moddep.lst normal.module normal.mod
18 #
19
20 moddep=$1
21 infile=$2
22 outfile=$3
23
24 tmpfile=${outfile}.tmp
25 modname=`echo $infile | sed -e 's@\.module.*$@@'`
26
27 if ! grep ^$modname: $moddep >/dev/null; then
28 echo "warning: moddep.lst has no dependencies for $modname" >&2
29 exit 0
30 fi
31
32 deps=`grep ^$modname: $moddep | sed s@^.*:@@`
33
34 # remove old files if any
35 rm -f $tmpfile $outfile
36
37 # stripout .modname and .moddeps sections from input module
38 @OBJCOPY@ -R .modname -R .moddeps $infile $tmpfile
39
40 # Attach .modname and .moddeps sections
41 t1=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
42 printf "$modname\0" >$t1
43
44 t2=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
45 for dep in $deps; do printf "$dep\0" >> $t2; done
46
47 if test -n "$deps"; then
48 @OBJCOPY@ --add-section .modname=$t1 --add-section .moddeps=$t2 $tmpfile
49 else
50 @OBJCOPY@ --add-section .modname=$t1 $tmpfile
51 fi
52 rm -f $t1 $t2
53
54 if test x@TARGET_APPLE_CC@ != x1; then
55 if ! test -z "${TARGET_OBJ2ELF}"; then
56 ./${TARGET_OBJ2ELF} $tmpfile || exit 1
57 fi
58 if test x@platform@ != xemu; then
59 @STRIP@ --strip-unneeded \
60 -K grub_mod_init -K grub_mod_fini \
61 -K _grub_mod_init -K _grub_mod_fini \
62 -R .note -R .comment $tmpfile || exit 1
63 fi
64 else
65 # XXX Test these Apple CC fixes
66 cp $tmpfile $tmpfile.bin
67 @OBJCONV@ -f@TARGET_MODULE_FORMAT@ \
68 -nr:_grub_mod_init:grub_mod_init \
69 -nr:_grub_mod_fini:grub_mod_fini \
70 -wd1106 -ew2030 -ew2050 -nu -nd $tmpfile.bin $tmpfile || exit 1
71 rm -f $name.bin
72 fi
73 mv $tmpfile $outfile