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