Branch data Line data Source code
1 : : /* m2configure.cc provides an interface to some configuration values.
2 : :
3 : : Copyright (C) 2022-2023 Free Software Foundation, Inc.
4 : : Contributed by Gaius Mulley <gaius@glam.ac.uk>.
5 : :
6 : : This file is part of GNU Modula-2.
7 : :
8 : : GNU Modula-2 is free software; you can redistribute it and/or modify
9 : : it under the terms of the GNU General Public License as published by
10 : : the Free Software Foundation; either version 3, or (at your option)
11 : : any later version.
12 : :
13 : : GNU Modula-2 is distributed in the hope that it will be useful, but
14 : : WITHOUT ANY WARRANTY; without even the implied warranty of
15 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 : : General Public License for more details.
17 : :
18 : : You should have received a copy of the GNU General Public License
19 : : along with GNU Modula-2; see the file COPYING3. If not see
20 : : <http://www.gnu.org/licenses/>. */
21 : :
22 : : #include "config.h"
23 : : #include "system.h"
24 : : #include "libiberty.h"
25 : :
26 : : #include "config.h"
27 : : #include "system.h"
28 : : #include "libiberty.h"
29 : :
30 : : #include "gcc-consolidation.h"
31 : :
32 : : #include "../gm2-lang.h"
33 : : #include "../m2-tree.h"
34 : : #include "m2convert.h"
35 : :
36 : : /* Prototypes. */
37 : :
38 : : #define m2configure_c
39 : :
40 : : #include "m2assert.h"
41 : : #include "m2builtins.h"
42 : : #include "m2convert.h"
43 : : #include "m2decl.h"
44 : : #include "m2expr.h"
45 : : #include "m2options.h"
46 : : #include "m2configure.h"
47 : :
48 : : #include "m2/gm2version.h"
49 : : #include "m2/gm2config.h"
50 : :
51 : : #define CPPPROGRAM "cc1"
52 : :
53 : :
54 : : /* gen_gm2_libexec returns a string containing libexec /
55 : : DEFAULT_TARGET_MACHINE string / DEFAULT_TARGET_MACHINE. */
56 : :
57 : : static char *
58 : 0 : gen_gm2_libexec (const char *libexec)
59 : : {
60 : 0 : int l = strlen (libexec) + 1 + strlen (DEFAULT_TARGET_MACHINE) + 1
61 : 0 : + strlen (DEFAULT_TARGET_VERSION) + 1;
62 : 0 : char *s = (char *)xmalloc (l);
63 : 0 : char dir_sep[2];
64 : :
65 : 0 : dir_sep[0] = DIR_SEPARATOR;
66 : 0 : dir_sep[1] = (char)0;
67 : :
68 : 0 : strcpy (s, libexec);
69 : 0 : strcat (s, dir_sep);
70 : 0 : strcat (s, DEFAULT_TARGET_MACHINE);
71 : 0 : strcat (s, dir_sep);
72 : 0 : strcat (s, DEFAULT_TARGET_VERSION);
73 : 0 : return s;
74 : : }
75 : :
76 : : /* FullPathCPP returns the fullpath and program name to cpp. */
77 : :
78 : : char *
79 : 1842 : m2configure_FullPathCPP (void)
80 : : {
81 : 1842 : if (M2Options_GetCpp ())
82 : : {
83 : 1842 : char *path = (char *) M2Options_GetB ();
84 : :
85 : 1842 : if (path == NULL)
86 : 0 : path = gen_gm2_libexec (STANDARD_LIBEXEC_PREFIX);
87 : :
88 : 1842 : if (strcmp (path, "") == 0)
89 : 0 : return xstrdup (CPPPROGRAM);
90 : :
91 : 1842 : char *full = (char *)xmalloc (strlen (path) + 1 + strlen (CPPPROGRAM) + 1);
92 : 1842 : strcpy (full, path);
93 : 1842 : char *sep = (char *)alloca (2);
94 : 1842 : sep[0] = DIR_SEPARATOR;
95 : 1842 : sep[1] = (char)0;
96 : 1842 : strcat (full, sep);
97 : 1842 : strcat (full, CPPPROGRAM);
98 : 1842 : return full;
99 : : }
100 : : return NULL;
101 : : }
|