The R Project SVN R

Rev

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

Rev Author Line No. Line
19165 hornik 1
#! /bin/sh
2
 
3
## config -- Simple shell script to get the values of basic R configure
4
## variables, or the header and library flags necessary for linking
5
## against R.
6
##
7
## Usage:
8
##   R CMD config [options] [VAR]
9
 
10
## Copyright (C) 2002 The R Core Development Team
11
##
12
## This document is free software; you can redistribute it and/or modify
13
## it under the terms of the GNU General Public License as published by
14
## the Free Software Foundation; either version 2, or (at your option)
15
## any later version.
16
##
17
## This program is distributed in the hope that it will be useful, but
18
## WITHOUT ANY WARRANTY; without even the implied warranty of
19
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20
## General Public License for more details.
21
##
22
## A copy of the GNU General Public License is available via WWW at
23
## http://www.gnu.org/copyleft/gpl.html.  You can also obtain it by
24
## writing to the Free Software Foundation, Inc., 59 Temple Place,
25
## Suite 330, Boston, MA  02111-1307, U.S.A.
26
 
23685 hornik 27
revision='$Revision: 1.2 $'
19165 hornik 28
version=`set - ${revision}; echo ${2}`
29
version="R configuration information retrieval script ${version}
30
 
31
Copyright (C) 2002 The R Core Development Team.
32
This is free software; see the GNU General Public Licence version 2
33
or later for copying conditions.  There is NO warranty."
34
 
35
usage="Usage: R CMD config [options] [VAR]
36
 
37
Get the value of a basic R configure variable VAR which must be among
38
those listed in the 'Variables' section below, or the header and
39
library flags necessary for linking against R.
40
 
41
Options:
42
  -h, --help            print short help message and exit
43
  -v, --version         print version info and exit
44
      --cppflags        print pre-processor flags required to compile
45
                        a program using R as a shared library
46
      --ldflags         print linker flags needed for linking against
47
                        the R shared library
48
 
49
Variables:
50
  CC                    C compiler command
51
  CFLAGS                C compiler flags
52
  CPICFLAGS             special flags for compiling C code to be turned
53
                        into a shared library
54
  CPP                   C preprocessor
55
  CPPFLAGS              C/C++ preprocessor flags, e.g. -I<dir> if you
56
                        have headers in a nonstandard directory <dir>
57
  CXX                   C++ compiler command
58
  CXXCPP                C++ preprocessor
59
  CXXFLAGS              C++ compiler flags
60
  CXXPICFLAGS           special flags for compiling C++ code to be
61
                        turned into a shared library
62
  F2C                   FORTRAN-to-C converter command
63
  F77                   Fortran 77 compiler command
64
  FFLAGS                Fortran 77 compiler flags
65
  FLIBS                 linker flags needed to link FORTRAN code
66
  FPICFLAGS             special flags for compiling FORTRAN code to be
67
                        turned into a shared library
68
  LDFLAGS               linker flags, e.g. -L<dir> if you have libraries
69
                        in a nonstandard directory <dir>
70
  MAKE                  Make command
71
  SHLIB_CFLAGS          additional CFLAGS used when building shared
72
                        libraries
73
  SHLIB_CXXLD           command for linking shared libraries which
74
                        contain object files from a C++ compiler
75
  SHLIB_CXXLDFLAGS      special flags used by SHLIB_CXXLD
76
  SHLIB_FFLAGS          additional FFLAGS used when building shared
77
                        libraries 
78
  SHLIB_LD              command for linking shared libraries which
79
                        contain object files from a C or FORTRAN
80
                        compiler only 
81
  SHLIB_LDFLAGS         special flags used by SHLIB_LD
82
  BLAS_LIBS             linker flags for the BLAS libraries used when
83
                        building R (empty if none were used)
84
  TCLTK_CPPFLAGS        flags needed for finding the tcl.h and tk.h headers
85
  TCLTK_LIBS            flags needed for linking against the Tcl and Tk
86
                        libraries
87
 
88
Report bugs to <r-bugs@r-project.org>."
89
 
90
## <NOTE>
91
## The variables are basically the precious configure variables (with
92
## the R_* and MAIN_* ones removed), plus FLIBS and BLAS_LIBS.
93
## One could use
94
##   precious_configure_vars=`~/src/R/configure --help \
95
##     | sed -n '/^Some influential/,/^[^ ]/p' \
96
##     | sed '/^[^ ]/d' \
97
##     | sed 's/^  //' \
98
##     | cut -f1 -d ' ' \
99
##     | sort \
100
##     | uniq`
101
## to obtain the configure vars and hence create most of the above usage
102
## info as well as the list ok accepted variables below automatically.
103
 
104
makefiles="-f ${R_HOME}/etc/Makeconf -f ${R_HOME}/share/make/config.mk"
23685 hornik 105
query="${MAKE} -s ${makefiles} print R_HOME=${R_HOME}"
19165 hornik 106
 
107
LIBR=`eval $query VAR=LIBR`
108
 
109
var=
110
while test -n "${1}"; do
111
  case "${1}" in
112
    -h|--help)
113
      echo "${usage}"; exit 0 ;;
114
    -v|--version)
115
      echo "${version}"; exit 0 ;;
116
    --cppflags)
117
      if test -z "${LIBR}"; then
118
        echo "R was not built as a shared library" >&2
119
      else
120
        echo "-I${R_HOME}/include"
121
      fi
122
      exit 0
123
      ;;
124
    --ldflags)
125
      if test -z "${LIBR}"; then
126
        echo "R was not built as a shared library" >&2
127
      else
128
        echo "${LIBR}"
129
      fi
130
      exit 0
131
      ;;
132
    *)
133
      if test -z "${var}"; then
134
        var="${1}"
135
      else
136
        echo "ERROR: cannot query more than one variable" >&2
137
        exit 1
138
      fi
139
      ;;
140
  esac
141
  shift
142
done
143
 
144
ok_c_vars="CC CFLAGS CPICFLAGS CPP CPPFLAGS"
145
ok_cxx_vars="CXX CXXCPP CXXFLAGS CXXPICFLAGS"
146
ok_f77_vars="F2C F77 FFLAGS FPICFLAGS FLIBS"
147
ok_ld_vars="LDFLAGS"
148
ok_shlib_vars="SHLIB_CFLAGS SHLIB_CXXLD SHLIB_CXXLDFLAGS SHLIB_FFLAGS SHLIB_LD SHLIB_LDFLAGS"
149
ok_tcltk_vars="TCLTK_CPPFLAGS TCLTK_LIBS"
150
ok_other_vars="BLAS_LIBS MAKE"
151
 
152
## Can we do this elegantly using case?
153
 
154
var_ok=no
155
for v in ${ok_c_vars} ${ok_cxx_vars} ${ok_f77_vars} ${ok_ld_vars} \
156
         ${ok_shlib_vars} ${ok_tcltk_vars} ${ok_other_vars}; do
157
  if test "${var}" = "${v}"; then
158
    var_ok=yes
159
    break
160
  fi
161
done
162
 
163
if test "${var_ok}" = yes; then
164
  eval "${query} VAR=${var}"
165
else
166
  echo "ERROR: no information for variable '${var}'"
167
  exit 1
168
fi
169
 
170
### Local Variables: ***
171
### mode: sh ***
172
### sh-indentation: 2 ***
173
### End: ***