The R Project SVN R

Rev

Rev 77128 | Rev 78359 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
19165 hornik 1
## config -- Simple shell script to get the values of basic R configure
2
## variables, or the header and library flags necessary for linking
3
## against R.
4
##
5
## Usage:
6
##   R CMD config [options] [VAR]
7
 
76330 ripley 8
## Copyright (C) 2002-2019 The R Core Team
19165 hornik 9
##
10
## This document is free software; you can redistribute it and/or modify
11
## it under the terms of the GNU General Public License as published by
12
## the Free Software Foundation; either version 2, or (at your option)
13
## any later version.
14
##
15
## This program is distributed in the hope that it will be useful, but
16
## WITHOUT ANY WARRANTY; without even the implied warranty of
17
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
## General Public License for more details.
19
##
42314 ripley 20
## A copy of the GNU General Public License is available at
68951 ripley 21
## https://www.R-project.org/Licenses/
19165 hornik 22
 
37351 ripley 23
revision='$Revision: 77305 $'
19165 hornik 24
version=`set - ${revision}; echo ${2}`
47522 ripley 25
version="R configuration information retrieval script: ${R_VERSION} (r${version})
19165 hornik 26
 
76330 ripley 27
Copyright (C) 2002-2019 The R Core Team.
42192 ripley 28
This is free software; see the GNU General Public License version 2
19165 hornik 29
or later for copying conditions.  There is NO warranty."
30
 
31
usage="Usage: R CMD config [options] [VAR]
32
 
33
Get the value of a basic R configure variable VAR which must be among
34
those listed in the 'Variables' section below, or the header and
35
library flags necessary for linking against R.
36
 
37
Options:
38
  -h, --help            print short help message and exit
47442 hornik 39
  -v, --version         print version info and exit
19165 hornik 40
      --cppflags        print pre-processor flags required to compile
63217 ripley 41
			a C/C++ file using R as a library
42
      --ldflags         print linker flags needed for linking a front-end
43
                        against the R library
71209 hornik 44
      --no-user-files   ignore customization files under ~/.R
45
      --no-site-files   ignore site customization files under R_HOME/etc
46
      --all             print names and values of all variables below
19165 hornik 47
 
48
Variables:
76672 ripley 49
  AR            command to make static libraries
46994 ripley 50
  BLAS_LIBS     flags needed for linking against external BLAS libraries
29123 ripley 51
  CC            C compiler command
52
  CFLAGS        C compiler flags
68386 ripley 53
  CPICFLAGS     special flags for compiling C code to be included in a
46994 ripley 54
		shared library
29123 ripley 55
  CPPFLAGS      C/C++ preprocessor flags, e.g. -I<dir> if you have
46994 ripley 56
		headers in a nonstandard directory <dir>
71141 plummer 57
  CXX           default compiler command for C++ code
77111 ripley 58
  CXXCPP        C++ preprocessor (deprecated)
68386 ripley 59
  CXXFLAGS      compiler flags for CXX
71141 plummer 60
  CXXPICFLAGS   special flags for compiling C++ code to be included in a
46994 ripley 61
		shared library
72374 plummer 62
  CXX11         compiler command for C++11 code
63
  CXX11STD      flag used with CXX11 to enable C++11 support
64
  CXX11FLAGS    further compiler flags for CXX11
65
  CXX11PICFLAGS
68386 ripley 66
                special flags for compiling C++11 code to be included in
65340 plummer 67
                a shared library
72374 plummer 68
  CXX14         compiler command for C++14 code
69
  CXX14STD      flag used with CXX14 to enable C++14 support
70
  CXX14FLAGS    further compiler flags for CXX14
71
  CXX14PICFLAGS
70899 plummer 72
                special flags for compiling C++14 code to be included in
73
                a shared library
72374 plummer 74
  CXX17         compiler command for C++17 code
75
  CXX17STD      flag used with CXX17 to enable C++17 support
76
  CXX17FLAGS    further compiler flags for CXX17
77
  CXX17PICFLAGS
72331 plummer 78
                special flags for compiling C++17 code to be included in
79
                a shared library
47780 ripley 80
  DYLIB_EXT	file extension (including '.') for dynamic libraries
29123 ripley 81
  DYLIB_LD      command for linking dynamic libraries which contain
46994 ripley 82
		object files from a C or Fortran compiler only
29123 ripley 83
  DYLIB_LDFLAGS
46994 ripley 84
		special flags used by DYLIB_LD
75799 ripley 85
  FC            Fortran compiler command
75658 ripley 86
  FFLAGS        fixed-form Fortran compiler flags
75799 ripley 87
  FCFLAGS       free-form Fortran 9x compiler flags
29123 ripley 88
  FLIBS         linker flags needed to link Fortran code
