customcc: Fix the setup of the /usr/include path to use.
[dragonfly.git] / libexec / customcc / cc.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2009-2012
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 CDIR=$(dirname $0)
35 CNAME=$(basename $0)
36
37 # XXX clang needs some special handling
38 #
39 # it is called only for "cc" and "gcc" and even then it could have been
40 # run on c++ files
41 #
42 if [ "${CCVER}" = "clang" ]; then
43         if [ "${CNAME}" = "cpp" ]; then
44                 exec ${CDIR}/../gcc41/cpp "$@"
45         elif [ "${CNAME}" = "c++" -o "${CNAME}" = "g++" ]; then
46                 exec ${CDIR}/../gcc41/c++ "$@"
47         elif [ -z $beenhere ]; then
48                 export beenhere=1
49                 oldargs="$@"
50                 export oldargs
51                 INCOPT="-nobuiltininc -nostdinc \
52                     -isysroot @@INCPREFIX@@ \
53                     -isystem /usr/include \
54                     -isystem /usr/libdata/gcc41 \
55                     -isystem /usr/include/c++/4.1"
56         elif [ "${CNAME}" = "cc" -o "${CNAME}" = "gcc" ]; then
57                 exec ${CDIR}/../gcc41/cc $oldargs
58         fi
59 elif [ "${CCVER}" = "clangsvn" ]; then
60         if [ "${CNAME}" = "cpp" ]; then
61                 exec ${CDIR}/../gcc41/cpp "$@"
62         else
63                 INCOPT="-nobuiltininc -nostdinc \
64                     -isysroot @@INCPREFIX@@ \
65                     -isystem /usr/include \
66                     -isystem /usr/include/c++/4.4"
67         fi
68 elif [ "${CCVER}" = "gcc46" ]; then
69         GCC46VER=`gnatc++ -dumpversion`
70         GCC46MAC=`gnatc++ -dumpmachine`
71         INCOPT="-nostdinc \
72             -iprefix @@INCPREFIX@@ \
73             -iwithprefixbefore /usr/include \
74             -isystem /usr/pkg/include/c++/${GCC46VER} \
75             -isystem /usr/pkg/include/c++/${GCC46VER}/${GCC46MAC}"
76 elif [ "${CCVER}" = "gcc47" ]; then
77         GCC47VER=`/usr/pkg/gcc-aux/bin/c++ -dumpversion`
78         GCC47MAC=`/usr/pkg/gcc-aux/bin/c++ -dumpmachine`
79         INCOPT="-nostdinc \
80             -iprefix @@INCPREFIX@@ \
81             -iwithprefixbefore /usr/include \
82             -isystem /usr/pkg/gcc-aux/include/c++/${GCC47VER} \
83             -isystem /usr/pkg/gcc-aux/include/c++/${GCC47VER}/${GCC47MAC}"
84 fi
85
86 . /etc/defaults/compilers.conf
87 [ -f /etc/compilers.conf ] && . /etc/compilers.conf
88
89 CUSTOM_CC=`eval echo \$\{${CCVER}_CC\}`
90 CUSTOM_CFLAGS=`eval echo \$\{${CCVER}_CFLAGS\}`
91 CUSTOM_CXX=`eval echo \$\{${CCVER}_CXX\}`
92 CUSTOM_CXXFLAGS=`eval echo \$\{${CCVER}_CXXFLAGS\}`
93 CUSTOM_CPP=`eval echo \$\{${CCVER}_CPP\}`
94 CUSTOM_CPPFLAGS=`eval echo \$\{${CCVER}_CPPFLAGS\}`
95 CUSTOM_VERSION=`eval echo \$\{${CCVER}_VERSION\}`
96
97 if [ "${CUSTOM_VERSION}" != "" -a "$1" = "-dumpversion" ]; then
98         echo ${CUSTOM_VERSION}
99 elif [ "${CNAME}" = "cc" -o "${CNAME}" = "gcc" ]; then
100         exec ${CUSTOM_CC} ${INCOPT} ${CUSTOM_CFLAGS} "$@"
101 elif [ "${CNAME}" = "c++" -o "${CNAME}" = "g++" ]; then
102         exec ${CUSTOM_CXX} ${INCOPT} ${CUSTOM_CXXFLAGS} "$@"
103 elif [ "${CNAME}" = "cpp" ]; then
104         exec ${CUSTOM_CPP} ${INCOPT} ${CUSTOM_CPPFLAGS} "$@"
105 fi