summary refs log tree commit diff
path: root/pkgs/development/haskell-modules/gcc-clang-wrapper.sh
blob: d081be231a1ce9d1144668f3c4570e0c9fad6cab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh

inPreprocessorMode () {
    hasE=0
    hasU=0
    hasT=0
    for arg in "$@"
    do
        if [ 'x-E' = "x$arg" ];             then hasE=1; fi
        if [ 'x-undef' = "x$arg" ];         then hasU=1; fi
        if [ 'x-traditional' = "x$arg" ];   then hasT=1; fi
    done
    [ "$hasE$hasU$hasT" = '111' ]
}

extraClangArgs="-Wno-invalid-pp-token -Wno-unicode -Wno-trigraphs"

adjustPreprocessorLanguage () {
    newArgs=''
    while [ $# -gt 0 ]
    do
        newArgs="$newArgs $1"
        if [ "$1" = '-x' ]
        then
            shift
            if [ $# -gt 0 ]
            then
                if [ "$1" = 'c' ]
                then
                    newArgs="$newArgs assembler-with-cpp"
                else
                    newArgs="$newArgs $1"
                fi
            fi
        fi
        shift
    done
    echo $newArgs
}

if inPreprocessorMode "$@"
then
    exec clang $extraClangArgs `adjustPreprocessorLanguage "$@"`
else
    exec clang $extraClangArgs "${@/-nodefaultlibs/}"
fi