89
  FPICFLAGS     special flags for compiling Fortran code to be turned
46994 ripley 90
		into a shared library
39786 urbaneks 91
  JAR           Java archive tool command
92
  JAVA          Java interpreter command
93
  JAVAC         Java compiler command
94
  JAVAH         Java header and stub generator command
41169 urbaneks 95
  JAVA_HOME     path to the home of Java distribution
39786 urbaneks 96
  JAVA_LIBS     flags needed for linking against Java libraries
41169 urbaneks 97
  JAVA_CPPFLAGS C preprocessor flags needed for compiling JNI programs
29123 ripley 98
  LAPACK_LIBS   flags needed for linking against external LAPACK libraries
40913 ripley 99
  LIBnn         location for libraries, e.g. 'lib' or 'lib64' on this platform
29123 ripley 100
  LDFLAGS       linker flags, e.g. -L<dir> if you have libraries in a
46994 ripley 101
		nonstandard directory <dir>
75799 ripley 102
  MAKE          Make command
39786 urbaneks 103
  OBJC          Objective C compiler command
104
  OBJCFLAGS     Objective C compiler flags
76672 ripley 105
  RANLIB        command to index static libraries
75658 ripley 106
  SAFE_FFLAGS   Safe (as conformant as possible) Fortran compiler flags
47780 ripley 107
  SHLIB_CFLAGS  additional CFLAGS used when building shared objects
75798 ripley 108
  SHLIB_CXXFLAGS
109
                additional CXXFLAGS used when building shared objects
47780 ripley 110
  SHLIB_CXXLD   command for linking shared objects which contain
77013 ripley 111
		object files from a C++ compiler (and CXX11 CXX14 CXX17)
29123 ripley 112
  SHLIB_CXXLDFLAGS
77013 ripley 113
		special flags used by SHLIB_CXXLD (and CXX11 CXX14 CXX17)
47836 ripley 114
  SHLIB_EXT	file extension (including '.') for shared objects
47780 ripley 115
  SHLIB_FFLAGS  additional FFLAGS used when building shared objects
116
  SHLIB_LD      command for linking shared objects which contain
46994 ripley 117
		object files from a C or Fortran compiler only
29123 ripley 118
  SHLIB_LDFLAGS
46994 ripley 119
		special flags used by SHLIB_LD
29123 ripley 120
  TCLTK_CPPFLAGS
46994 ripley 121
		flags needed for finding the tcl.h and tk.h headers
29123 ripley 122
  TCLTK_LIBS    flags needed for linking against the Tcl and Tk libraries
70374 murdoch 123
"
19165 hornik 124
 
70374 murdoch 125
if test "${R_OSTYPE}" = "windows"; then
126
  usage="${usage}
127
Windows only:
75798 ripley 128
  COMPILED_BY   name and version of compiler used to build R
129
  LOCAL_SOFT    absolute path to '/usr/local' software collection
130
  OBJDUMP       command to dump objects"
70374 murdoch 131
fi
132
 
133
usage="${usage}
134
 
71736 hornik 135
Report bugs at <https://bugs.R-project.org>."
19165 hornik 136
 
137
## <NOTE>
138
## The variables are basically the precious configure variables (with
139
## the R_* and MAIN_* ones removed), plus FLIBS and BLAS_LIBS.
140
## One could use
141
##   precious_configure_vars=`~/src/R/configure --help \
142
##     | sed -n '/^Some influential/,/^[^ ]/p' \
143
##     | sed '/^[^ ]/d' \
144
##     | sed 's/^  //' \
145
##     | cut -f1 -d ' ' \
29123 ripley 146
##     | grep -v '^MAIN_' \
147
##     | grep -v '^R_' \
19165 hornik 148
##     | sort \
149
##     | uniq`
150
## to obtain the configure vars and hence create most of the above usage
29123 ripley 151
## info as well as the list of accepted variables below automatically.
152
## </NOTE>
19165 hornik 153
 
29123 ripley 154
if test $# = 0; then
155
  echo "${usage}"
156
  exit 1
157
fi
158
 
45260 ripley 159
if test "${R_OSTYPE}" = "windows"; then
160
  MAKE=make
161
  R_DOC_DIR=${R_HOME}/doc
162
  R_INCLUDE_DIR=${R_HOME}/include
163
  R_SHARE_DIR=${R_HOME}/share
164
fi
165
 
37310 ripley 166
makefiles="-f ${R_HOME}/etc${R_ARCH}/Makeconf -f ${R_SHARE_DIR}/make/config.mk"
46881 ripley 167
## avoid passing down -jN
47769 ripley 168
MAKEFLAGS=
169
export MAKEFLAGS
23685 hornik 170
query="${MAKE} -s ${makefiles} print R_HOME=${R_HOME}"
19165 hornik 171
 
