customcc: Fix the setup of the /usr/include path to use.
[dragonfly.git] / libexec / customcc / cc.sh
CommitLineData
c97b9141 1#!/bin/sh
c7c26905
SW
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#
c97b9141
SW
33
34CDIR=$(dirname $0)
35CNAME=$(basename $0)
36
1c4f2fa4
SW
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
c97b9141
SW
41#
42if [ "${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++ "$@"
1c4f2fa4
SW
47 elif [ -z $beenhere ]; then
48 export beenhere=1
49 oldargs="$@"
50 export oldargs
61909597
SW
51 INCOPT="-nobuiltininc -nostdinc \
52 -isysroot @@INCPREFIX@@ \
53 -isystem /usr/include \
54 -isystem /usr/libdata/gcc41 \
55 -isystem /usr/include/c++/4.1"
1c4f2fa4
SW
56 elif [ "${CNAME}" = "cc" -o "${CNAME}" = "gcc" ]; then
57 exec ${CDIR}/../gcc41/cc $oldargs
c97b9141 58 fi
b262ad55
SW
59elif [ "${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 \
30be8470 66 -isystem /usr/include/c++/4.4"
b262ad55 67 fi
127a3eb4 68elif [ "${CCVER}" = "gcc46" ]; then
9dce22ab
JM
69 GCC46VER=`gnatc++ -dumpversion`
70 GCC46MAC=`gnatc++ -dumpmachine`
127a3eb4 71 INCOPT="-nostdinc \
c7c26905
SW
72 -iprefix @@INCPREFIX@@ \
73 -iwithprefixbefore /usr/include \
9dce22ab
JM
74 -isystem /usr/pkg/include/c++/${GCC46VER} \
75 -isystem /usr/pkg/include/c++/${GCC46VER}/${GCC46MAC}"
b0eef83f
JM
76elif [ "${CCVER}" = "gcc47" ]; then
77 GCC47VER=`/usr/pkg/gcc-aux/bin/c++ -dumpversion`
78 GCC47MAC=`/usr/pkg/gcc-aux/bin/c++ -dumpmachine`
79 INCOPT="-nostdinc \
c7c26905
SW
80 -iprefix @@INCPREFIX@@ \
81 -iwithprefixbefore /usr/include \
b0eef83f
JM
82 -isystem /usr/pkg/gcc-aux/include/c++/${GCC47VER} \
83 -isystem /usr/pkg/gcc-aux/include/c++/${GCC47VER}/${GCC47MAC}"
c97b9141
SW
84fi
85
86. /etc/defaults/compilers.conf
87[ -f /etc/compilers.conf ] && . /etc/compilers.conf
88
89CUSTOM_CC=`eval echo \$\{${CCVER}_CC\}`
90CUSTOM_CFLAGS=`eval echo \$\{${CCVER}_CFLAGS\}`
91CUSTOM_CXX=`eval echo \$\{${CCVER}_CXX\}`
92CUSTOM_CXXFLAGS=`eval echo \$\{${CCVER}_CXXFLAGS\}`
93CUSTOM_CPP=`eval echo \$\{${CCVER}_CPP\}`
94CUSTOM_CPPFLAGS=`eval echo \$\{${CCVER}_CPPFLAGS\}`
95CUSTOM_VERSION=`eval echo \$\{${CCVER}_VERSION\}`
96
97if [ "${CUSTOM_VERSION}" != "" -a "$1" = "-dumpversion" ]; then
98 echo ${CUSTOM_VERSION}
99elif [ "${CNAME}" = "cc" -o "${CNAME}" = "gcc" ]; then
100 exec ${CUSTOM_CC} ${INCOPT} ${CUSTOM_CFLAGS} "$@"
101elif [ "${CNAME}" = "c++" -o "${CNAME}" = "g++" ]; then
102 exec ${CUSTOM_CXX} ${INCOPT} ${CUSTOM_CXXFLAGS} "$@"
103elif [ "${CNAME}" = "cpp" ]; then
104 exec ${CUSTOM_CPP} ${INCOPT} ${CUSTOM_CPPFLAGS} "$@"
c97b9141 105fi