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 | |
---|
24 | if [ -z "$CXX" ]; then |
---|
25 | echo "Sorry, you should define the enivronment variable CXX" |
---|
26 | exit 1 |
---|
27 | fi |
---|
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 | |
---|
33 | TESTFILE=/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 | |
---|
40 | echo "#ifdef __GNUC__" > $TESTFILE |
---|
41 | echo "#ifdef __INTEL_COMPILER" >> $TESTFILE |
---|
42 | echo "it_is_the_Intel_improved_GCC" >> $TESTFILE |
---|
43 | echo "#elseif __SUNPRO_CC " >> $TESTFILE |
---|
44 | echo "it_is_the_Sun_improved_GCC" >> $TESTFILE |
---|
45 | echo "#else " >> $TESTFILE |
---|
46 | echo "it_is_the_GNU_compiler" >> $TESTFILE |
---|
47 | echo "#endif" >> $TESTFILE |
---|
48 | echo "#endif" >> $TESTFILE |
---|
49 | |
---|
50 | echo "#ifndef __GNUC__" >> $TESTFILE |
---|
51 | echo "#ifdef __SUNPRO_CC" >> $TESTFILE |
---|
52 | echo "it_is_the_Sun_compiler" >> $TESTFILE |
---|
53 | echo "#endif" >> $TESTFILE |
---|
54 | echo "#endif" >> $TESTFILE |
---|
55 | |
---|
56 | echo "#ifdef __digital__" >> $TESTFILE |
---|
57 | echo "#ifdef __DECCXX" >> $TESTFILE |
---|
58 | echo "it_is_the_HP_Tru64_compiler" >> $TESTFILE |
---|
59 | echo "#endif" >> $TESTFILE |
---|
60 | echo "#endif" >> $TESTFILE |
---|
61 | |
---|
62 | echo "#ifdef __linux__" >> $TESTFILE |
---|
63 | echo "#ifdef __DECCXX" >> $TESTFILE |
---|
64 | echo "it_is_the_HP_Alpha_Linux_compiler" >> $TESTFILE |
---|
65 | echo "#endif" >> $TESTFILE |
---|
66 | echo "#endif" >> $TESTFILE |
---|
67 | |
---|
68 | echo "#ifdef __HP_aCC" >> $TESTFILE |
---|
69 | echo "it_is_the_HP_HPUX_compiler" >> $TESTFILE |
---|
70 | echo "#endif" >> $TESTFILE |
---|
71 | |
---|
72 | echo "#ifdef __xlC__" >> $TESTFILE |
---|
73 | echo "it_is_the_IBM_AIX_compiler" >> $TESTFILE |
---|
74 | echo "#endif" >> $TESTFILE |
---|
75 | |
---|
76 | ${CC} -E $TESTFILE | grep it_is_the_Intel_improved_GCC >/dev/null 2>&1 |
---|
77 | if [ $? = 0 ]; then |
---|
78 | echo Intel_improved_GCC |
---|
79 | rm $TESTFILE |
---|
80 | exit 0 |
---|
81 | fi |
---|
82 | |
---|
83 | ${CC} -E $TESTFILE | grep it_is_the_Sun_improved_GCC >/dev/null 2>&1 |
---|
84 | if [ $? = 0 ]; then |
---|
85 | echo Sun_improved_GCC |
---|
86 | rm $TESTFILE |
---|
87 | exit 0 |
---|
88 | fi |
---|
89 | |
---|
90 | ${CXX} -E $TESTFILE | grep it_is_the_GNU_compiler >/dev/null 2>&1 |
---|
91 | if [ $? = 0 ]; then |
---|
92 | echo GNU |
---|
93 | rm $TESTFILE |
---|
94 | exit 0 |
---|
95 | fi |
---|
96 | |
---|
97 | ${CXX} -E $TESTFILE | grep it_is_the_Sun_compiler >/dev/null 2>&1 |
---|
98 | if [ $? = 0 ]; then |
---|
99 | echo Sun_on_Solaris |
---|
100 | rm $TESTFILE |
---|
101 | exit 0 |
---|
102 | fi |
---|
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 |
---|
107 | if [ $? = 0 ]; then |
---|
108 | echo HP_on_Tru64 |
---|
109 | rm $TESTFILE |
---|
110 | exit 0 |
---|
111 | fi |
---|
112 | |
---|
113 | ${CXX} -E $TESTFILE | grep it_is_the_HP_Alpha_Linux_compiler >/dev/null 2>&1 |
---|
114 | if [ $? = 0 ]; then |
---|
115 | echo HP_on_Alpha_Linux |
---|
116 | rm $TESTFILE |
---|
117 | exit 0 |
---|
118 | fi |
---|
119 | |
---|
120 | ${CXX} -E $TESTFILE | grep it_is_the_HP_HPUX_compiler >/dev/null 2>&1 |
---|
121 | if [ $? = 0 ]; then |
---|
122 | echo HP_on_HPUX |
---|
123 | rm $TESTFILE |
---|
124 | exit 0 |
---|
125 | fi |
---|
126 | |
---|
127 | ${CXX} -E $TESTFILE | grep it_is_the_IBM_AIX_compiler >/dev/null 2>&1 |
---|
128 | if [ $? = 0 ]; then |
---|
129 | echo IBM_on_AIX |
---|
130 | rm $TESTFILE |
---|
131 | exit 0 |
---|
132 | fi |
---|
133 | |
---|
134 | # Exit saying 'Unknown' if the type of the compiler could not be found. |
---|
135 | echo Unknown |
---|
136 | rm $TESTFILE |
---|
137 | exit 0 |
---|
138 | |
---|
139 | |
---|