Ticket #54166: gccas.sh

File gccas.sh, 1.9 KB (added by RJVB (René Bertin), 7 years ago)
Line 
1#!/bin/sh
2# This is a wrapper around the clang assembler that allows to call it
3# in lieu and place of the `as` command (= Apple's version of GNU as, gas).
4# It's name is taken from the old gccas tool that mimicked gas for use by
5# the llvm-gcc front-end. The purpose remains the same: being able to
6# use GCC compilers as a front-end for the LLVM assembler/linker toolchain
7# with the goal of having access to the full x86_64 instruction set from
8# those compilers (which include gfortran).
9
10HAS_INPUT_FILE=0 
11
12if [ "${CLANG_ASSEMBLER}" = "" ] ;then
13    CLANG_ASSEMBLER="/opt/local/bin/clang-mp-4.0 -x assembler -c"
14fi
15CLARGS=""
16
17# let's hope we never meet arguments with whitespace...
18while [ $# -ne 0 ]; do 
19     # Skip options
20    case ${1} in
21        # filter out options known to cause warnings
22        -I)
23            shift
24            ;;
25        # any assembler-exclusive options should be caught here and
26        # passed as "-Wa,${1} [-Wa,${2}]"
27        # Also, filter the most obvious GNU-style arguments
28        --32)
29            CLARGS="${CLARGS} -arch i386"
30            CLARGS="${CLARGS} -arch i386"
31            ;;
32        --64)
33            CLARGS="${CLARGS} -arch x86_64"
34            ;;
35        -help|--help)
36            echo "Usage: `basename $0` [options] <inputs>"
37            echo "Default clang assembler command: \$CLANG_ASSEMBLER=\"${CLANG_ASSEMBLER}\""
38            echo "Override by setting the CLANG_ASSEMBLER env. variable"
39            echo
40            CLARGS="${CLARGS} ${1}"
41            ;;
42        -c)
43            # already included in the command
44            ;;
45        -*)
46            # use generic options as assembler-specific
47            CLARGS="${CLARGS} ${1}"
48            ;;
49        *)
50            HAS_INPUT_FILE=1
51            CLARGS="${CLARGS} ${1}"
52            ;;
53    esac
54    shift
55done 
56
57if [ $HAS_INPUT_FILE -eq 1 ]; then 
58    exec ${CLANG_ASSEMBLER} ${CLARGS}
59else 
60    exec ${CLANG_ASSEMBLER} ${CLARGS} -
61fi