#!/bin/sh
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This figures out the architecture of the version of Python we are building
# pyautolib against.
#
#  python_arch.sh /usr/lib/libpython2.5.so.1.0
#  python_arch.sh /path/to/sysroot/usr/lib/libpython2.4.so.1.0
#

python=$(readlink -f "$1")
if [ ! -r "$python" ]; then
  echo unknown
  exit 0
fi
file_out=$(file "$python")
if [ $? -ne 0 ]; then
  echo unknown
  exit 0
fi

echo $file_out | grep -qs "ARM"
if [ $? -eq 0 ]; then
  echo arm
  exit 0
fi

echo $file_out | grep -qs "MIPS"
if [ $? -eq 0 ]; then
  echo mipsel
  exit 0
fi

echo $file_out | grep -qs "x86-64"
if [ $? -eq 0 ]; then
  echo x64
  exit 0
fi

echo $file_out | grep -qs "Intel 80386"
if [ $? -eq 0 ]; then
  echo ia32
  exit 0
fi

exit 1

#!/bin/sh
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This figures out the architecture of the version of Python we are building
# pyautolib against.
#
#  python_arch.sh /usr/lib/libpython2.5.so.1.0
#  python_arch.sh /path/to/sysroot/usr/lib/libpython2.4.so.1.0
#

file_out=$(file --dereference "$1")
if [ $? -ne 0 ]; then
  echo unknown
  exit 0
fi

echo $file_out | grep -qs "ARM"
if [ $? -eq 0 ]; then
  echo arm
  exit 0
fi

echo $file_out | grep -qs "MIPS"
if [ $? -eq 0 ]; then
  echo mipsel
  exit 0
fi

echo $file_out | grep -qs "x86-64"
if [ $? -eq 0 ]; then
  echo x64
  exit 0
fi

echo $file_out | grep -qs "Intel 80386"
if [ $? -eq 0 ]; then
  echo ia32
  exit 0
fi

exit 1

Use `file --dereference' instead of `readlink -f' + `file'.
Use `file --dereference' instead of `readlink -f' + `file'.

`readlink -f' is not standard and may not be present on all systems (such as
some BSDs).

Instead of the readlink+file combo, just ask file(1) to dereference the file
it is given.

R=mark@chromium.org

Review URL: https://codereview.chromium.org/19221002

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@211783 0039d316-1c4b-4281-b951-d872f2087c98
