5
Line | |
---|
1 | #!/bin/sh |
---|
2 | # |
---|
3 | # Find the native ELF format for a host platform by compiling a |
---|
4 | # test object and examining the resulting object. |
---|
5 | # |
---|
6 | # This script is used if there is no easy way to determine this |
---|
7 | # information statically at compile time. |
---|
8 | |
---|
9 | program=`basename $0` |
---|
10 | tmp_c=`mktemp -u nefXXXXXX`.c |
---|
11 | tmp_o=`echo ${tmp_c} | sed -e 's/.c$/.o/'` |
---|
12 | |
---|
13 | trap "rm -f ${tmp_c} ${tmp_o}" 0 1 2 3 15 |
---|
14 | |
---|
15 | touch ${tmp_c} |
---|
16 | |
---|
17 | echo "/* Generated by ${program} on `date` */" |
---|
18 | |
---|
19 | cc -c ${tmp_c} -o ${tmp_o} |
---|
20 | readelf -h ${tmp_o} | awk ' |
---|
21 | $1 ~ "Class:" { |
---|
22 | sub("ELF","",$2); elfclass = $2; |
---|
23 | } |
---|
24 | $1 ~ "Data:" { |
---|
25 | if (match($0, "little")) { |
---|
26 | elfdata = "LSB"; |
---|
27 | } else { |
---|
28 | elfdata = "MSB"; |
---|
29 | } |
---|
30 | } |
---|
31 | $1 ~ "Machine:" { |
---|
32 | if (match($0, "Intel.*386")) { |
---|
33 | elfarch = "EM_386"; |
---|
34 | } else if (match($0, ".*X86-64")) { |
---|
35 | elfarch = "EM_X86_64"; |
---|
36 | } else { |
---|
37 | elfarch = "unknown"; |
---|
38 | } |
---|
39 | } |
---|
40 | END { |
---|
41 | printf("#define ELFTC_CLASS ELFCLASS%s\n", elfclass); |
---|
42 | printf("#define ELFTC_ARCH %s\n", elfarch); |
---|
43 | printf("#define ELFTC_BYTEORDER ELFDATA2%s\n", elfdata); |
---|
44 | }' |
---|
45 | |
---|
Note: See
TracBrowser
for help on using the repository browser.