source: rtems-tools/rtemstoolkit/elftoolchain/common/native-elf-format @ 763f102

5
Last change on this file since 763f102 was 763f102, checked in by Sebastian Huber <sebastian.huber@…>, on 03/05/20 at 09:43:50

rtemstoolkit: Detect native SPARCV9 ELF arch

  • Property mode set to 100755
File size: 1.4 KB
Line 
1#!/bin/sh
2#
3# $Id: native-elf-format 3293 2016-01-07 19:26:27Z emaste $
4#
5# Find the native ELF format for a host platform by compiling a
6# test object and examining the resulting object.
7#
8# This script is used if there is no easy way to determine this
9# information statically at compile time.
10
11program=`basename $0`
12tmp_c=`mktemp -u nefXXXXXX`.c
13tmp_o=`echo ${tmp_c} | sed -e 's/.c$/.o/'`
14
15trap "rm -f ${tmp_c} ${tmp_o}"  0 1 2 3 15
16
17touch ${tmp_c}
18
19echo "/* Generated by ${program} on `date` */"
20
21cc -c ${tmp_c} -o ${tmp_o}
22LC_ALL=C readelf -h ${tmp_o} | awk '
23$1 ~ "Class:" {
24        sub("ELF","",$2); elfclass = $2;
25    }
26$1 ~ "Data:"  {
27        if (match($0, "little")) {
28            elfdata = "LSB";
29        } else {
30            elfdata = "MSB";
31        }
32    }
33$1 ~ "Machine:" {
34        if (match($0, "ARM")) {
35            elfarch = "EM_ARM";
36        } else if (match($0, "AArch64")) {
37            elfarch = "EM_AARCH64";
38        } else if (match($0, "Intel.*386")) {
39            elfarch = "EM_386";
40        } else if (match($0, "MIPS")) {
41            elfarch = "EM_MIPS";
42        } else if (match($0, ".*[xX]86[-_]64")) {
43            elfarch = "EM_X86_64";
44        } else if (match($0, "Sparc v9")) {
45            elfarch = "EM_SPARCV9";
46        } else {
47            elfarch = "unknown";
48        }
49    }
50END {
51    printf("#define     ELFTC_CLASS     ELFCLASS%s\n", elfclass);
52    printf("#define     ELFTC_ARCH      %s\n", elfarch);
53    printf("#define     ELFTC_BYTEORDER ELFDATA2%s\n", elfdata);
54}'
55
Note: See TracBrowser for help on using the repository browser.