GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
octave-config.in.cc
Go to the documentation of this file.
1 // %NO_EDIT_WARNING%
2 
3 ////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (C) 2008-2021 The Octave Project Developers
6 //
7 // See the file COPYRIGHT.md in the top-level directory of this
8 // distribution or <https://octave.org/copyright/>.
9 //
10 // This file is part of Octave.
11 //
12 // Octave is free software: you can redistribute it and/or modify it
13 // under the terms of the GNU General Public License as published by
14 // the Free Software Foundation, either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // Octave 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
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with Octave; see the file COPYING. If not, see
24 // <https://www.gnu.org/licenses/>.
25 //
26 ////////////////////////////////////////////////////////////////////////
27 
28 #if defined (HAVE_CONFIG_H)
29 # include "config.h"
30 #endif
31 
32 #include <string>
33 #include <map>
34 #include <iostream>
35 #include <algorithm>
36 #include <cstdlib>
37 
38 #if ! defined (OCTAVE_PREFIX)
39 # define OCTAVE_PREFIX %OCTAVE_PREFIX%
40 #endif
41 
42 #if ! defined (OCTAVE_EXEC_PREFIX)
43 # define OCTAVE_EXEC_PREFIX %OCTAVE_EXEC_PREFIX%
44 #endif
45 
46 #ifndef OCTAVE_UNUSED
47 # define OCTAVE_UNUSED
48 #endif
49 
50 #include "shared-fcns.h"
51 
52 static std::map<std::string,std::string> vars;
53 
54 static std::string usage_msg = "usage: octave-config [options]";
55 
56 static std::string help_msg =
57  "\n"
58  "Options:\n"
59  "\n"
60  " -h, -?, --help Print this message.\n"
61  "\n"
62  " --m-site-dir Print the name of the directory where Octave\n"
63  " expects to find locally installed .m files.\n"
64  "\n"
65  " --oct-site-dir Print the name of the directory where Octave\n"
66  " expects to find locally installed .oct files.\n"
67  "\n"
68  " -p VAR, --print VAR Print the value of the given configuration\n"
69  " variable VAR. Recognized variables are:\n"
70  "\n"
71  " API_VERSION LOCALFCNFILEDIR\n"
72  " ARCHLIBDIR LOCALOCTFILEDIR\n"
73  " BINDIR LOCALSTARTUPFILEDIR\n"
74  " CANONICAL_HOST_TYPE LOCALVERARCHLIBDIR\n"
75  " DATADIR LOCALVERFCNFILEDIR\n"
76  " DATAROOTDIR LOCALVEROCTFILEDIR\n"
77  " DEFAULT_PAGER MAN1DIR\n"
78  " EXEC_PREFIX MAN1EXT\n"
79  " EXEEXT MANDIR\n"
80  " FCNFILEDIR OCTAVE_EXEC_HOME\n"
81  " IMAGEDIR OCTAVE_HOME\n"
82  " INCLUDEDIR OCTDATADIR\n"
83  " INFODIR OCTDOCDIR\n"
84  " INFOFILE OCTFILEDIR\n"
85  " LIBDIR OCTFONTSDIR\n"
86  " LIBEXECDIR OCTINCLUDEDIR\n"
87  " LOCALAPIARCHLIBDIR OCTLIBDIR\n"
88  " LOCALAPIFCNFILEDIR STARTUPFILEDIR\n"
89  " LOCALAPIOCTFILEDIR VERSION\n"
90  " LOCALARCHLIBDIR\n"
91  "\n"
92  " -v, --version Print the Octave version number.\n"
93  "\n";
94 
95 static void
96 initialize (void)
97 {
98  set_octave_home ();
99 
100  vars["OCTAVE_HOME"] = Voctave_home;
101  vars["OCTAVE_EXEC_HOME"] = Voctave_exec_home;
102 
103  vars["API_VERSION"] = %OCTAVE_API_VERSION%;
104  vars["CANONICAL_HOST_TYPE"] = %OCTAVE_CANONICAL_HOST_TYPE%;
105  vars["DEFAULT_PAGER"] = %OCTAVE_DEFAULT_PAGER%;
106  vars["EXEEXT"] = %OCTAVE_EXEEXT%;
107  vars["MAN1EXT"] = %OCTAVE_MAN1EXT%;
108  vars["VERSION"] = %OCTAVE_VERSION%;
109 
110  vars["ARCHLIBDIR"] = prepend_octave_exec_home (%OCTAVE_ARCHLIBDIR%);
112  vars["DATADIR"] = prepend_octave_home (%OCTAVE_DATADIR%);
113  vars["DATAROOTDIR"] = prepend_octave_home (%OCTAVE_DATAROOTDIR%);
114  vars["FCNFILEDIR"] = prepend_octave_home (%OCTAVE_FCNFILEDIR%);
115  vars["IMAGEDIR"] = prepend_octave_home (%OCTAVE_IMAGEDIR%);
116  vars["INCLUDEDIR"] = prepend_octave_home (%OCTAVE_INCLUDEDIR%);
117  vars["INFODIR"] = prepend_octave_home (%OCTAVE_INFODIR%);
118  vars["INFOFILE"] = prepend_octave_home (%OCTAVE_INFOFILE%);
120  vars["LIBEXECDIR"] = prepend_octave_exec_home (%OCTAVE_LIBEXECDIR%);
121  vars["LOCALAPIARCHLIBDIR"] = prepend_octave_exec_home (%OCTAVE_LOCALAPIARCHLIBDIR%);
122  vars["LOCALAPIFCNFILEDIR"] = prepend_octave_home (%OCTAVE_LOCALAPIFCNFILEDIR%);
123  vars["LOCALAPIOCTFILEDIR"] = prepend_octave_exec_home (%OCTAVE_LOCALAPIOCTFILEDIR%);
124  vars["LOCALARCHLIBDIR"] = prepend_octave_exec_home (%OCTAVE_LOCALARCHLIBDIR%);
125  vars["LOCALFCNFILEDIR"] = prepend_octave_home (%OCTAVE_LOCALFCNFILEDIR%);
126  vars["LOCALOCTFILEDIR"] = prepend_octave_exec_home (%OCTAVE_LOCALOCTFILEDIR%);
127  vars["LOCALSTARTUPFILEDIR"] = prepend_octave_home (%OCTAVE_LOCALSTARTUPFILEDIR%);
128  vars["LOCALVERARCHLIBDIR"] = prepend_octave_exec_home (%OCTAVE_LOCALVERARCHLIBDIR%);
129  vars["LOCALVERFCNFILEDIR"] = prepend_octave_home (%OCTAVE_LOCALVERFCNFILEDIR%);
130  vars["LOCALVEROCTFILEDIR"] = prepend_octave_exec_home (%OCTAVE_LOCALVEROCTFILEDIR%);
131  vars["MAN1DIR"] = prepend_octave_home (%OCTAVE_MAN1DIR%);
132  vars["MANDIR"] = prepend_octave_home (%OCTAVE_MANDIR%);
133  vars["OCTDATADIR"] = prepend_octave_home (%OCTAVE_OCTDATADIR%);
134  vars["OCTDOCDIR"] = prepend_octave_home (%OCTAVE_OCTDOCDIR%);
135  vars["OCTFILEDIR"] = prepend_octave_exec_home (%OCTAVE_OCTFILEDIR%);
136  vars["OCTFONTSDIR"] = prepend_octave_home (%OCTAVE_OCTFONTSDIR%);
137  vars["OCTINCLUDEDIR"] = prepend_octave_home (%OCTAVE_OCTINCLUDEDIR%);
139  vars["STARTUPFILEDIR"] = prepend_octave_home (%OCTAVE_STARTUPFILEDIR%);
140 }
141 
142 int
143 main (int argc, char **argv)
144 {
145  initialize ();
146 
147  if (argc == 1)
148  {
149  std::cout << usage_msg << std::endl;
150  return 1;
151  }
152 
153  for (int i = 1; i < argc; i++)
154  {
155  std::string arg (argv[i]);
156 
157  if (arg == "-h" || arg == "-?" || arg == "--help")
158  {
159  std::cout << usage_msg << std::endl;
160  std::cout << help_msg;
161  return 0;
162  }
163  else if (arg == "--m-site-dir")
164  std::cout << vars["LOCALVERFCNFILEDIR"] << std::endl;
165  else if (arg == "--oct-site-dir")
166  std::cout << vars["LOCALVEROCTFILEDIR"] << std::endl;
167  else if (arg == "-v" || arg == "--version")
168  std::cout << vars["VERSION"] << std::endl;
169  else if (arg == "-p" || arg == "--print")
170  {
171  if (i < argc-1)
172  {
173  arg = argv[++i];
174  std::cout << vars[arg] << std::endl;
175  }
176  else
177  {
178  std::cerr << "octave-config: " << arg
179  << " options requires argument" << std::endl;
180  return 1;
181  }
182  }
183  else
184  {
185  std::cerr << "octave-config: unrecognized argument " << arg
186  << std::endl;
187  return 1;
188  }
189  }
190 
191  return 0;
192 }
#define OCTAVE_OCTLIBDIR
#define OCTAVE_LOCALSTARTUPFILEDIR
#define OCTAVE_LOCALVERFCNFILEDIR
#define OCTAVE_OCTINCLUDEDIR
#define OCTAVE_LOCALAPIOCTFILEDIR
#define OCTAVE_OCTDOCDIR
#define OCTAVE_LIBEXECDIR
#define OCTAVE_INFOFILE
#define OCTAVE_LOCALVEROCTFILEDIR
#define OCTAVE_OCTFONTSDIR
#define OCTAVE_OCTDATADIR
#define OCTAVE_FCNFILEDIR
#define OCTAVE_MAN1EXT
#define OCTAVE_LOCALOCTFILEDIR
#define OCTAVE_LIBDIR
#define OCTAVE_MANDIR
#define OCTAVE_LOCALAPIARCHLIBDIR
#define OCTAVE_STARTUPFILEDIR
#define OCTAVE_INFODIR
#define OCTAVE_INCLUDEDIR
#define OCTAVE_DEFAULT_PAGER
#define OCTAVE_OCTFILEDIR
#define OCTAVE_LOCALARCHLIBDIR
#define OCTAVE_LOCALVERARCHLIBDIR
#define OCTAVE_IMAGEDIR
#define OCTAVE_LOCALFCNFILEDIR
#define OCTAVE_LOCALAPIFCNFILEDIR
#define OCTAVE_MAN1DIR
#define OCTAVE_DATADIR
#define OCTAVE_DATAROOTDIR
#define OCTAVE_BINDIR
Definition: main.in.cc:60
#define OCTAVE_ARCHLIBDIR
Definition: main.in.cc:56
#define OCTAVE_VERSION
Definition: main.in.cc:52
static std::string help_msg
static std::map< std::string, std::string > vars
int main(int argc, char **argv)
static void initialize(void)
static std::string usage_msg
static std::string Voctave_home
Definition: shared-fcns.h:101
static void set_octave_home(void)
Definition: shared-fcns.h:105
static std::string prepend_octave_exec_home(const std::string &s)
Definition: shared-fcns.h:189
static std::string Voctave_exec_home
Definition: shared-fcns.h:102
static OCTAVE_UNUSED std::string prepend_octave_home(const std::string &s)
Definition: shared-fcns.h:183
#define OCTAVE_CANONICAL_HOST_TYPE
Definition: version.in.h:53
#define OCTAVE_API_VERSION
Definition: version.in.h:49