source: rtems-tools/rtemstoolkit/elftoolchain/common/native-elf-format @ 0c5db2d

5
Last change on this file since 0c5db2d was 0c5db2d, checked in by Chris Johns <chrisj@…>, on 04/29/18 at 01:55:37

rtemstoolkit: Update elftoolchain to the latest code.

The update is taken from https://github.com/elftoolchain/elftoolchain.

Update #3417

  • Property mode set to 100755
File size: 1.1 KB
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
9program=`basename $0`
10tmp_c=`mktemp -u nefXXXXXX`.c
11tmp_o=`echo ${tmp_c} | sed -e 's/.c$/.o/'`
12
13trap "rm -f ${tmp_c} ${tmp_o}"  0 1 2 3 15
14
15touch ${tmp_c}
16
17echo "/* Generated by ${program} on `date` */"
18
19cc -c ${tmp_c} -o ${tmp_o}
20readelf -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    }
40END {
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.