| 1 |
#! /bin/sh |
| 2 |
# |
| 3 |
# Evaluate C++ compiler implementation, to determine which kludges the |
| 4 |
# Blitz++ library should use. |
| 5 |
# |
| 6 |
# With thanks to Tom Keffer (Rogue Wave Software) and Larry Wall |
| 7 |
# |
| 8 |
# $Id$ |
| 9 |
|
| 10 |
# If you need to debug this script, try uncommenting the |
| 11 |
# next line |
| 12 |
# set -x |
| 13 |
|
| 14 |
# Alternately, try setting verbose=1 on the next line |
| 15 |
verbose=0 |
| 16 |
|
| 17 |
# If your platform generates .OBJ instead of .o files, you'll need |
| 18 |
# to edit the next line |
| 19 |
objextension='o' |
| 20 |
|
| 21 |
if test ! -t 0; then |
| 22 |
echo "Use 'sh bzconfig', not 'sh < bzconfig'" |
| 23 |
exit 1 |
| 24 |
fi |
| 25 |
|
| 26 |
# clean="rm -f a.out core bztemp bztest bzjunk.cpp bzjunk.o bzjunk.ii bzjunk.int.c bzjunk.s" |
| 27 |
clean="rm -f core" |
| 28 |
trap '$clean; exit 1' 1 2 3 15 |
| 29 |
|
| 30 |
# Information about the system: |
| 31 |
link='ln -s' |
| 32 |
|
| 33 |
# Information about invoking the compiler |
| 34 |
cppinvoke='' |
| 35 |
extension='cpp' |
| 36 |
special='' |
| 37 |
srcdir='.' |
| 38 |
install=0 |
| 39 |
interactive=1 |
| 40 |
|
| 41 |
# Don't bother using symbolic links, just copy |
| 42 |
|
| 43 |
# Does the system support symbolic links? |
| 44 |
# echo "foo" >test.1 |
| 45 |
# ln -s test.1 test.2 >>bztemp 2>&1 |
| 46 |
# if grep foo test.2 >>bztemp 2>&1; then |
| 47 |
# copy='ln -s' |
| 48 |
# else |
| 49 |
# copy='cp' |
| 50 |
# fi |
| 51 |
# rm -f test.1 test.2 |
| 52 |
copy='cp' |
| 53 |
|
| 54 |
# Determine if we're running in interactive mode, or if the |
| 55 |
# arguments were passed on the command line |
| 56 |
|
| 57 |
ac_prev= |
| 58 |
for ac_option |
| 59 |
do |
| 60 |
case "$ac_option" in |
| 61 |
-*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;; |
| 62 |
*) ac_optarg= ;; |
| 63 |
esac |
| 64 |
|
| 65 |
case "$ac_option" in |
| 66 |
--compiler=*) |
| 67 |
cppinvoke="$ac_optarg" |
| 68 |
interactive=0 ;; |
| 69 |
--flags=*) |
| 70 |
special="$ac_optarg" ;; |
| 71 |
--srcdir=*) |
| 72 |
srcdir="$ac_optarg" ;; |
| 73 |
--extension=*) |
| 74 |
extension="$ac_optarg" ;; |
| 75 |
--install) |
| 76 |
install=1 ;; |
| 77 |
--help) |
| 78 |
cat << EOF |
| 79 |
Usage: bzconfig [options] |
| 80 |
Options: |
| 81 |
--compiler=PROGRAM Compiler invokation (cc, KCC, g++, vacbld, etc.) |
| 82 |
You will be prompted if this option is missing. |
| 83 |
--flags=FLAGS Flags for the compiler. Multiple flags can be |
| 84 |
indicated using quotes, e.g. --flags="-x -g" |
| 85 |
--extension=EXT Extension for C++ programs (cpp, C, cxx) |
| 86 |
Defaults to cpp |
| 87 |
--install Automatically install the resulting config.h |
| 88 |
file to ../blitz/config.h (default is not to) |
| 89 |
EOF |
| 90 |
exit 0;; |
| 91 |
-*) { echo "bzconfig: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; } |
| 92 |
;; |
| 93 |
esac |
| 94 |
done |
| 95 |
|
| 96 |
cat << 'EOH' |
| 97 |
|
| 98 |
Blitz++ compiler evaluation |
| 99 |
|
| 100 |
This script will test your compiler to determine which language |
| 101 |
features it supports. |
| 102 |
|
| 103 |
EOH |
| 104 |
|
| 105 |
if test $interactive -eq 1; then |
| 106 |
|
| 107 |
echo "Running in interactive mode (the --compiler option was not specified)" |
| 108 |
|
| 109 |
echo "What is the command to invoke your C++ compiler? " |
| 110 |
read cppinvoke |
| 111 |
|
| 112 |
echo " " |
| 113 |
echo "Suggested flags:" |
| 114 |
echo "KCC: -x --restrict" |
| 115 |
echo "KCC under Linux: -x --restrict -D__signed__=" |
| 116 |
echo "SGi: -n32 -experimental" |
| 117 |
echo " " |
| 118 |
echo "* If your compiler does not recognize the new ISO C++ keyword" |
| 119 |
echo " \"typename,\" you should compile with -DBZ_NO_TYPENAME" |
| 120 |
echo "* If your compiler does not implement namespaces, you should" |
| 121 |
echo " compile with -DBZ_NO_NAMESPACES" |
| 122 |
echo "* If your compiler needs special flags for exceptions and RTTI, don't " |
| 123 |
echo " bother -- Blitz++ doesn't use these features, although this suite does " |
| 124 |
echo " test for them." |
| 125 |
echo " " |
| 126 |
echo "Any special compile flags? (ENTER for none) " |
| 127 |
read special |
| 128 |
|
| 129 |
echo " " |
| 130 |
echo "I am assuming your compiler recognizes .cpp extensions. If not," |
| 131 |
echo "start bzconfig again and use the --extension=EXT option." |
| 132 |
fi |
| 133 |
|
| 134 |
|
| 135 |
case "$cppinvoke" in |
| 136 |
vacbld) |
| 137 |
vacbld=1 |
| 138 |
echo Using special setup for vacbld. |
| 139 |
;; |
| 140 |
*) |
| 141 |
vacbld=0 |
| 142 |
;; |
| 143 |
esac |
| 144 |
|
| 145 |
echo " " |
| 146 |
echo "I am now going to try a simple program." |
| 147 |
cat <<'EOP' >bzjunk.$extension |
| 148 |
int main() { return 0; } |
| 149 |
EOP |
| 150 |
|
| 151 |
if test $vacbld -eq 1; then |
| 152 |
echo Checking vacbld... |
| 153 |
rm -f bzjunk |
| 154 |
if vacbld $special $srcdir/vac.icc >>bztemp 2>&1 && |
| 155 |
test -x bzjunk |
| 156 |
then |
| 157 |
echo vacbld ran successfully. |
| 158 |
else |
| 159 |
echo "Hmmm.. I was unable to compile a simple program." |
| 160 |
echo "The command used was:" |
| 161 |
echo "vacbld $special $srcdir/vac.icc" |
| 162 |
$clean |
| 163 |
exit 1 |
| 164 |
fi |
| 165 |
else |
| 166 |
if test $verbose -eq 1; then |
| 167 |
echo $cppinvoke $special -c bzjunk.$extension |
| 168 |
echo test -f bzjunk.$objextension |
| 169 |
fi |
| 170 |
|
| 171 |
if $cppinvoke $special -c bzjunk.$extension && # >>bztemp 2>&1 && |
| 172 |
test -f bzjunk.$objextension |
| 173 |
then |
| 174 |
echo "Okay, it compiled. But will it link?" |
| 175 |
else |
| 176 |
echo "Hmmm.. I was unable to compile a simple program." |
| 177 |
echo "The command line I used was:" |
| 178 |
echo "$cppinvoke $special -c bzjunk.$extension" |
| 179 |
echo "If your platform uses .OBJ instead of .o files, you'll need" |
| 180 |
echo "to edit the bzconfig script and set objextension correctly." |
| 181 |
$clean |
| 182 |
exit 1 |
| 183 |
fi |
| 184 |
|
| 185 |
if test $verbose -eq 1; then |
| 186 |
echo $cppinvoke $special bzjunk.$objextension -o bzjunk |
| 187 |
echo test -x bzjunk |
| 188 |
echo sh -c ./bzjunk |
| 189 |
fi |
| 190 |
|
| 191 |
if $cppinvoke $special bzjunk.$objextension -o bzjunk -lm >>bztemp 2>&1 && |
| 192 |
sh -c ./bzjunk >>bztemp 2>&1 |
| 193 |
then |
| 194 |
echo "Yes, it linked too. Great." |
| 195 |
echo " " |
| 196 |
rm -f bzjunk.$extension bzjunk.o bzjunk |
| 197 |
else |
| 198 |
echo "No, I could compile, but couldn't link (or couldn't execute" |
| 199 |
echo "the resulting file." |
| 200 |
echo "The command line I used was:" |
| 201 |
echo "$cppinvoke $special bzjunk.$objextension -o bzjunk -lm" |
| 202 |
$clean |
| 203 |
exit 1 |
| 204 |
fi |
| 205 |
fi |
| 206 |
|
| 207 |
######################################################################## |
| 208 |
|
| 209 |
echo " " |
| 210 |
echo "Okay, now the fun begins." |
| 211 |
echo " " |
| 212 |
|
| 213 |
rm -f config.h logfile |
| 214 |
cat << 'EOH' >config.h |
| 215 |
/****************************************************************************** |
| 216 |
* config.h Compiler language support flags |
| 217 |
* |
| 218 |
* This file was generated automatically by the script bzconfig. |
| 219 |
* You should rerun bzconfig each time you switch compilers, install new |
| 220 |
* standard libraries, or change compiler versions. |
| 221 |
* |
| 222 |
*/ |
| 223 |
|
| 224 |
EOH |
| 225 |
|
| 226 |
echo " " >>config.h |
| 227 |
echo "#ifndef BZ_CONFIG_H" >>config.h |
| 228 |
echo "#define BZ_CONFIG_H" >>config.h |
| 229 |
echo " " >>config.h |
| 230 |
echo "#define BZ_COMPILER_NAME \"$cppinvoke\"" >>config.h |
| 231 |
echo "#define BZ_COMPILER_OPTIONS \"$special\"" >>config.h |
| 232 |
echo "#define BZ_OS_NAME \"`uname -s -r`\"" >>config.h |
| 233 |
echo "#define BZ_BZCONFIG_DATE \"`date`\"" >>config.h |
| 234 |
echo "#define BZ_PLATFORM \"`$srcdir/../config.guess`\"" >>config.h |
| 235 |
echo " " >>config.h |
| 236 |
|
| 237 |
# Set up a little script to make this easier |
| 238 |
echo \#\!/bin/sh > bztest |
| 239 |
echo cppinvoke=\"$cppinvoke\" >> bztest |
| 240 |
echo special=\"$special\" >> bztest |
| 241 |
echo copy=\"$copy\" >> bztest |
| 242 |
echo extension=\"$extension\" >> bztest |
| 243 |
echo verbose=\"$verbose\" >> bztest |
| 244 |
echo srcdir=\"$srcdir\" >> bztest |
| 245 |
cat << 'EOSC' >>bztest |
| 246 |
# set -x |
| 247 |
echo " " |
| 248 |
echo $3 |
| 249 |
echo " " >>logfile |
| 250 |
echo " " >>logfile |
| 251 |
echo " " >>logfile |
| 252 |
echo $3 >>logfile |
| 253 |
echo $cppinvoke $special $srcdir/$2 >>logfile |
| 254 |
|
| 255 |
rm -f bzjunk bzjunk.$extension bzjunk.o |
| 256 |
if test $verbose -eq 1; then echo $copy $srcdir/$2 bzjunk.$extension; fi |
| 257 |
|
| 258 |
$copy $srcdir/$2 bzjunk.$extension |
| 259 |
|
| 260 |
if test $verbose -eq 1; then |
| 261 |
echo $cppinvoke $special bzjunk.$extension -o bzjunk |
| 262 |
fi |
| 263 |
|
| 264 |
case $cppinvoke in |
| 265 |
vacbld) |
| 266 |
build="vacbld $special vac.icc" |
| 267 |
;; |
| 268 |
*) |
| 269 |
build="$cppinvoke $special bzjunk.$extension -o bzjunk -lm" |
| 270 |
;; |
| 271 |
esac |
| 272 |
|
| 273 |
if $build >>logfile 2>&1 && |
| 274 |
test -x bzjunk && |
| 275 |
sh -c ./bzjunk >>bztemp 2>&1 |
| 276 |
then |
| 277 |
echo "Yes." |
| 278 |
echo "#define $1" >>config.h |
| 279 |
echo "Success: $1" >>logfile |
| 280 |
else |
| 281 |
echo "Nope." |
| 282 |
echo "#undef $1" >>config.h |
| 283 |
echo "Failed: $1" >>logfile |
| 284 |
fi |
| 285 |
EOSC |
| 286 |
chmod +x bztest |
| 287 |
|
| 288 |
# Major language features |
| 289 |
./bztest BZ_NAMESPACES namespac.cpp "Does your compiler implement namespaces?" |
| 290 |
./bztest BZ_EXCEPTIONS except.cpp "What about exceptions?" |
| 291 |
./bztest BZ_RTTI rtti.cpp "Run-Time Type Identification?" |
| 292 |
./bztest BZ_MEMBER_CONSTANTS membcnst.cpp "Member constants?" |
| 293 |
./bztest BZ_OLD_FOR_SCOPING oldfor.cpp "Does your compiler cling to the old 'for' scoping rules?" |
| 294 |
|
| 295 |
# New keywords |
| 296 |
echo " " |
| 297 |
echo "Now for some of the new keywords." |
| 298 |
./bztest BZ_EXPLICIT explicit.cpp "How about the 'explicit' keyword?" |
| 299 |
./bztest BZ_MUTABLE mutable.cpp "What about the 'mutable' keyword?" |
| 300 |
./bztest BZ_TYPENAME typename.cpp "Does your compiler recognize 'typename'?" |
| 301 |
./bztest BZ_NCEG_RESTRICT restrict.cpp "Just on the off chance... the NCEG 'restrict' keyword?" |
| 302 |
./bztest BZ_NCEG_RESTRICT_EGCS restric2.cpp "Maybe it recognizes __restrict__?" |
| 303 |
./bztest BZ_BOOL bool.cpp "Does it recognize bool as a built-in type?" |
| 304 |
|
| 305 |
# Typecasting |
| 306 |
echo " " |
| 307 |
echo "Does your compiler understand the newfangled casting syntax?" |
| 308 |
./bztest BZ_CONST_CAST constcst.cpp "What about const_cast<>?" |
| 309 |
./bztest BZ_STATIC_CAST statcast.cpp "static_cast<>?" |
| 310 |
./bztest BZ_REINTERPRET_CAST reinterp.cpp "reinterpret_cast<>?" |
| 311 |
./bztest BZ_DYNAMIC_CAST dynamic.cpp "dynamic_cast<>?" |
| 312 |
|
| 313 |
# Templates (most important) |
| 314 |
echo " " |
| 315 |
echo "Okay, now the important stuff -- templates." |
| 316 |
|
| 317 |
./bztest BZ_TEMPLATES template.cpp "Will it handle basic templates? (If not, just give up now.)" |
| 318 |
./bztest BZ_PARTIAL_SPECIALIZATION partial.cpp "Partial specialization?" |
| 319 |
./bztest BZ_PARTIAL_ORDERING porder.cpp "Partial ordering?" |
| 320 |
./bztest BZ_DEFAULT_TEMPLATE_PARAMETERS default.cpp "Default template parameters?" |
| 321 |
./bztest BZ_MEMBER_TEMPLATES membtmpl.cpp "Member templates?" |
| 322 |
./bztest BZ_MEMBER_TEMPLATES_OUTSIDE_CLASS membtmp2.cpp "Member templates outside the class declaration?" |
| 323 |
./bztest BZ_FULL_SPECIALIZATION_SYNTAX fullspec.cpp "Does it recognize the full specialization syntax?" |
| 324 |
./bztest BZ_FUNCTION_NONTYPE_PARAMETERS nontype.cpp "Function templates with non-type parameters?" |
| 325 |
./bztest BZ_TEMPLATE_QUALIFIED_BASE_CLASS elabbase.cpp "Template-qualified base class specifiers?" |
| 326 |
./bztest BZ_TEMPLATE_QUALIFIED_RETURN_TYPE elabret.cpp "Template-qualified return types (necessary for vector type promotion)?" |
| 327 |
./bztest BZ_EXPLICIT_TEMPLATE_FUNCTION_QUALIFICATION tempqual.cpp "Explicit template function qualification?" |
| 328 |
./bztest BZ_TEMPLATES_AS_TEMPLATE_ARGUMENTS temptemp.cpp "Templates as template arguments?" |
| 329 |
./bztest BZ_TEMPLATE_KEYWORD_QUALIFIER tempkey.cpp "Use of the template keyword as a qualifier?" |
| 330 |
./bztest BZ_TEMPLATE_SCOPED_ARGUMENT_MATCHING tempqmt.cpp "Function matching with argument types which are template scope-qualified?" |
| 331 |
./bztest BZ_TYPE_PROMOTION promote.cpp "Will it support the vector type promotion mechanism?" |
| 332 |
./bztest BZ_USE_NUMTRAIT numtrait.cpp "Numeric traits promotions (sum type, etc.)?" |
| 333 |
./bztest BZ_ENUM_COMPUTATIONS enumcomp.cpp "Can your compiler handle computations inside an enum?" |
| 334 |
./bztest BZ_ENUM_COMPUTATIONS_WITH_CAST enumcmp2.cpp "Does it handle (int) casts in enum computations?" |
| 335 |
|
| 336 |
# Standard library |
| 337 |
echo " " |
| 338 |
echo "Which library features does your compiler provide?" |
| 339 |
./bztest BZ_HAVE_COMPLEX complex.cpp "Does it have complex<T>?" |
| 340 |
./bztest BZ_HAVE_NUMERIC_LIMITS numlimit.cpp "Does it have numeric_limits<T>?" |
| 341 |
./bztest BZ_HAVE_CLIMITS climits.cpp "Does it have <climits>?" |
| 342 |
./bztest BZ_HAVE_VALARRAY valarray.cpp "Does it have valarray<T>?" |
| 343 |
./bztest BZ_HAVE_COMPLEX_MATH compmath.cpp "Complex math functions?" |
| 344 |
./bztest BZ_HAVE_IEEE_MATH ieeemath.cpp "IEEE Math library?" |
| 345 |
./bztest BZ_HAVE_SYSTEM_V_MATH sysvmath.cpp "System V Math library?" |
| 346 |
./bztest BZ_MATH_FN_IN_NAMESPACE_STD mathscop.cpp "Are C math functions in <cmath> and std::?" |
| 347 |
./bztest BZ_COMPLEX_MATH_IN_NAMESPACE_STD cmthscop.cpp "Are complex math functions in std::?" |
| 348 |
./bztest BZ_HAVE_STD std.cpp "ISO C++ Standard library?" |
| 349 |
./bztest BZ_HAVE_STL stl.cpp "Standard template library?" |
| 350 |
./bztest BZ_HAVE_RUSAGE getruse.cpp "What about getrusage()?" |
| 351 |
# Clean up |
| 352 |
$clean |
| 353 |
|
| 354 |
echo " " >>config.h |
| 355 |
echo "#endif // BZ_CONFIG_H" >>config.h |
| 356 |
|
| 357 |
echo " " |
| 358 |
echo The results have been written to the file config.h. |
| 359 |
|
| 360 |
if test $interactive -eq 1; then |
| 361 |
|
| 362 |
echo You should now copy this file to the location of the Blitz++ header |
| 363 |
echo files, overwriting the current version of "<blitz/config.h>". |
| 364 |
echo " " |
| 365 |
echo If you have installed this library in the usual fashion, the command |
| 366 |
echo you should run is: |
| 367 |
echo " " |
| 368 |
echo cp config.h ../blitz |
| 369 |
echo " " |
| 370 |
|
| 371 |
fi |
| 372 |
|
| 373 |
echo If you\'re curious about which tests passed and failed and why, see |
| 374 |
echo this file: |
| 375 |
ls -l logfile |
| 376 |
|
| 377 |
|