Ticket #54166: gccas.2.sh

File gccas.2.sh, 2.3 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# Its 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
10if [ "${GCCAS_SHUNT}" != "" ] ;then
11    echo ${GCCAS_SHUNT} "$@"
12    exec ${GCCAS_SHUNT} "$@"
13elif [ "${CLANG_ASSEMBLER}" = "" ] ;then
14    CLANG_ASSEMBLER="@CLANG@ -x assembler -c"
15fi
16
17HAS_INPUT_FILE=0 
18
19CLARGS=""
20
21# let's hope we never meet arguments with whitespace...
22while [ $# -ne 0 ]; do 
23     # Skip options
24    case ${1} in
25        # filter out options known to cause warnings
26        -I)
27            shift
28            ;;
29        # any assembler-exclusive options should be caught here and
30        # passed as "-Wa,${1} [-Wa,${2}]"
31        # Also, filter the most obvious GNU-style arguments
32        --32)
33            CLARGS="${CLARGS} -arch i386"
34            CLARGS="${CLARGS} -arch i386"
35            ;;
36        --64)
37            CLARGS="${CLARGS} -arch x86_64"
38            ;;
39        -help|--help)
40            echo "Usage: `basename $0` [options] <inputs>"
41            echo "Default clang assembler command: \$CLANG_ASSEMBLER=\"${CLANG_ASSEMBLER}\""
42            echo "Override by setting the CLANG_ASSEMBLER env. variable"
43            echo "Bypass the clang assembler argument translation by setting GCCAS_SHUNT to the path of the desired assembler"
44            echo
45            CLARGS="${CLARGS} ${1}"
46            ;;
47        -c)
48            # already included in the command
49            ;;
50        -force_cpusubtype_ALL|-mmacosx-version-min=*)
51            # arguments that would be passed to the linker:
52            ;;
53        -o|-arch)
54            CLARGS="${CLARGS} ${1} ${2}"
55                  shift
56            ;;
57        -*)
58            CLARGS="${CLARGS} ${1}"
59            ;;
60        *)
61            HAS_INPUT_FILE=1
62            CLARGS="${CLARGS} ${1}"
63            ;;
64    esac
65    shift
66done 
67
68if [ $HAS_INPUT_FILE -eq 1 ]; then 
69    exec ${CLANG_ASSEMBLER} ${CLARGS}
70else 
71    exec ${CLANG_ASSEMBLER} ${CLARGS} -
72fi