172
LIBR=`eval $query VAR=LIBR`
43352 ripley 173
STATIC_LIBR=`eval $query VAR=STATIC_LIBR`
63217 ripley 174
MAIN_LDFLAGS=`eval $query VAR=MAIN_LDFLAGS`
175
LIBS=`eval $query VAR=LIBS`
71275 lawrence 176
LDFLAGS=`eval $query VAR=LDFLAGS`
19165 hornik 177
 
63217 ripley 178
 
45260 ripley 179
if test -n "${R_ARCH}"; then
180
  includes="-I${R_INCLUDE_DIR} -I${R_INCLUDE_DIR}${R_ARCH}"
181
else
182
  includes="-I${R_INCLUDE_DIR}"
183
fi
184
 
19165 hornik 185
var=
62501 ripley 186
personal="yes"
62515 ripley 187
site="yes"
71209 hornik 188
all="no"
19165 hornik 189
while test -n "${1}"; do
190
  case "${1}" in
191
    -h|--help)
192
      echo "${usage}"; exit 0 ;;
193
    -v|--version)
194
      echo "${version}"; exit 0 ;;
195
    --cppflags)
196
      if test -z "${LIBR}"; then
46994 ripley 197
	if test -z "${STATIC_LIBR}"; then
198
	  echo "R was not built as a library" >&2
43352 ripley 199
	else
46994 ripley 200
	  echo "${includes}"
201
	fi
19165 hornik 202
      else
46994 ripley 203
	echo "${includes}"
19165 hornik 204
      fi
205
      exit 0
206
      ;;
207
    --ldflags)
63217 ripley 208
      ## changed in R 3.1.0 to be those needed to link a front-end
19165 hornik 209
      if test -z "${LIBR}"; then
46994 ripley 210
	if test -z "${STATIC_LIBR}"; then
211
	  echo "R was not built as a library" >&2
43352 ripley 212
	else
63217 ripley 213
	  echo "${MAIN_LDFLAGS} ${LDFLAGS} ${STATIC_LIBR}"
46994 ripley 214
	fi
19165 hornik 215
      else
63217 ripley 216
	echo "${MAIN_LDFLAGS} ${LDFLAGS} ${LIBR} ${LIBS}"
19165 hornik 217
      fi
218
      exit 0
219
      ;;
62515 ripley 220
    --no-user-files)
62501 ripley 221
      personal="no"
222
      ;;
62515 ripley 223
    --no-site-files)
224
      site="no"
225
      ;;
71209 hornik 226
    --all)
227
      all="yes"
228
      ;;
19165 hornik 229
    *)
230
      if test -z "${var}"; then
46994 ripley 231
	var="${1}"
19165 hornik 232
      else
46994 ripley 233
	echo "ERROR: cannot query more than one variable" >&2
234
	exit 1
19165 hornik 235
      fi
236
      ;;
237
  esac
238
  shift
239
done
240
 
71187 ripley 241
## quotes added in R 3.3.2
62515 ripley 242
if test "${site}" = "yes"; then
62605 ripley 243
: ${R_MAKEVARS_SITE="${R_HOME}/etc${R_ARCH}/Makevars.site"}
244
  if test -f "${R_MAKEVARS_SITE}"; then
71187 ripley 245
    makefiles="${makefiles} -f \"${R_MAKEVARS_SITE}\""
62515 ripley 246
  fi
247
fi
62501 ripley 248
if test "${personal}" = "yes"; then
249
  if test "${R_OSTYPE}" = "windows"; then
70474 hornik 250
    if test -f "${R_MAKEVARS_USER}"; then
71187 ripley 251
      makefiles="${makefiles} -f \"${R_MAKEVARS_USER}\""
77305 ripley 252
    elif test ${R_ARCH} = "/x64" && test -f "${HOME}/.R/Makevars.win64"; then
71187 ripley 253
      makefiles="${makefiles} -f \"${HOME}\"/.R/Makevars.win64"
62501 ripley 254
    elif test -f "${HOME}/.R/Makevars.win"; then
71187 ripley 255
      makefiles="${makefiles} -f \"${HOME}\"/.R/Makevars.win"
62501 ripley 256
    elif test -f "${HOME}/.R/Makevars"; then
71187 ripley 257
      makefiles="${makefiles} -f \"${HOME}\"/.R/Makevars"
62501 ripley 258
    fi
259
  else
62758 ripley 260
    . ${R_HOME}/etc${R_ARCH}/Renviron
70474 hornik 261
    if test -f "${R_MAKEVARS_USER}"; then
71187 ripley 262
      makefiles="${makefiles} -f \"${R_MAKEVARS_USER}\""
62605 ripley 263
    elif test -f "${HOME}/.R/Makevars-${R_PLATFORM}"; then
