Merge remote-tracking branch 'mfleming/for-hpa/elflink/core' into elflink
[syslinux.git] / elf_gen_dep.sh
blobdba990d47f1e35e7943a913c4c94565ca009eb47
1 #!/bin/sh
3 #######################################################
4 # Round 1: get all the loacl and external symbols
5 #######################################################
7 for i in com32/elflink/modules/*.c32 core/isolinux.elf core/pxelinux.elf com32/elflink/ldlinux/*.c32
8 do
9 # module=$(echo $i | sed "s/^\(.*\).o$/\1/")
11 # remove the path infomation
12 module=$(echo $i | sed "s/^.*\/\(.*\)$/\1/")
14 readelf -s $i > temp.txt
15 #Get the last 2 items of each line
16 cut -c47- temp.txt > $module.txt
17 rm temp.txt
19 #Get the unresolved symbols
20 sed -n -e "/UND $/d" -e "/_GLOBAL_OFFSET_TABLE_/d" -e "s/^.UND.\(.*\)$/\1/p" $module.txt > $module.ext
22 #Get the local symbols
23 sed -n -e "/UND/d" -e "/ABS/d" -e "/...[0-9] $/d" -e "/...[0-9] \./d" -e "/...[0-9]/p" $module.txt > $module.int
24 sed -i -e "s/^.....//g" $module.int
25 sed -i -e "s/^\(.*\)$/\1 <$module>/g" $module.int
27 cat $module.int >> all.txt
28 done
31 touch modules.dep
33 #######################################################
34 # Round 2: get all the loacl and external symbols
35 #######################################################
37 # Consolidate the dependent modules to one line and remove
38 # the redundant ones, and the "core"
39 rm_cr ()
41 touch rmcr.tmp
42 all_dep=$module:
43 space=' '
45 while read line
47 # skip the module which is alreay on the list
48 grep $line rmcr.tmp > /dev/null && continue
50 # grep extlinux/isolinux and remove them
51 echo $line | grep extlinux > /dev/null && continue
52 echo $line | grep isolinux > /dev/null && continue
53 echo $line | grep pxelinux > /dev/null && continue
55 all_dep=$all_dep$space$line
56 echo $all_dep > rmcr.tmp
57 done
59 echo $all_dep >> modules.dep
60 rm rmcr.tmp
63 # Find the symbol belongs to which module by screening all.txt, do it
64 # one by one, and the result "resolve.tmp" will be a file like:
65 # a.c32
66 # b.c32
67 # c.c32
68 resolve_sym ()
70 touch resolve.tmp
72 while read symbol
74 # If no one provides the symbol we're trying to
75 # resolve then add it to the list of unresolved
76 # symbols.
77 grep -q $symbol all.txt
78 if [ $? -ne 0 ]; then
79 # We only need to add the symbol once
80 if [[ ! "$unresolved_symbols" =~ "$symbol" ]]; then
81 unresolved_symbols="$unresolved_symbols $symbol"
83 else
84 #echo $symbol
85 sed -n -e "s/^$symbol <\(.*\)>/\1/p" all.txt >> resolve.tmp
86 #grep $symbol all.txt
88 done
90 rm_cr < resolve.tmp
91 rm resolve.tmp
94 #only test name start with a/b
95 #rm [c-z]*.ext
97 if [ -e modules.dep ]
98 then
99 rm modules.dep
100 touch modules.dep
103 # Don't need to resolve the core symbols
104 for i in extlinux isolinux pxelinux
106 if [ -e $i.elf.ext ]
107 then
108 rm $i.elf.ext
110 done
112 for i in *.ext
114 module=$(echo $i | sed "s/^\(.*\).ext$/\1/")
115 resolve_sym < $i
116 done
118 # Do some cleanup
119 rm *.txt
120 rm *.ext
121 rm *.int
123 if [ "$unresolved_symbols" ]; then
124 echo "WARNING: These symbols could not be resolved:" $unresolved_symbols
127 echo ELF modules dependency is bult up, pls check modules.dep!