Ticket #7375: testcxx

File testcxx, 4.0 KB (added by drkirkby, 13 years ago)

Teses the C++ compiler. Not really needed here, but done for completelness.

Line 
1#!/bin/sh
2# Determine the type of C++ compiler, which can later
3# be used to determine the flags the compiler
4# will want. Do this by defining pre-processing a bit
5# of C++ code, and checking what are defined.
6
7# The Sun and GNU compilers have been tested.
8
9# The HP and GNU compilers have not been tested, but
10# use information gained from the documentation.
11
12# HP-UX C and C++ compiler.
13# http://docs.hp.com/en/7730/newhelp0610/preprocess.htm
14
15# IBM Compiler Reference - XL C/C++ for AIX, V10.1
16# http://www-01.ibm.com/support/docview.wss?uid=swg27012860&aid=1
17
18# Using HP C++ for Tru64 UNIX and Linux Alpha
19# http://h30097.www3.hp.com/cplus/ugu_impl.html#implem_chap
20
21
22# First, make sure the enviroment variable CXX is defined.
23
24if [ -z "$CXX" ]; then
25   echo "Sorry, you should define the enivronment variable CXX"
26   exit 1
27fi
28
29# Create a test file. It does not need to be a complete
30# C++ file, as it is only pre-processed. So there is no
31# need for a 'main'
32
33TESTFILE=/tmp/test.$$.cpp
34
35# The flags for the GNU compilers do not change with
36# operating system, so there is no need to worry too
37# much about what system this is on.
38
39
40echo "#ifdef __GNUC__"                   > $TESTFILE
41echo "#ifdef __INTEL_COMPILER"           >> $TESTFILE
42echo "it_is_the_Intel_improved_GCC"      >> $TESTFILE
43echo "#elseif __SUNPRO_CC       "        >> $TESTFILE
44echo "it_is_the_Sun_improved_GCC"        >> $TESTFILE
45echo "#else                  "           >> $TESTFILE
46echo "it_is_the_GNU_compiler"            >> $TESTFILE
47echo "#endif"                            >> $TESTFILE
48echo "#endif"                            >> $TESTFILE
49
50echo "#ifndef __GNUC__"                  >> $TESTFILE
51echo "#ifdef __SUNPRO_CC"                >> $TESTFILE
52echo "it_is_the_Sun_compiler"            >> $TESTFILE
53echo "#endif"                            >> $TESTFILE
54echo "#endif"                            >> $TESTFILE
55
56echo "#ifdef __digital__"                >> $TESTFILE
57echo "#ifdef __DECCXX"                   >> $TESTFILE
58echo "it_is_the_HP_Tru64_compiler"       >> $TESTFILE
59echo "#endif"                            >> $TESTFILE
60echo "#endif"                            >> $TESTFILE
61
62echo "#ifdef __linux__"                  >> $TESTFILE
63echo "#ifdef __DECCXX"                   >> $TESTFILE
64echo "it_is_the_HP_Alpha_Linux_compiler" >> $TESTFILE
65echo "#endif"                            >> $TESTFILE
66echo "#endif"                            >> $TESTFILE
67
68echo "#ifdef __HP_aCC"                   >> $TESTFILE
69echo "it_is_the_HP_HPUX_compiler"        >> $TESTFILE
70echo "#endif"                            >> $TESTFILE
71
72echo "#ifdef __xlC__"                    >> $TESTFILE
73echo "it_is_the_IBM_AIX_compiler"        >> $TESTFILE
74echo "#endif"                            >> $TESTFILE
75
76${CC} -E $TESTFILE | grep it_is_the_Intel_improved_GCC >/dev/null 2>&1
77if [ $? = 0 ]; then
78   echo Intel_improved_GCC
79   rm $TESTFILE
80   exit 0
81fi
82
83${CC} -E $TESTFILE | grep it_is_the_Sun_improved_GCC >/dev/null 2>&1
84if [ $? = 0 ]; then
85   echo Sun_improved_GCC
86   rm $TESTFILE
87   exit 0
88fi
89
90${CXX} -E $TESTFILE | grep it_is_the_GNU_compiler  >/dev/null 2>&1
91if [ $? = 0 ]; then
92   echo GNU
93   rm $TESTFILE
94   exit 0
95fi
96
97${CXX} -E $TESTFILE | grep it_is_the_Sun_compiler  >/dev/null 2>&1
98if [ $? = 0 ]; then
99   echo Sun_on_Solaris
100   rm $TESTFILE
101   exit 0
102fi
103
104# HP make compilers for linux, HP-UX and tru64, which complicates matters.
105
106${CXX} -E $TESTFILE | grep it_is_the_HP_Tru64_compiler >/dev/null 2>&1
107if [ $? = 0 ]; then
108   echo HP_on_Tru64
109   rm $TESTFILE
110   exit 0
111fi
112
113${CXX} -E $TESTFILE | grep it_is_the_HP_Alpha_Linux_compiler >/dev/null 2>&1
114if [ $? = 0 ]; then
115   echo HP_on_Alpha_Linux
116   rm $TESTFILE
117   exit 0
118fi
119
120${CXX} -E $TESTFILE | grep it_is_the_HP_HPUX_compiler >/dev/null 2>&1
121if [ $? = 0 ]; then
122   echo HP_on_HPUX
123   rm $TESTFILE
124   exit 0
125fi
126
127${CXX} -E $TESTFILE | grep it_is_the_IBM_AIX_compiler >/dev/null 2>&1
128if [ $? = 0 ]; then
129   echo IBM_on_AIX
130   rm $TESTFILE
131   exit 0
132fi
133
134# Exit saying 'Unknown' if the type of the compiler could not be found.
135echo Unknown
136rm $TESTFILE
137exit 0
138
139