Merge pull request #438 from s4Ys369/revert-434-patch-1
[sm64pc.git] / tools / calc_bss.sh
blobe7369d87d755f080a534da45bd71844083be3fdf
1 #!/bin/bash
2 # Given a list of header files, compute the bss index that results from
3 # including them. (See prevent_bss_reordering.h for more information.)
5 TEMPC=$(mktemp -t bss.XXXXXXX.c)
6 TEMPO=$(mktemp -t bss.XXXXXXX.o)
7 trap "rm -f $TEMPC $TEMPO" EXIT
9 set -e
11 if [[ $# = 0 ]]; then
12 echo "Usage: ./tools/calc_bss.sh file1.h file2.h ..." >&2
13 exit 1
16 if [ -z "$QEMU_IRIX" ]; then
17 echo "env variable QEMU_IRIX should point to the qemu-mips binary" >&2
18 exit 1
21 if [ -z "$CROSS" ]; then
22 CROSS=mips-linux-gnu-
25 # bss indexing starts at 3
26 for I in {3..255}; do
27 echo "char bss$I;" >> $TEMPC
28 done
29 for I in {0..2}; do
30 echo "char bss$I;" >> $TEMPC
31 done
33 while [[ $# -gt 0 ]]; do
34 echo "#include \"$1\"" >> $TEMPC
35 shift
36 done
38 echo "char measurement;" >> $TEMPC
40 $QEMU_IRIX -silent -L $IRIX_ROOT $IRIX_ROOT/usr/bin/cc -c -non_shared -G 0 \
41 -g -Xcpluscomm -mips2 -I $(pwd)/include/ $TEMPC -o $TEMPO
43 LINE=$(${CROSS}objdump -t $TEMPO | grep measurement | cut -d' ' -f1)
44 NUM=$((0x$LINE - 1))
45 echo "bss index: $NUM"