File: genmod.sh.in

package info (click to toggle)
grub2 2.02+dfsg1-20
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 61,784 kB
  • sloc: ansic: 384,086; asm: 16,323; sh: 13,230; cpp: 1,994; makefile: 1,488; python: 1,458; sed: 423; lex: 393; yacc: 267; awk: 75; lisp: 50; perl: 31
file content (99 lines) | stat: -rw-r--r-- 2,940 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#! /bin/sh
set -e

# 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:
#
# genmod.sh moddep.lst normal.module build-grub-module-verifier normal.mod
#

moddep=$1
infile=$2
outfile=$4

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

if test x@TARGET_APPLE_LINKER@ != x1; then
    # stripout .modname and .moddeps sections from input module
    @TARGET_OBJCOPY@ -R .modname -R .moddeps $infile $tmpfile

    # Attach .modname and .moddeps sections
    t1=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
    printf "$modname\0" >$t1

    t2=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
    for dep in $deps; do printf "$dep\0" >> $t2; done

    if test -n "$deps"; then
	@TARGET_OBJCOPY@ --add-section .modname=$t1 --add-section .moddeps=$t2 $tmpfile
    else
	@TARGET_OBJCOPY@ --add-section .modname=$t1 $tmpfile
    fi
    rm -f $t1 $t2

	if test x@platform@ != xemu; then
	    @TARGET_STRIP@ --strip-unneeded \
		-K grub_mod_init -K grub_mod_fini \
		-K _grub_mod_init -K _grub_mod_fini \
		-R .note.gnu.gold-version -R .note.GNU-stack \
		-R .note -R .comment -R .ARM.exidx $tmpfile || exit 1
	fi
	if ! test -z "${TARGET_OBJ2ELF}"; then
	    "${TARGET_OBJ2ELF}" $tmpfile || exit 1
	fi
else
    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

    for dep in $deps; do echo "char moddep_$dep[] __attribute__ ((section(\"_moddeps, _moddeps\"))) = \"$dep\";" >>$t2; done

    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

	cp $tmpfile $tmpfile.bin
	@TARGET_OBJCONV@ -f@TARGET_MODULE_FORMAT@ \
	    -nr:_grub_mod_init:grub_mod_init \
	    -nr:_grub_mod_fini:grub_mod_fini \
	    -wd1106 -nu -nd $tmpfile.bin $tmpfile || exit 1
	rm -f $tmpfile.bin
fi
if test x@platform@ != xemu; then
    ./build-grub-module-verifier@BUILD_EXEEXT@ $tmpfile @target_cpu@ @platform@
fi
mv $tmpfile $outfile