21 #include "../../dep.h" 24 dbg_cmd_write(
char *psz_args)
27 const char *psz_target = NULL;
33 char *psz_filename = NULL;
38 printf(
_(
"Target \"%s\" doesn't have commands associated with it.\n"),
47 if (psz_args && *psz_args) {
48 if (strcmp (psz_args,
"here") == 0)
51 psz_filename = strdup(psz_args);
54 char *psz_target_basename = strrchr(psz_target,
'/');
55 if (!psz_target_basename)
56 psz_target_basename = (
char *) psz_target;
58 psz_target_basename++;
59 psz_filename =
CALLOC(
char, strlen(psz_target_basename) + 10);
60 snprintf(psz_filename, MAX_FILE_LENGTH,
"/tmp/%s.sh",
78 if (!
isblank ((
unsigned char)*s))
86 printf(
_(
"Null command string parsed\n"));
93 else if (!(outfd = fopen (psz_filename,
"w"))) {
94 perror (
"write target");
118 "## %s:%s", p_target->
name,
122 for (d = p_target->
deps; d != 0; d = d->next)
123 if (! d->ignore_mtime) {
124 fprintf (outfd,
" %s",
dep_name (d));
131 fprintf (outfd,
" | %s",
dep_name (ood));
132 for (d = ood->next; d != 0; d = d->next)
134 fprintf (outfd,
" %s",
dep_name (d));
137 fprintf (outfd,
"\n");
141 if (
getcwd (wd,
sizeof(wd))) {
142 fprintf(outfd,
"\n#cd %s\n", wd);
154 memcpy(&cmds, p_target->
cmds,
sizeof(cmds));
158 expand_command_lines(&cmds, lines, p_target);
161 fprintf (outfd,
"%s\n", lines[i]);
167 fprintf (outfd,
"%s\n", line);
174 if (0 == fstat(fileno(outfd), &buf)) {
175 mode_t mode = buf.st_mode;
176 if (buf.st_mode & S_IRUSR) mode |= S_IXUSR;
177 if (buf.st_mode & S_IRGRP) mode |= S_IXGRP;
178 if (buf.st_mode & S_IROTH) mode |= S_IXOTH;
179 if (0 != fchmod(fileno(outfd), mode)) {
180 printf(
_(
"Can't set execute mode on \"%s\".\n"), psz_filename);
184 printf(
_(
"File \"%s\" written.\n"), psz_filename);
193 dbg_cmd_write_init(
unsigned int c)
195 short_command[c].func = &dbg_cmd_write;
196 short_command[c].use =
_(
"write [TARGET [FILENAME]]");
char * allocated_variable_expand_for_file(const char *psz_line, file_t *p_file)
const char * name
Definition: filedef.h:36
char * value
Definition: variable.h:59
char * starting_directory
#define isblank(c)
Definition: make.h:91
Definition: commands.h:27
#define CALLOC(t, n)
Definition: types.h:83
gmk_floc floc
Definition: filedef.h:39
char * commands
Definition: commands.h:30
unsigned short ncommand_lines
Definition: commands.h:33
struct commands * cmds
Definition: filedef.h:46
struct file * double_colon
Definition: filedef.h:72
struct variable * lookup_variable(const char *name, size_t length)
debug_return_t
Definition: trace.h:32
struct dep * deps
Definition: filedef.h:45
char ** command_lines
Definition: commands.h:31
#define _(msgid)
Definition: make.h:293
unsigned long lineno
Definition: gnuremake.h:26
file_t * get_target(char **ppsz_args, const char **ppsz_target)
void initialize_file_variables(struct file *file, int reading)
void chop_commands(struct commands *cmds)
const char * filenm
Definition: gnuremake.h:25
void set_file_variables(struct file *file)
gmk_floc fileinfo
Definition: commands.h:29
#define dep_name(d)
Definition: dep.h:104
char * variable_expand(const char *line)
Definition: variable.h:56