71187 ripley 264
      makefiles="${makefiles} -f \"${HOME}\"/.R/Makevars-${R_PLATFORM}"
62501 ripley 265
    elif test -f "${HOME}/.R/Makevars"; then
71187 ripley 266
      makefiles="${makefiles} -f \"${HOME}\"/.R/Makevars"
62501 ripley 267
    fi
268
  fi
269
fi
62515 ripley 270
query="${MAKE} -s ${makefiles} print R_HOME=${R_HOME}"
62501 ripley 271
 
77116 ripley 272
ok_c_vars="CC CFLAGS CPICFLAGS CPPFLAGS"
77104 ripley 273
ok_cxx_vars="CXX CXXFLAGS CXXPICFLAGS CXX11 CXX11STD CXX11FLAGS CXX11PICFLAGS CXX14 CXX14STD CXX14FLAGS CXX14PICFLAGS CXX17 CXX17STD CXX17FLAGS CXX17PICFLAGS"
47780 ripley 274
ok_dylib_vars="DYLIB_EXT DYLIB_LD DYLIB_LDFLAGS"
39786 urbaneks 275
ok_objc_vars="OBJC OBJCFLAGS"
41169 urbaneks 276
ok_java_vars="JAVA JAVAC JAVAH JAR JAVA_HOME JAVA_LIBS JAVA_CPPFLAGS"
76330 ripley 277
ok_ftn_vars="FC FFLAGS FPICFLAGS FLIBS FCFLAGS SAFE_FFLAGS"
19165 hornik 278
ok_ld_vars="LDFLAGS"
77013 ripley 279
ok_shlib_vars="SHLIB_CFLAGS SHLIB_CXXFLAGS SHLIB_CXXLD SHLIB_CXXLDFLAGS SHLIB_CXX11LD SHLIB_CXX11LDFLAGS SHLIB_CXX14LD SHLIB_CXX14LDFLAGS SHLIB_CXX17LD SHLIB_CXX17LDFLAGS SHLIB_EXT SHLIB_FFLAGS SHLIB_LD SHLIB_LDFLAGS"
19165 hornik 280
ok_tcltk_vars="TCLTK_CPPFLAGS TCLTK_LIBS"
76672 ripley 281
ok_other_vars="BLAS_LIBS LAPACK_LIBS MAKE LIBnn AR RANLIB"
77128 ripley 282
deprecated_vars="CPP CXXCPP"
75798 ripley 283
if test "${R_OSTYPE}" = "windows"; then
284
  ok_win_vars="LOCAL_SOFT COMPILED_BY OBJDUMP"
285
fi
19165 hornik 286
 
71209 hornik 287
if test "${all}" = "yes"; then
288
  query="${MAKE} -s ${makefiles} print-name-and-value R_HOME=${R_HOME}"
75727 ripley 289
  for v in ${ok_c_vars} ${ok_cxx_vars} ${ok_dylib_vars} ${ok_ftn_vars} \
71209 hornik 290
	   ${ok_objc_vars} ${ok_java_vars} \
291
	   ${ok_ld_vars} ${ok_shlib_vars} ${ok_tcltk_vars} \
75798 ripley 292
	   ${ok_other_vars} ${ok_win_vars}; do
71209 hornik 293
    eval "${query} VAR=${v}"
294
  done
77111 ripley 295
  echo "## The following variables are deprecated"
296
  for v in ${deprecated_vars}; do
297
    eval "${query} VAR=${v}"
298
  done
71209 hornik 299
  exit 0
300
fi
301
 
19165 hornik 302
## Can we do this elegantly using case?
303
 
304
var_ok=no
75727 ripley 305
for v in ${ok_c_vars} ${ok_cxx_vars} ${ok_dylib_vars} ${ok_ftn_vars} \
46994 ripley 306
	 ${ok_objc_vars} ${ok_java_vars} \
307
	 ${ok_ld_vars} ${ok_shlib_vars} ${ok_tcltk_vars} \
75798 ripley 308
	 ${ok_other_vars} ${ok_win_vars}; do
19165 hornik 309
  if test "${var}" = "${v}"; then
310
    var_ok=yes
311
    break
312
  fi
313
done
314
 
77111 ripley 315
for v in ${deprecated_vars}; do
316
  if test "${var}" = "${v}"; then
317
    var_ok=yes
318
    1>&2 echo "'config' variable '${v}' is deprecated"
319
    break
320
  fi
321
done
77105 ripley 322
 
19165 hornik 323
if test "${var_ok}" = yes; then
324
  eval "${query} VAR=${var}"
325
else
326
  echo "ERROR: no information for variable '${var}'"
327
  exit 1
328
fi
329
 
330
### Local Variables: ***
331
### mode: sh ***
332
### sh-indentation: 2 ***
333
### End: ***