remake  4.3+dbg-1.5
load.h
Go to the documentation of this file.
1 /* Read and evaluate a Makefile. */
2 /*
3 Copyright (C) 2020 R. Bernstein <rocky@gnu.org>
4 
5 This file is part of GNU Make (remake variant).
6 
7 GNU Make is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11 
12 GNU Make is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with GNU Make; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21 
22 #include <glob.h>
23 #include "read.h"
24 #include "filedef.h"
25 
26 static debug_return_t
27 dbg_cmd_load(char *psz_filename)
28 {
29  if (psz_filename && *psz_filename) {
30  glob_t p;
31  char *psz_expanded_file;
32  struct goaldep *p_goaldep;
33 
34  glob(psz_filename, 0, NULL, &p);
35  if (0 == p.gl_pathc) {
36  struct stat stat_buf;
37  int ret = stat(psz_filename, &stat_buf);
38  if (ret != 0) {
39  dbg_errmsg("Can't find file %s:\n\t%s", psz_filename, strerror(errno));
40  return debug_cmd_error;
41  }
42  psz_expanded_file = psz_filename;
43 
44  } else if (1 != p.gl_pathc) {
45  dbg_errmsg("Expansion of %s doesn't lead to a single filename. \n"
46  "Got %zu matches",
47  psz_filename, p.gl_pathc);
48  return debug_cmd_error;
49 
50  } else {
51  psz_expanded_file = p.gl_pathv[0];
52  }
53 
54  snapped_deps = 0;
55  p_goaldep = eval_makefile(psz_expanded_file, 0);
56 
57  if (p_goaldep == NULL) {
58  dbg_errmsg("error reading Makefile %s (expanded to %s):",
59  psz_filename, psz_expanded_file);
60  snapped_deps = 1;
61  return debug_cmd_error;
62  } else {
63  snap_deps();
64  free_goaldep(p_goaldep);
65  }
66  globfree(&p);
67  } else {
68  dbg_errmsg("load command expects a filename");
69  }
70  return debug_readloop;
71 }
72 
73 static void
74 dbg_cmd_load_init(unsigned int c)
75 {
76  short_command[c].func = &dbg_cmd_load;
77  short_command[c].use = _("load *Makefile*");
78 }
79 
80 
81 /*
82  * Local variables:
83  * eval: (c-set-style "gnu")
84  * indent-tabs-mode: nil
85  * End:
86  */
void dbg_errmsg()
struct goaldep * eval_makefile(const char *filename, unsigned short flags)
debug_return_t
Definition: trace.h:32
#define _(msgid)
Definition: make.h:293
Definition: trace.h:40
int snapped_deps
int errno
Definition: dep.h:69
void snap_deps(void)
Definition: trace.h:42
#define free_goaldep(_g)
Definition: dep.h:131