The R Project SVN R

Rev

Rev 89223 | 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
 
87644 ripley 8
## Copyright (C) 2002-2025 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: 89241 $'
19165 hornik 24
version=`set - ${revision}; echo ${2}`
47522 ripley 25
version="R configuration information retrieval script: ${R_VERSION} (r${version})
19165 hornik 26
 
83520 ripley 27
Copyright (C) 2002-2022 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
79388 ripley 35
library flags necessary for linking a front-end against R.
19165 hornik 36
 
37
Options:
38
  -h, --help            print short help message and exit
47442 hornik 39
  -v, --version         print version info and exit
79388 ripley 40
      --cppflags        print pre-processor flags required to compile a
41
			C/C++ file as part of a front-end using R as a library
63217 ripley 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
83520 ripley 53
  CC17          Ditto for the C17 or earlier compiler
54
  C17FLAGS
55
  CC23          Ditto for the C23 or later compiler
56
  C23FLAGS
68386 ripley 57
  CPICFLAGS     special flags for compiling C code to be included in a
46994 ripley 58
		shared library
29123 ripley 59
  CPPFLAGS      C/C++ preprocessor flags, e.g. -I<dir> if you have
46994 ripley 60
		headers in a nonstandard directory <dir>
71141 plummer 61
  CXX           default compiler command for C++ code
68386 ripley 62
  CXXFLAGS      compiler flags for CXX
71141 plummer 63
  CXXPICFLAGS   special flags for compiling C++ code to be included in a
46994 ripley 64
		shared library
72374 plummer 65
  CXX17         compiler command for C++17 code
66
  CXX17STD      flag used with CXX17 to enable C++17 support
67
  CXX17FLAGS    further compiler flags for CXX17
68
  CXX17PICFLAGS
72331 plummer 69
                special flags for compiling C++17 code to be included in
70
                a shared library
78110 ripley 71
  CXX20         compiler command for C++20 code
72
  CXX20STD      flag used with CXX20 to enable C++20 support
73
  CXX20FLAGS    further compiler flags for CXX20
89241 ripley 74
  CXX20PICFLAGS
75
                special flags for compiling C++20 code to be included in
76
                a shared library
82866 ripley 77
  CXX23         compiler command for C++23 code
78
  CXX23STD      flag used with CXX23 to enable C++23 support
79
  CXX23FLAGS    further compiler flags for CXX23
80
  CXX23PICFLAGS
81
                special flags for compiling C++23 code to be included in
78110 ripley 82
                a shared library
87644 ripley 83
  CXX26         compiler command for C++26 code
84
  CXX26STD      flag used with CXX26 to enable C++26 support
85
  CXX26FLAGS    further compiler flags for CXX26
86
  CXX26PICFLAGS
87
                special flags for compiling C++26 code to be included in
88
                a shared library
47780 ripley 89
  DYLIB_EXT	file extension (including '.') for dynamic libraries
29123 ripley 90
  DYLIB_LD      command for linking dynamic libraries which contain
46994 ripley 91
		object files from a C or Fortran compiler only
29123 ripley 92
  DYLIB_LDFLAGS
46994 ripley 93
		special flags used by DYLIB_LD
75799 ripley 94
  FC            Fortran compiler command
75658 ripley 95
  FFLAGS        fixed-form Fortran compiler flags
75799 ripley 96
  FCFLAGS       free-form Fortran 9x compiler flags
29123 ripley 97
  FLIBS         linker flags needed to link Fortran code
98
  FPICFLAGS     special flags for compiling Fortran code to be turned
46994 ripley 99
		into a shared library
39786 urbaneks 100
  JAR           Java archive tool command
101
  JAVA          Java interpreter command
102
  JAVAC         Java compiler command
103
  JAVAH         Java header and stub generator command
41169 urbaneks 104
  JAVA_HOME     path to the home of Java distribution
39786 urbaneks 105
  JAVA_LIBS     flags needed for linking against Java libraries
41169 urbaneks 106
  JAVA_CPPFLAGS C preprocessor flags needed for compiling JNI programs
29123 ripley 107
  LAPACK_LIBS   flags needed for linking against external LAPACK libraries
40913 ripley 108
  LIBnn         location for libraries, e.g. 'lib' or 'lib64' on this platform
29123 ripley 109
  LDFLAGS       linker flags, e.g. -L<dir> if you have libraries in a
46994 ripley 110
		nonstandard directory <dir>
78849 ripley 111
  LTO LTO_FC LTO_LD  flags for Link-Time Optimization
75799 ripley 112
  MAKE          Make command
78773 ripley 113
  NM            comand to display symbol tables
39786 urbaneks 114
  OBJC          Objective C compiler command
115
  OBJCFLAGS     Objective C compiler flags
