xref: /unit/auto/cc/test (revision 0:a63ceefd6ab0)
1*0Sigor@sysoev.ru
2*0Sigor@sysoev.ru# Copyright (C) Igor Sysoev
3*0Sigor@sysoev.ru# Copyright (C) NGINX, Inc.
4*0Sigor@sysoev.ru
5*0Sigor@sysoev.ru
6*0Sigor@sysoev.ru$echo checking for C compiler: $CC
7*0Sigor@sysoev.rucat << END >> $NXT_AUTOCONF_ERR
8*0Sigor@sysoev.ru----------------------------------------
9*0Sigor@sysoev.ruchecking for C compiler: $CC
10*0Sigor@sysoev.ruEND
11*0Sigor@sysoev.ru
12*0Sigor@sysoev.ru
13*0Sigor@sysoev.ru# Allow error exit status.
14*0Sigor@sysoev.ruset +e
15*0Sigor@sysoev.ru
16*0Sigor@sysoev.ruif [ -z `which $CC` ]; then
17*0Sigor@sysoev.ru    $echo
18*0Sigor@sysoev.ru    $echo $0: error: $CC not found.
19*0Sigor@sysoev.ru    $echo
20*0Sigor@sysoev.ru    exit 1;
21*0Sigor@sysoev.rufi
22*0Sigor@sysoev.ru
23*0Sigor@sysoev.ru
24*0Sigor@sysoev.ruif `/bin/sh -c "($CC -v)" 2>&1 | grep "gcc version" >> $NXT_AUTOCONF_ERR 2>&1`
25*0Sigor@sysoev.ruthen
26*0Sigor@sysoev.ru    NXT_CC_NAME=gcc
27*0Sigor@sysoev.ru    $echo " + using GNU C compiler"
28*0Sigor@sysoev.ru    NXT_CC_VERSION=`/bin/sh -c "($CC -v)" 2>&1 | grep "gcc version" 2>&1`
29*0Sigor@sysoev.ru    $echo " + $NXT_CC_VERSION"
30*0Sigor@sysoev.ru
31*0Sigor@sysoev.ruelse
32*0Sigor@sysoev.ruif `/bin/sh -c "($CC -v)" 2>&1 | grep "clang version" >> $NXT_AUTOCONF_ERR 2>&1`
33*0Sigor@sysoev.ruthen
34*0Sigor@sysoev.ru    NXT_CC_NAME=clang
35*0Sigor@sysoev.ru    $echo " + using Clang C compiler"
36*0Sigor@sysoev.ru    NXT_CC_VERSION=`/bin/sh -c "($CC -v)" 2>&1 | grep "clang version" 2>&1`
37*0Sigor@sysoev.ru    $echo " + $NXT_CC_VERSION"
38*0Sigor@sysoev.ru
39*0Sigor@sysoev.ruelse
40*0Sigor@sysoev.ruif `/bin/sh -c "($CC -v)" 2>&1 \
41*0Sigor@sysoev.ru                 | grep "Apple LLVM version" >> $NXT_AUTOCONF_ERR 2>&1`
42*0Sigor@sysoev.ruthen
43*0Sigor@sysoev.ru    NXT_CC_NAME=clang
44*0Sigor@sysoev.ru    $echo " + using Clang C compiler"
45*0Sigor@sysoev.ru    NXT_CC_VERSION=`/bin/sh -c "($CC -v)" 2>&1 | grep "Apple LLVM version" 2>&1`
46*0Sigor@sysoev.ru    $echo " + $NXT_CC_VERSION"
47*0Sigor@sysoev.ru
48*0Sigor@sysoev.ruelse
49*0Sigor@sysoev.ruif `/bin/sh -c "($CC -V)" 2>&1 | grep "Sun C" >> $NXT_AUTOCONF_ERR 2>&1`
50*0Sigor@sysoev.ruthen
51*0Sigor@sysoev.ru    NXT_CC_NAME=SunC
52*0Sigor@sysoev.ru    $echo " + using Sun C compiler"
53*0Sigor@sysoev.ru    NXT_CC_VERSION=`/bin/sh -c "($CC -V)" 2>&1 | grep "Sun C" 2>&1`
54*0Sigor@sysoev.ru    $echo " + $NXT_CC_VERSION"
55*0Sigor@sysoev.ru
56*0Sigor@sysoev.ruelse
57*0Sigor@sysoev.ruif `/bin/sh -c "($CC -qversion)" 2>&1 \
58*0Sigor@sysoev.ru                | grep "^IBM XL" >> $NXT_AUTOCONF_ERR 2>&1`
59*0Sigor@sysoev.ruthen
60*0Sigor@sysoev.ru    NXT_CC_NAME=xlC
61*0Sigor@sysoev.ru    $echo " + using AIX xlC compiler"
62*0Sigor@sysoev.ru    NXT_CC_VERSION=`/bin/sh -c "($CC -qversion)" 2>&1 | grep "IBM XL" 2>&1`
63*0Sigor@sysoev.ru    $echo " + $NXT_CC_VERSION"
64*0Sigor@sysoev.ru
65*0Sigor@sysoev.ruelse
66*0Sigor@sysoev.ruif `/bin/sh -c "($CC -V)" 2>&1 | grep "Intel(R) C" >> $NXT_AUTOCONF_ERR 2>&1`
67*0Sigor@sysoev.ruthen
68*0Sigor@sysoev.ru    NXT_CC_NAME=ICC
69*0Sigor@sysoev.ru    $echo " + using Intel C++ compiler"
70*0Sigor@sysoev.ru    NXT_CC_VERSION=ICC
71*0Sigor@sysoev.ru
72*0Sigor@sysoev.ruelse
73*0Sigor@sysoev.ruif `/bin/sh -c "($CC -v)" 2>&1 \
74*0Sigor@sysoev.ru                | grep "Microsoft (R) 32-bit C/C" >> $NXT_AUTOCONF_ERR 2>&1`
75*0Sigor@sysoev.ruthen
76*0Sigor@sysoev.ru    NXT_CC_NAME=MSVC
77*0Sigor@sysoev.ru    $echo " + using MS Visual C++ compiler"
78*0Sigor@sysoev.ru    NXT_CC_VERSION=MSVC
79*0Sigor@sysoev.ru
80*0Sigor@sysoev.ruelse
81*0Sigor@sysoev.ru    NXT_CC_NAME=cc
82*0Sigor@sysoev.ru    NXT_CC_VERSION=cc
83*0Sigor@sysoev.ru
84*0Sigor@sysoev.rufi # MSVC
85*0Sigor@sysoev.rufi # ICC
86*0Sigor@sysoev.rufi # xlC
87*0Sigor@sysoev.rufi # SunC
88*0Sigor@sysoev.rufi # Apple LLVM clang
89*0Sigor@sysoev.rufi # clang
90*0Sigor@sysoev.rufi # gcc
91*0Sigor@sysoev.ru
92*0Sigor@sysoev.ru
93*0Sigor@sysoev.rucase $NXT_CC_NAME in
94*0Sigor@sysoev.ru
95*0Sigor@sysoev.ru    gcc)
96*0Sigor@sysoev.ru        nxt_have=NXT_GCC . auto/have
97*0Sigor@sysoev.ru
98*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -pipe"
99*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -fPIC"
100*0Sigor@sysoev.ru
101*0Sigor@sysoev.ru        # Do not export symbols except explicitly marked with NXT_EXPORT.
102*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -fvisibility=hidden"
103*0Sigor@sysoev.ru
104*0Sigor@sysoev.ru        # c99/gnu99 conflict with Solaris XOPEN.
105*0Sigor@sysoev.ru        #NXT_CFLAGS="$NXT_CFLAGS -std=gnu99"
106*0Sigor@sysoev.ru
107*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -O"
108*0Sigor@sysoev.ru        #NXT_CFLAGS="$NXT_CFLAGS -O0"
109*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -W -Wall -Wextra"
110*0Sigor@sysoev.ru
111*0Sigor@sysoev.ru        #NXT_CFLAGS="$NXT_CFLAGS -Wunused-result"
112*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -Wno-unused-parameter"
113*0Sigor@sysoev.ru        #NXT_CFLAGS="$NXT_CFLAGS -Wshorten-64-to-32"
114*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -Wwrite-strings"
115*0Sigor@sysoev.ru
116*0Sigor@sysoev.ru        # -O2 enables -fstrict-aliasing and -fstrict-overflow.
117*0Sigor@sysoev.ru        #NXT_CFLAGS="$NXT_CFLAGS -O2"
118*0Sigor@sysoev.ru        #NXT_CFLAGS="$NXT_CFLAGS -Wno-strict-aliasing"
119*0Sigor@sysoev.ru
120*0Sigor@sysoev.ru        #NXT_CFLAGS="$NXT_CFLAGS -fomit-frame-pointer"
121*0Sigor@sysoev.ru        #NXT_CFLAGS="$NXT_CFLAGS -momit-leaf-frame-pointer"
122*0Sigor@sysoev.ru
123*0Sigor@sysoev.ru        # -Wstrict-overflow is supported by GCC 4.2+.
124*0Sigor@sysoev.ru        #NXT_CFLAGS="$NXT_CFLAGS -Wstrict-overflow=5"
125*0Sigor@sysoev.ru
126*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -Wmissing-prototypes"
127*0Sigor@sysoev.ru
128*0Sigor@sysoev.ru        # Stop on warning.
129*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -Werror"
130*0Sigor@sysoev.ru
131*0Sigor@sysoev.ru        # Debug.
132*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -g"
133*0Sigor@sysoev.ru    ;;
134*0Sigor@sysoev.ru
135*0Sigor@sysoev.ru    clang)
136*0Sigor@sysoev.ru        nxt_have=NXT_CLANG . auto/have
137*0Sigor@sysoev.ru
138*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -pipe"
139*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -fPIC"
140*0Sigor@sysoev.ru
141*0Sigor@sysoev.ru        # Do not export symbols except explicitly marked with NXT_EXPORT.
142*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -fvisibility=hidden"
143*0Sigor@sysoev.ru
144*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -O"
145*0Sigor@sysoev.ru        #NXT_CFLAGS="$NXT_CFLAGS -O0"
146*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -W -Wall -Wextra"
147*0Sigor@sysoev.ru
148*0Sigor@sysoev.ru        #NXT_CFLAGS="$NXT_CFLAGS -Wunused-result"
149*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -Wno-unused-parameter"
150*0Sigor@sysoev.ru        #NXT_CFLAGS="$NXT_CFLAGS -Wshorten-64-to-32"
151*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -Wwrite-strings"
152*0Sigor@sysoev.ru        #NXT_CFLAGS="$NXT_CFLAGS -O2"
153*0Sigor@sysoev.ru        #NXT_CFLAGS="$NXT_CFLAGS -fomit-frame-pointer"
154*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -fstrict-aliasing"
155*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -Wstrict-overflow=5"
156*0Sigor@sysoev.ru
157*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -Wmissing-prototypes"
158*0Sigor@sysoev.ru
159*0Sigor@sysoev.ru        # Stop on warning.
160*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -Werror"
161*0Sigor@sysoev.ru
162*0Sigor@sysoev.ru        # Debug.
163*0Sigor@sysoev.ru
164*0Sigor@sysoev.ru        if [ "$NXT_SYSTEM_PLATFORM" != "powerpc" ]; then
165*0Sigor@sysoev.ru            # "-g" flag causes the "unknown pseudo-op: `.cfi_sections'"
166*0Sigor@sysoev.ru            # error on PowerPC Clang.
167*0Sigor@sysoev.ru            NXT_CFLAGS="$NXT_CFLAGS -g"
168*0Sigor@sysoev.ru        fi
169*0Sigor@sysoev.ru    ;;
170*0Sigor@sysoev.ru
171*0Sigor@sysoev.ru    SunC)
172*0Sigor@sysoev.ru        nxt_have=NXT_SUNC . auto/have
173*0Sigor@sysoev.ru
174*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -fPIC"
175*0Sigor@sysoev.ru        # Optimization.
176*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -O -fast"
177*0Sigor@sysoev.ru        # Stop on warning.
178*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -errwarn=%all"
179*0Sigor@sysoev.ru        # Debug.
180*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -g"
181*0Sigor@sysoev.ru    ;;
182*0Sigor@sysoev.ru
183*0Sigor@sysoev.ru    xlC)
184*0Sigor@sysoev.ru        nxt_have=NXT_XLC . auto/have
185*0Sigor@sysoev.ru
186*0Sigor@sysoev.ru        #NXT_CFLAGS="$NXT_CFLAGS -qalloca"
187*0Sigor@sysoev.ru        # alloca support.
188*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -qlanglvl=extc99"
189*0Sigor@sysoev.ru        # __thread support.
190*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -qtls"
191*0Sigor@sysoev.ru        # Suppress warning
192*0Sigor@sysoev.ru        #    1506-159 (E) Bit field type specified for XXX is not valid.
193*0Sigor@sysoev.ru        #    Type unsigned assumed.
194*0Sigor@sysoev.ru        NXT_CFLAGS="$NXT_CFLAGS -qsuppress=1506-159"
195*0Sigor@sysoev.ru    ;;
196*0Sigor@sysoev.ru
197*0Sigor@sysoev.ru    ICC)
198*0Sigor@sysoev.ru    ;;
199*0Sigor@sysoev.ru
200*0Sigor@sysoev.ru    MSVC)
201*0Sigor@sysoev.ru    ;;
202*0Sigor@sysoev.ru
203*0Sigor@sysoev.ru    *)
204*0Sigor@sysoev.ru    ;;
205*0Sigor@sysoev.ru
206*0Sigor@sysoev.ruesac
207*0Sigor@sysoev.ru
208*0Sigor@sysoev.ru# Stop on error exit status again.
209*0Sigor@sysoev.ruset -e
210