ceaada8cc5f0936eae1172c43794b955009cd9cd
[dragonfly.git] / libexec / customcc / cc.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2009-2014
4 #       The DragonFly Project.  All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # 1. Redistributions of source code must retain the above copyright
11 #    notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 #    notice, this list of conditions and the following disclaimer in
14 #    the documentation and/or other materials provided with the
15 #    distribution.
16 # 3. Neither the name of The DragonFly Project nor the names of its
17 #    contributors may be used to endorse or promote products derived
18 #    from this software without specific, prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
24 # COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 # SUCH DAMAGE.
32 #
33
34 CNAME=$(basename $0)
35
36 INCPREFIX=@@INCPREFIX@@
37 MACHARCH=@@MACHARCH@@
38 MACHREL=@@MACHREL@@
39
40 . /etc/defaults/compilers.conf
41 [ -f /etc/compilers.conf ] && . /etc/compilers.conf
42
43
44 case ${CNAME} in
45         gcc)
46                 CUSTOM_GCC=`eval echo \$\{${CCVER}_GCC\}`
47                 if [ -n  "${CUSTOM_GCC}" ]; then
48                         COMPILER=${CUSTOM_GCC}
49                         INCOPT=`eval echo \$\{${CCVER}_INCOPT\}`
50                 else
51                         COMPILER=/usr/libexec/gcc47/gcc
52                         INCOPT=${STD_INCOPT}
53                 fi
54                 ;;
55         g++)
56                 CUSTOM_GXX=`eval echo \$\{${CCVER}_GXX\}`
57                 if [ -n  "${CUSTOM_GXX}" ]; then
58                         COMPILER=${CUSTOM_GXX}
59                         INCOPT=`eval echo \$\{${CCVER}_INCOPT\}`
60                         INCOPTCXX=`eval echo \$\{${CCVER}_INCOPTCXX\}`
61                 else
62                         COMPILER=/usr/libexec/gcc47/g++
63                         INCOPT=${GCC_INCOPT}
64                         INCOPTCXX="-isystem /usr/include/c++/4.7"
65                 fi
66                 ;;
67         clang)
68                 CUSTOM_CLANG=`eval echo \$\{${CCVER}_CLANG\}`
69                 if [ -n  "${CUSTOM_CLANG}" ]; then
70                         COMPILER=${CUSTOM_CLANG}
71                         INCOPT=`eval echo \$\{${CCVER}_INCOPT\}`
72                 else
73                         COMPILER=/usr/libexec/clangbase/clang
74                         INCOPT=${STD_INCOPT}
75                 fi
76                 ;;
77         clang++)
78                 CUSTOM_CLANGCXX=`eval echo \$\{${CCVER}_CLANGCXX\}`
79                 if [ -n  "${CUSTOM_CLANGCXX}" ]; then
80                         COMPILER=${CUSTOM_CLANGCXX}
81                         INCOPT=`eval echo \$\{${CCVER}_INCOPT\}`
82                         INCOPTCXX=`eval echo \$\{${CCVER}_INCOPTCXX\}`
83                 else
84                         COMPILER=/usr/libexec/clangbase/clang++
85                         INCOPT=${CLANG_INCOPT}
86                         INCOPTCXX="-isystem /usr/include/c++/4.7"
87                 fi
88                 ;;
89         cc)
90                 CUSTOM_CC=`eval echo \$\{${CCVER}_CC\}`
91                 if [ -n ${CUSTOM_CC} ]; then
92                         COMPILER=${CUSTOM_CC}
93                         INCOPT=`eval echo \$\{${CCVER}_INCOPT\}`
94                 else
95                         echo "${CCVER}_CC undefined, see compilers.conf(5)"
96                         exit 1
97                 fi
98                 ;;
99         c++|CC)
100                 CUSTOM_CXX=`eval echo \$\{${CCVER}_CXX\}`
101                 if [ -n ${CUSTOM_CXX} ]; then
102                         COMPILER=${CUSTOM_CXX}
103                         INCOPT=`eval echo \$\{${CCVER}_INCOPT\}`
104                         INCOPTCXX=`eval echo \$\{${CCVER}_INCOPTCXX\}`
105                 else
106                         echo "${CCVER}_CXX undefined, see compilers.conf(5)"
107                         exit 1
108                 fi
109                 ;;
110         cpp)
111                 CUSTOM_CPP=`eval echo \$\{${CCVER}_CPP\}`
112                 if [ -n ${CUSTOM_CPP} ]; then
113                         COMPILER=${CUSTOM_CPP}
114                         INCOPT=`eval echo \$\{${CCVER}_INCOPT\}`
115                 else
116                         echo "${CCVER}_CPP undefined, see compilers.conf(5)"
117                         exit 1
118                 fi
119                 ;;
120         clang-cpp)
121                 CUSTOM_CLANGCPP=`eval echo \$\{${CCVER}_CLANGCPP\}`
122                 if [ -n  "${CUSTOM_CLANGCPP}" ]; then
123                         COMPILER=${CUSTOM_CLANGCPP}
124                         INCOPT=`eval echo \$\{${CCVER}_INCOPT\}`
125                 else
126                         COMPILER=/usr/libexec/clangbase/clang-cpp
127                         INCOPT=${CLANG_INCOPT}
128                 fi
129                 ;;
130         gcov)
131                 CUSTOM_GCOV=`eval echo \$\{${CCVER}_GCOV\}`
132                 if [ -n  "${CUSTOM_GCOV}" ]; then
133                         exec ${CUSTOM_GCOV} "$@"
134                 else
135                         exec /usr/libexec/gcc47/gcov "$@"
136                 fi
137                 ;;
138         *)
139                 echo "customcc: unrecognized command '${CNAME}'"
140                 exit 1
141                 ;;
142 esac
143
144 case ${CNAME} in
145         gcc|clang|cc)
146                 CUSTOM_CFLAGS=`eval echo \$\{${CCVER}_CFLAGS\}`
147                 exec ${COMPILER} ${INCOPT} ${CUSTOM_CFLAGS} "$@"
148                 ;;
149         g++|clang++|c++|CC)
150                 CUSTOM_CXXFLAGS=`eval echo \$\{${CCVER}_CXXFLAGS\}`
151                 exec ${COMPILER} ${INCOPT} ${INCOPTCXX} ${CUSTOM_CFLAGS} "$@"
152                 ;;
153         cpp|clang-cpp)
154                 CUSTOM_CPPFLAGS=`eval echo \$\{${CCVER}_CPPFLAGS\}`
155                 exec ${COMPILER} ${INCOPT} ${CUSTOM_CPPFLAGS} "$@"
156                 ;;
157 esac