76672 ripley 116
  RANLIB        command to index static libraries
75658 ripley 117
  SAFE_FFLAGS   Safe (as conformant as possible) Fortran compiler flags
47780 ripley 118
  SHLIB_CFLAGS  additional CFLAGS used when building shared objects
75798 ripley 119
  SHLIB_CXXFLAGS
120
                additional CXXFLAGS used when building shared objects
47780 ripley 121
  SHLIB_CXXLD   command for linking shared objects which contain
89223 ripley 122
		object files from a C++ compiler (and CXX17 CXX20 CXX23 CXX26)
29123 ripley 123
  SHLIB_CXXLDFLAGS
89223 ripley 124
		special flags used by SHLIB_CXXLD (and CXX17 CXX20 CXX23 CXX26)
47836 ripley 125
  SHLIB_EXT	file extension (including '.') for shared objects
47780 ripley 126
  SHLIB_FFLAGS  additional FFLAGS used when building shared objects
127
  SHLIB_LD      command for linking shared objects which contain
46994 ripley 128
		object files from a C or Fortran compiler only
29123 ripley 129
  SHLIB_LDFLAGS
46994 ripley 130
		special flags used by SHLIB_LD
29123 ripley 131
  TCLTK_CPPFLAGS
46994 ripley 132
		flags needed for finding the tcl.h and tk.h headers
29123 ripley 133
  TCLTK_LIBS    flags needed for linking against the Tcl and Tk libraries
70374 murdoch 134
"
19165 hornik 135
 
70374 murdoch 136
if test "${R_OSTYPE}" = "windows"; then
137
  usage="${usage}
138
Windows only:
75798 ripley 139
  COMPILED_BY   name and version of compiler used to build R
140
  LOCAL_SOFT    absolute path to '/usr/local' software collection
81375 kalibera 141
  R_TOOLS_SOFT  absolute path to 'R tools' software collection
75798 ripley 142
  OBJDUMP       command to dump objects"
70374 murdoch 143
fi
144
 
145
usage="${usage}
146
 
71736 hornik 147
Report bugs at <https://bugs.R-project.org>."
19165 hornik 148
 
149
## <NOTE>
150
## The variables are basically the precious configure variables (with
151
## the R_* and MAIN_* ones removed), plus FLIBS and BLAS_LIBS.
152
## One could use
153
##   precious_configure_vars=`~/src/R/configure --help \
154
##     | sed -n '/^Some influential/,/^[^ ]/p' \
155
##     | sed '/^[^ ]/d' \
156
##     | sed 's/^  //' \
157
##     | cut -f1 -d ' ' \
29123 ripley 158
##     | grep -v '^MAIN_' \
159
##     | grep -v '^R_' \
19165 hornik 160
##     | sort \
161
##     | uniq`
162
## to obtain the configure vars and hence create most of the above usage
29123 ripley 163
## info as well as the list of accepted variables below automatically.
164
## </NOTE>
19165 hornik 165
 
29123 ripley 166
if test $# = 0; then
167
  echo "${usage}"
168
  exit 1
169
fi
170
 
45260 ripley 171
if test "${R_OSTYPE}" = "windows"; then
172
  MAKE=make
173
  R_DOC_DIR=${R_HOME}/doc
174
  R_INCLUDE_DIR=${R_HOME}/include
175
  R_SHARE_DIR=${R_HOME}/share
176
fi
177
 
37310 ripley 178
makefiles="-f ${R_HOME}/etc${R_ARCH}/Makeconf -f ${R_SHARE_DIR}/make/config.mk"
46881 ripley 179
## avoid passing down -jN
47769 ripley 180
MAKEFLAGS=
181
export MAKEFLAGS
23685 hornik 182
query="${MAKE} -s ${makefiles} print R_HOME=${R_HOME}"
19165 hornik 183
 
184
LIBR=`eval $query VAR=LIBR`
43352 ripley 185
STATIC_LIBR=`eval $query VAR=STATIC_LIBR`
63217 ripley 186
MAIN_LDFLAGS=`eval $query VAR=MAIN_LDFLAGS`
187
LIBS=`eval $query VAR=LIBS`
71275 lawrence 188
LDFLAGS=`eval $query VAR=LDFLAGS`
19165 hornik 189
 
63217 ripley 190
 
45260 ripley 191
if test -n "${R_ARCH}"; then
192
  includes="-I${R_INCLUDE_DIR} -I${R_INCLUDE_DIR}${R_ARCH}"
193
else
194
  includes="-I${R_INCLUDE_DIR}"
195
fi
196
 
19165 hornik 197
var=
62501 ripley 198
personal="yes"
62515 ripley 199
site="yes"
71209 hornik 200
all="no"
19165 hornik 201
while test -n "${1}"; do
202
  case "${1}" in
