3 # $Id: native-elf-format 3735 2019-04-25 19:44:47Z jkoshy $
5 # Find the native ELF format for a host platform by compiling a
6 # test object and examining the resulting object.
8 # This script is used if there is no easy way to determine this
9 # information statically at compile time.
12 tmp_c=`mktemp -u nefXXXXXX`.c
13 tmp_o=`echo ${tmp_c} | sed -e 's/.c$/.o/'`
15 trap "rm -f ${tmp_c} ${tmp_o}" 0 1 2 3 15
19 echo "/* Generated by ${program} on `date` */"
21 cc -c ${tmp_c} -o ${tmp_o}
22 LC_ALL=C readelf -h ${tmp_o} | awk '
24 sub("ELF","",$2); elfclass = $2;
27 if (match($0, "little")) {
34 if (match($0, "Intel.*386")) {
36 } else if (match($0, "MIPS")) {
38 } else if (match($0, ".*[xX]86[-_]64")) {
39 elfarch = "EM_X86_64";
40 } else if (match($0, "PowerPC64")) {
42 } else if (match($0, "AArch64")) {
43 elfarch = "EM_AARCH64";
49 printf("#define ELFTC_CLASS ELFCLASS%s\n", elfclass);
50 printf("#define ELFTC_ARCH %s\n", elfarch);
51 printf("#define ELFTC_BYTEORDER ELFDATA2%s\n", elfdata);