config 7.35 KB
Newer Older
1 2 3 4 5 6 7
## config -- Simple shell script to get the values of basic R configure
## variables, or the header and library flags necessary for linking
## against R.
##
## Usage:
##   R CMD config [options] [VAR]

8
## Copyright (C) 2002-6 The R Core Development Team
9 10 11 12 13 14 15 16 17 18 19
##
## This document is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
20 21
## A copy of the GNU General Public License is available at
## http://www.r-project.org/Licenses/
22

23
revision='$Revision: 47836 $'
24
version=`set - ${revision}; echo ${2}`
25
version="R configuration information retrieval script: ${R_VERSION} (r${version})
26

27
Copyright (C) 2002-6 The R Core Development Team.
28
This is free software; see the GNU General Public License version 2
29 30 31 32 33 34 35 36 37 38
or later for copying conditions.  There is NO warranty."

usage="Usage: R CMD config [options] [VAR]

Get the value of a basic R configure variable VAR which must be among
those listed in the 'Variables' section below, or the header and
library flags necessary for linking against R.

Options:
  -h, --help            print short help message and exit
39
  -v, --version         print version info and exit
40
      --cppflags        print pre-processor flags required to compile
41
			a program using R as a library
42
      --ldflags         print linker flags needed for linking against
43
			the R library
44 45

Variables:
46
  BLAS_LIBS     flags needed for linking against external BLAS libraries
47 48 49
  CC            C compiler command
  CFLAGS        C compiler flags
  CPICFLAGS     special flags for compiling C code to be turned into a
50
		shared library
51 52
  CPP           C preprocessor
  CPPFLAGS      C/C++ preprocessor flags, e.g. -I<dir> if you have
53
		headers in a nonstandard directory <dir>
54 55 56 57
  CXX           C++ compiler command
  CXXCPP        C++ preprocessor
  CXXFLAGS      C++ compiler flags
  CXXPICFLAGS   special flags for compiling C++ code to be turned into a
58 59
		shared library
  DYLIB_EXT	file extension (including '.') for dynamic libraries
60
  DYLIB_LD      command for linking dynamic libraries which contain
61
		object files from a C or Fortran compiler only
62
  DYLIB_LDFLAGS
63
		special flags used by DYLIB_LD
64 65 66 67
  F77           Fortran 77 compiler command
  FFLAGS        Fortran 77 compiler flags
  FLIBS         linker flags needed to link Fortran code
  FPICFLAGS     special flags for compiling Fortran code to be turned
68
		into a shared library
69 70 71
  FC            Fortran 9x compiler command
  FCFLAGS       Fortran 9x compiler flags
  FCPICFLAGS    special flags for compiling Fortran 9x code to be turned
72
		into a shared library
73 74 75 76 77 78 79
  JAR           Java archive tool command
  JAVA          Java interpreter command
  JAVAC         Java compiler command
  JAVAH         Java header and stub generator command
  JAVA_HOME     path to the home of Java distribution
  JAVA_LIBS     flags needed for linking against Java libraries
  JAVA_CPPFLAGS C preprocessor flags needed for compiling JNI programs
80
  LAPACK_LIBS   flags needed for linking against external LAPACK libraries
81
  LIBnn         location for libraries, e.g. 'lib' or 'lib64' on this platform
82
  LDFLAGS       linker flags, e.g. -L<dir> if you have libraries in a
83
		nonstandard directory <dir>
84 85
  OBJC          Objective C compiler command
  OBJCFLAGS     Objective C compiler flags
86
  MAKE          Make command
87
  SAFE_FFLAGS   Safe (as conformant as possible) Fortran 77 compiler flags
88 89 90
  SHLIB_CFLAGS  additional CFLAGS used when building shared objects
  SHLIB_CXXLD   command for linking shared objects which contain
		object files from a C++ compiler
91
  SHLIB_CXXLDFLAGS
92 93 94 95 96
		special flags used by SHLIB_CXXLD
  SHLIB_EXT	file extension (including '.') for shared objects
  SHLIB_FFLAGS  additional FFLAGS used when building shared objects
  SHLIB_LD      command for linking shared objects which contain
		object files from a C or Fortran compiler only
97
  SHLIB_LDFLAGS
98
		special flags used by SHLIB_LD
99
  SHLIB_FCLD, SHLIB_FCLDFLAGS
100
		ditto when using Fortran 9x
101
  TCLTK_CPPFLAGS
102
		flags needed for finding the tcl.h and tk.h headers
103
  TCLTK_LIBS    flags needed for linking against the Tcl and Tk libraries
104 105 106 107 108 109 110 111 112 113 114 115

Report bugs to <r-bugs@r-project.org>."