203
    -h|--help)
204
      echo "${usage}"; exit 0 ;;
205
    -v|--version)
206
      echo "${version}"; exit 0 ;;
207
    --cppflags)
208
      if test -z "${LIBR}"; then
46994 ripley 209
	if test -z "${STATIC_LIBR}"; then
210
	  echo "R was not built as a library" >&2
43352 ripley 211
	else
46994 ripley 212
	  echo "${includes}"
213
	fi
19165 hornik 214
      else
46994 ripley 215
	echo "${includes}"
19165 hornik 216
      fi
217
      exit 0
218
      ;;
219
    --ldflags)
63217 ripley 220
      ## changed in R 3.1.0 to be those needed to link a front-end
19165 hornik 221
      if test -z "${LIBR}"; then
46994 ripley 222
	if test -z "${STATIC_LIBR}"; then
223
	  echo "R was not built as a library" >&2
43352 ripley 224
	else
63217 ripley 225
	  echo "${MAIN_LDFLAGS} ${LDFLAGS} ${STATIC_LIBR}"
46994 ripley 226
	fi
19165 hornik 227
      else
63217 ripley 228
	echo "${MAIN_LDFLAGS} ${LDFLAGS} ${LIBR} ${LIBS}"
19165 hornik 229
      fi
230
      exit 0
231
      ;;
62515 ripley 232
    --no-user-files)
62501 ripley 233
      personal="no"
234
      ;;
62515 ripley 235
    --no-site-files)
236
      site="no"
237
      ;;
71209 hornik 238
    --all)
239
      all="yes"
240
      ;;
19165 hornik 241
    *)
242
      if test -z "${var}"; then
46994 ripley 243
	var="${1}"
19165 hornik 244
      else
46994 ripley 245
	echo "ERROR: cannot query more than one variable" >&2
246
	exit 1
19165 hornik 247
      fi
248
      ;;
249
  esac
250
  shift
251
done
252
 
71187 ripley 253
## quotes added in R 3.3.2
62515 ripley 254
if test "${site}" = "yes"; then
62605 ripley 255
: ${R_MAKEVARS_SITE="${R_HOME}/etc${R_ARCH}/Makevars.site"}
256
  if test -f "${R_MAKEVARS_SITE}"; then
71187 ripley 257
    makefiles="${makefiles} -f \"${R_MAKEVARS_SITE}\""
62515 ripley 258
  fi
259
fi
62501 ripley 260
if test "${personal}" = "yes"; then
261
  if test "${R_OSTYPE}" = "windows"; then
70474 hornik 262
    if test -f "${R_MAKEVARS_USER}"; then
71187 ripley 263
      makefiles="${makefiles} -f \"${R_MAKEVARS_USER}\""
85072 kalibera 264
    elif test -f "${HOME}/.R/Makevars.ucrt"; then
81360 kalibera 265
      makefiles="${makefiles} -f \"${HOME}\"/.R/Makevars.ucrt"
85072 kalibera 266
    elif test -f "${HOME}/.R/Makevars.win64"; then
71187 ripley 267
      makefiles="${makefiles} -f \"${HOME}\"/.R/Makevars.win64"
62501 ripley 268
    elif test -f "${HOME}/.R/Makevars.win"; then
71187 ripley 269
      makefiles="${makefiles} -f \"${HOME}\"/.R/Makevars.win"
62501 ripley 270
    elif test -f "${HOME}/.R/Makevars"; then
71187 ripley 271
      makefiles="${makefiles} -f \"${HOME}\"/.R/Makevars"
62501 ripley 272
    fi
273
  else
62758 ripley 274
    . ${R_HOME}/etc${R_ARCH}/Renviron
70474 hornik 275
    if test -f "${R_MAKEVARS_USER}"; then
71187 ripley 276
      makefiles="${makefiles} -f \"${R_MAKEVARS_USER}\""
62605 ripley 277
    elif test -f "${HOME}/.R/Makevars-${R_PLATFORM}"; then
71187 ripley 278
      makefiles="${makefiles} -f \"${HOME}\"/.R/Makevars-${R_PLATFORM}"
62501 ripley 279
    elif test -f "${HOME}/.R/Makevars"; then
71187 ripley 280
      makefiles="${makefiles} -f \"${HOME}\"/.R/Makevars"
62501 ripley 281
    fi
282
  fi
283
fi
62515 ripley 284
query="${MAKE} -s ${makefiles} print R_HOME=${R_HOME}"
62501 ripley 285
 
