Enable extra gcc warning categories
[openmx:openmx.git] / configure
1 #!/bin/sh
2
3 set -o errexit
4 set -o nounset
5
6 isdef() {
7     tmp1=/tmp/openmx.$$.cpp
8     tmp2=/tmp/openmx.$$.out
9     trap 'rm -f $tmp1 $tmp2' EXIT
10     cat >$tmp1 <<EOF
11 int main()
12 {
13 #ifndef $1
14 crash me
15 #endif
16         ; return 0;
17 }
18 EOF
19     $CXX -c $tmp1 -o $tmp2 > /dev/null 2>&1
20 }
21
22 : ${R_HOME:=`R RHOME`}
23 if test -z "${R_HOME}"; then 
24    echo "could not determine R_HOME" 
25    exit 1 
26 fi 
27
28 REXEC=${R_HOME}/bin/R
29
30 CXX=$($REXEC CMD config CXX)
31
32 COMPILER_CXXFLAGS=
33 COMPILER_LDFLAGS=
34 arch_CXXFLAGS=
35 arch_LDFLAGS=
36 OPENMP_CXXFLAGS=
37 OPENMP_LDFLAGS=
38
39 if isdef __clang__; then
40     cxx_type=clang
41 elif isdef __llvm__; then
42     cxx_type=llvm
43 elif isdef __GNUC__; then
44     cxx_type=gcc
45 else
46     echo "Compiler unrecognized:"
47     $CXX --version
48     exit 1
49 fi
50
51 if [ "$cxx_type" = gcc ]; then
52     COMPILER_CXXFLAGS="-Wall -Wextra -Wno-unknown-pragmas -Wno-unused-parameter"
53     OPENMP_CXXFLAGS="-fopenmp"
54     OPENMP_LDFLAGS="-fopenmp"
55 fi
56
57 cxx_version=$($CXX -dumpversion | awk -F '.' '{print $1 "." $2}')
58
59 host_cpu=$(uname -p)
60 case "$host_cpu" in
61     *86_64) omx_arch=x86_64 ;;
62     *86) omx_arch=x86 ;;
63     *)
64         echo "Host arch is not recognized: ${host_cpu}"
65         exit 1
66         ;;
67 esac
68
69 npsol_dir='inst/npsol'
70
71 os=$(uname -s)
72 case "$os" in
73     *Linux)
74         omx_os=linux
75         npsol_library="${npsol_dir}/linux/${omx_arch}/gcc${cxx_version}"
76         ;;
77     *Darwin)
78         omx_os=osx
79         arch_LDFLAGS="-mmacosx-version-min=10.4"
80         arch_CXXFLAGS="-mmacosx-version-min=10.4"
81         npsol_library="${npsol_dir}/osx"
82         ;;
83     *)
84         echo "Host os is not recognized: $os"
85         exit 1
86         ;;
87 esac
88
89 echo "### Generated $(date)" > src/Makevars
90 echo >> src/Makevars
91
92 if [ ! -e inst/no-npsol ]; then
93     npsol_file="${npsol_library}/libnpsol.a"
94     if [ ! -f "$npsol_file" ]; then
95         echo "$npsol_file not found"
96         exit 1
97     else
98         echo "NPSOL_LDFLAGS=-L../${npsol_library} -lnpsol" >> src/Makevars
99     fi
100 fi
101
102 echo "ARCH_SPECIFIC_LINKER_FLAGS=$arch_LDFLAGS" >> src/Makevars
103 echo "ARCH_SPECIFIC_COMPILER_FLAGS=$arch_CXXFLAGS" >> src/Makevars
104 echo "COMPILER_CXXFLAGS=$COMPILER_CXXFLAGS" >> src/Makevars
105 echo "COMPILER_LDFLAGS=$COMPILER_LDFLAGS" >> src/Makevars
106 echo "OPENMP_CXXFLAGS=$OPENMP_CXXFLAGS" >> src/Makevars
107 echo "OPENMP_LDFLAGS=$OPENMP_LDFLAGS" >> src/Makevars
108 echo >> src/Makevars
109 echo "# ---- appending Makevars.in ----" >> src/Makevars
110 echo >> src/Makevars
111 cat src/Makevars.in >> src/Makevars