2011-05-18 11:53:07 +00:00
|
|
|
#! /bin/sh
|
|
|
|
set -e
|
|
|
|
|
2010-08-29 11:13:07 +00:00
|
|
|
# Copyright (C) 2010 Free Software Foundation, Inc.
|
|
|
|
#
|
|
|
|
# This gensymlist.sh is free software; the author
|
|
|
|
# gives unlimited permission to copy and/or distribute it,
|
|
|
|
# with or without modifications, as long as this notice is preserved.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
|
|
|
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
|
|
# PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
#
|
2010-09-19 13:59:36 +00:00
|
|
|
# genmod.sh moddep.lst normal.module normal.mod
|
2010-08-29 11:13:07 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
moddep=$1
|
|
|
|
infile=$2
|
|
|
|
outfile=$3
|
|
|
|
|
|
|
|
tmpfile=${outfile}.tmp
|
|
|
|
modname=`echo $infile | sed -e 's@\.module.*$@@'`
|
|
|
|
|
|
|
|
if ! grep ^$modname: $moddep >/dev/null; then
|
|
|
|
echo "warning: moddep.lst has no dependencies for $modname" >&2
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
deps=`grep ^$modname: $moddep | sed s@^.*:@@`
|
|
|
|
|
|
|
|
# remove old files if any
|
|
|
|
rm -f $tmpfile $outfile
|
|
|
|
|
2012-02-29 15:00:27 +00:00
|
|
|
if test x@TARGET_APPLE_CC@ != x1; then
|
|
|
|
# stripout .modname and .moddeps sections from input module
|
2013-08-21 23:56:28 +00:00
|
|
|
@TARGET_OBJCOPY@ -R .modname -R .moddeps $infile $tmpfile
|
2010-08-29 11:13:07 +00:00
|
|
|
|
2012-02-29 15:00:27 +00:00
|
|
|
# Attach .modname and .moddeps sections
|
|
|
|
t1=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
|
|
|
|
printf "$modname\0" >$t1
|
2010-08-29 11:13:07 +00:00
|
|
|
|
2012-02-29 15:00:27 +00:00
|
|
|
t2=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
|
|
|
|
for dep in $deps; do printf "$dep\0" >> $t2; done
|
2010-08-29 11:13:07 +00:00
|
|
|
|
2012-02-29 15:00:27 +00:00
|
|
|
if test -n "$deps"; then
|
2013-08-21 23:56:28 +00:00
|
|
|
@TARGET_OBJCOPY@ --add-section .modname=$t1 --add-section .moddeps=$t2 $tmpfile
|
2012-02-29 15:00:27 +00:00
|
|
|
else
|
2013-08-21 23:56:28 +00:00
|
|
|
@TARGET_OBJCOPY@ --add-section .modname=$t1 $tmpfile
|
2012-02-29 15:00:27 +00:00
|
|
|
fi
|
|
|
|
rm -f $t1 $t2
|
2010-08-29 11:13:07 +00:00
|
|
|
|
2011-01-13 21:23:49 +00:00
|
|
|
if ! test -z "${TARGET_OBJ2ELF}"; then
|
|
|
|
./${TARGET_OBJ2ELF} $tmpfile || exit 1
|
2010-08-29 11:13:07 +00:00
|
|
|
fi
|
|
|
|
if test x@platform@ != xemu; then
|
2013-08-21 23:56:28 +00:00
|
|
|
@TARGET_STRIP@ --strip-unneeded \
|
2010-08-29 11:13:07 +00:00
|
|
|
-K grub_mod_init -K grub_mod_fini \
|
|
|
|
-K _grub_mod_init -K _grub_mod_fini \
|
2012-03-10 15:55:48 +00:00
|
|
|
-R .note.gnu.gold-version -R .note.GNU-stack \
|
|
|
|
-R .note -R .comment $tmpfile || exit 1
|
2010-08-29 11:13:07 +00:00
|
|
|
fi
|
|
|
|
else
|
2012-02-29 15:00:27 +00:00
|
|
|
tmpfile2=${outfile}.tmp2
|
|
|
|
t1=${outfile}.t1.c
|
|
|
|
t2=${outfile}.t2.c
|
|
|
|
|
|
|
|
# remove old files if any
|
|
|
|
rm -f $t1 $t2
|
|
|
|
|
|
|
|
cp $infile $tmpfile
|
|
|
|
|
|
|
|
# Attach .modname and .moddeps sections
|
|
|
|
echo "char modname[] __attribute__ ((section(\"_modname, _modname\"))) = \"$modname\";" >$t1
|
|
|
|
|
2012-05-28 15:32:24 +00:00
|
|
|
for dep in $deps; do echo "char moddep_$dep[] __attribute__ ((section(\"_moddeps, _moddeps\"))) = \"$dep\";" >>$t2; done
|
2012-02-29 15:00:27 +00:00
|
|
|
|
|
|
|
if test -n "$deps"; then
|
|
|
|
@TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib -o $tmpfile2 $t1 $t2 $tmpfile -Wl,-r,-d
|
|
|
|
else
|
|
|
|
@TARGET_CC@ @TARGET_LDFLAGS@ -ffreestanding -nostdlib -o $tmpfile2 $t1 $tmpfile -Wl,-r,-d
|
|
|
|
fi
|
|
|
|
rm -f $t1 $t2 $tmpfile
|
|
|
|
mv $tmpfile2 $tmpfile
|
|
|
|
|
2010-08-29 11:13:07 +00:00
|
|
|
cp $tmpfile $tmpfile.bin
|
2013-08-21 23:56:28 +00:00
|
|
|
@TARGET_OBJCONV@ -f@TARGET_MODULE_FORMAT@ \
|
2010-08-29 11:13:07 +00:00
|
|
|
-nr:_grub_mod_init:grub_mod_init \
|
|
|
|
-nr:_grub_mod_fini:grub_mod_fini \
|
2012-06-05 15:20:39 +00:00
|
|
|
-wd1106 -nu -nd $tmpfile.bin $tmpfile || exit 1
|
2010-08-29 11:13:07 +00:00
|
|
|
rm -f $name.bin
|
|
|
|
fi
|
|
|
|
mv $tmpfile $outfile
|