83600 ripley 286
ok_c_vars="CC CFLAGS CPICFLAGS CPPFLAGS CC17 C17FLAGS CC23 C23FLAGS CC90 C90FLAGS CC99 C99FLAGS"
89241 ripley 287
ok_cxx_vars="CXX CXXFLAGS CXXPICFLAGS CXX17 CXX17STD CXX17FLAGS CXX17PICFLAGS CXX20 CXX20STD CXX20FLAGS CXX20PICFLAGS CXX23 CXX23STD CXX23FLAGS CXX23PICFLAGS CXX26 CXX26STD CXX26FLAGS CXX26PICFLAGS"
47780 ripley 288
ok_dylib_vars="DYLIB_EXT DYLIB_LD DYLIB_LDFLAGS"
39786 urbaneks 289
ok_objc_vars="OBJC OBJCFLAGS"
41169 urbaneks 290
ok_java_vars="JAVA JAVAC JAVAH JAR JAVA_HOME JAVA_LIBS JAVA_CPPFLAGS"
76330 ripley 291
ok_ftn_vars="FC FFLAGS FPICFLAGS FLIBS FCFLAGS SAFE_FFLAGS"
19165 hornik 292
ok_ld_vars="LDFLAGS"
89223 ripley 293
ok_shlib_vars="SHLIB_CFLAGS SHLIB_CXXFLAGS SHLIB_CXXLD SHLIB_CXXLDFLAGS SHLIB_CXX17LD SHLIB_CXX17LDFLAGS SHLIB_CXX20LD SHLIB_CXX20LDFLAGS SHLIB_CXX23LD SHLIB_CXX23LDFLAGS SHLIB_CXX26LD SHLIB_CXX26LDFLAGS SHLIB_EXT SHLIB_FFLAGS SHLIB_LD SHLIB_LDFLAGS"
19165 hornik 294
ok_tcltk_vars="TCLTK_CPPFLAGS TCLTK_LIBS"
78849 ripley 295
ok_other_vars="BLAS_LIBS LAPACK_LIBS MAKE LIBnn AR NM RANLIB LTO LTO_FC LTO_LD"
89223 ripley 296
defunct_vars="CPP CXXCPP CXX11 CXX11STD CXX11FLAGS CXX11PICFLAGS CXX14 CXX14STD CXX14FLAGS CXX14PICFLAGS SHLIB_CXX11LD SHLIB_CXX11LDFLAGS SHLIB_CXX14LD SHLIB_CXX14LDFLAGS"
75798 ripley 297
if test "${R_OSTYPE}" = "windows"; then
81375 kalibera 298
  ok_win_vars="LOCAL_SOFT R_TOOLS_SOFT COMPILED_BY OBJDUMP"
75798 ripley 299
fi
19165 hornik 300
 
71209 hornik 301
if test "${all}" = "yes"; then
302
  query="${MAKE} -s ${makefiles} print-name-and-value R_HOME=${R_HOME}"
75727 ripley 303
  for v in ${ok_c_vars} ${ok_cxx_vars} ${ok_dylib_vars} ${ok_ftn_vars} \
71209 hornik 304
	   ${ok_objc_vars} ${ok_java_vars} \
305
	   ${ok_ld_vars} ${ok_shlib_vars} ${ok_tcltk_vars} \
75798 ripley 306
	   ${ok_other_vars} ${ok_win_vars}; do
71209 hornik 307
    eval "${query} VAR=${v}"
308
  done
78359 ripley 309
  echo
310
  echo "## The following variables are defunct"
311
  echo ${defunct_vars}
71209 hornik 312
  exit 0
313
fi
314
 
19165 hornik 315
## Can we do this elegantly using case?
316
 
317
var_ok=no
75727 ripley 318
for v in ${ok_c_vars} ${ok_cxx_vars} ${ok_dylib_vars} ${ok_ftn_vars} \
46994 ripley 319
	 ${ok_objc_vars} ${ok_java_vars} \
320
	 ${ok_ld_vars} ${ok_shlib_vars} ${ok_tcltk_vars} \
75798 ripley 321
	 ${ok_other_vars} ${ok_win_vars}; do
19165 hornik 322
  if test "${var}" = "${v}"; then
323
    var_ok=yes
324
    break
325
  fi
326
done
327
 
78359 ripley 328
for v in ${defunct_vars}; do
77111 ripley 329
  if test "${var}" = "${v}"; then
330
    var_ok=yes
78359 ripley 331
    1>&2 echo "'config' variable '${v}' is defunct"
332
    exit 2
77111 ripley 333
  fi
334
done
77105 ripley 335
 
19165 hornik 336
if test "${var_ok}" = yes; then
337
  eval "${query} VAR=${var}"
338
else
339
  echo "ERROR: no information for variable '${var}'"
340
  exit 1
341
fi
342
 
343
### Local Variables: ***
344
### mode: sh ***
345
### sh-indentation: 2 ***
346
### End: ***