## <NOTE>
## The variables are basically the precious configure variables (with
## the R_* and MAIN_* ones removed), plus FLIBS and BLAS_LIBS.
## One could use
##   precious_configure_vars=`~/src/R/configure --help \
##     | sed -n '/^Some influential/,/^[^ ]/p' \
##     | sed '/^[^ ]/d' \
##     | sed 's/^  //' \
##     | cut -f1 -d ' ' \
116 117
##     | grep -v '^MAIN_' \
##     | grep -v '^R_' \
118 119 120
##     | sort \
##     | uniq`
## to obtain the configure vars and hence create most of the above usage
121 122 123 124 125 126 127
## info as well as the list of accepted variables below automatically.
## </NOTE>

if test $# = 0; then
  echo "${usage}"
  exit 1
fi
128

129 130 131 132 133 134 135 136
if test "${R_OSTYPE}" = "windows"; then
  MAKE=make
  R_DOC_DIR=${R_HOME}/doc
  R_INCLUDE_DIR=${R_HOME}/include
  R_SHARE_DIR=${R_HOME}/share
  R_ARCH=
fi

137
makefiles="-f ${R_HOME}/etc${R_ARCH}/Makeconf -f ${R_SHARE_DIR}/make/config.mk"
138
## avoid passing down -jN
139 140
MAKEFLAGS=
export MAKEFLAGS
141
query="${MAKE} -s ${makefiles} print R_HOME=${R_HOME}"
142 143

LIBR=`eval $query VAR=LIBR`
144
STATIC_LIBR=`eval $query VAR=STATIC_LIBR`
145

146 147 148 149 150 151
if test -n "${R_ARCH}"; then
  includes="-I${R_INCLUDE_DIR} -I${R_INCLUDE_DIR}${R_ARCH}"
else
  includes="-I${R_INCLUDE_DIR}"
fi

152 153 154 155 156 157 158 159 160
var=
while test -n "${1}"; do
  case "${1}" in
    -h|--help)
      echo "${usage}"; exit 0 ;;
    -v|--version)
      echo "${version}"; exit 0 ;;
    --cppflags)
      if test -z "${LIBR}"; then
161 162
	if test -z "${STATIC_LIBR}"; then
	  echo "R was not built as a library" >&2
163
	else
164 165
	  echo "${includes}"
	fi
166
      else
167
	echo "${includes}"
168 169 170 171 172
      fi
      exit 0
      ;;
    --ldflags)
      if test -z "${LIBR}"; then
173 174
	if test -z "${STATIC_LIBR}"; then
	  echo "R was not built as a library" >&2
175
	else
176 177
	  echo "${STATIC_LIBR}"
	fi
178
      else
179
	echo "${LIBR}"
180 181 182 183 184
      fi
      exit 0
      ;;
    *)
      if test -z "${var}"; then
185
	var="${1}"
186
      else
187 188
	echo "ERROR: cannot query more than one variable" >&2
	exit 1
189 190 191 192 193 194 195 196
      fi
      ;;
  esac
  shift
done

ok_c_vars="CC CFLAGS CPICFLAGS CPP CPPFLAGS"
ok_cxx_vars="CXX CXXCPP CXXFLAGS CXXPICFLAGS"
197
ok_dylib_vars="DYLIB_EXT DYLIB_LD DYLIB_LDFLAGS"
198 199
ok_objc_vars="OBJC OBJCFLAGS"
ok_java_vars="JAVA JAVAC JAVAH JAR JAVA_HOME JAVA_LIBS JAVA_CPPFLAGS"
200
ok_f77_vars="F77 FFLAGS FPICFLAGS FLIBS SAFE_FFLAGS FC FCFLAGS FCPICFLAGS"
201
ok_ld_vars="LDFLAGS"
202
ok_shlib_vars="SHLIB_CFLAGS SHLIB_CXXLD SHLIB_CXXLDFLAGS SHLIB_EXT SHLIB_FFLAGS SHLIB_LD SHLIB_LDFLAGS SHLIB_FCLD SHLIB_FCLDFLAGS"
203
ok_tcltk_vars="TCLTK_CPPFLAGS TCLTK_LIBS"
204
ok_other_vars="BLAS_LIBS LAPACK_LIBS MAKE LIBnn"
205 206 207 208

## Can we do this elegantly using case?

var_ok=no
209
for v in ${ok_c_vars} ${ok_cxx_vars} ${ok_dylib_vars} ${ok_f77_vars} \
210 211
	 ${ok_objc_vars} ${ok_java_vars} \
	 ${ok_ld_vars} ${ok_shlib_vars} ${ok_tcltk_vars} \
212
	 ${ok_other_vars}; do
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
  if test "${var}" = "${v}"; then
    var_ok=yes
    break
  fi
done

if test "${var_ok}" = yes; then
  eval "${query} VAR=${var}"
else
  echo "ERROR: no information for variable '${var}'"
  exit 1
fi

### Local Variables: ***
### mode: sh ***
### sh-indentation: 2 ***
### End: ***