summaryrefslogtreecommitdiffstats
path: root/rtemstoolkit/elftoolchain/common/native-elf-format
blob: af707591d19d7e486c52224c83a9915cfcb0d5cd (plain) (blame)
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
#!/bin/sh
#
# $Id: native-elf-format 2064 2011-10-26 15:12:32Z jkoshy $
#
# Find the native ELF format for a host platform by compiling a
# test object and examining the resulting object.
#
# This script is used if there is no easy way to determine this
# information statically at compile time.

program=`basename $0`
tmp_c=`mktemp -u nefXXXXXX`.c
tmp_o=`echo ${tmp_c} | sed -e 's/.c$/.o/'`

trap "rm -f ${tmp_c} ${tmp_o}"	0 1 2 3 15

touch ${tmp_c}

echo "/* Generated by ${program} on `date` */"

cc -c ${tmp_c} -o ${tmp_o}
readelf -h ${tmp_o} | awk '
$1 ~ "Class:" {
        sub("ELF","",$2); elfclass = $2;
    }
$1 ~ "Data:"  {
        if (match($0, "little")) {
            elfdata = "LSB";
 	} else {
            elfdata = "MSB";
	}
    }
$1 ~ "Machine:" {
        if (match($0, "Intel.*386")) {
            elfarch = "EM_386";
        } else if (match($0, ".*X86-64")) {
            elfarch = "EM_X86_64";
        } else {
            elfarch = "unknown";
        }
    }
END {
    printf("#define	ELFTC_CLASS	ELFCLASS%s\n", elfclass);
    printf("#define	ELFTC_ARCH	%s\n", elfarch);
    printf("#define	ELFTC_BYTEORDER	ELFDATA2%s\n", elfdata);
}'