mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-15 04:31:49 +08:00
3b4dbbbf59
* output-file.c (output_file_create): Make file name argument const. (output_file_close): Likewise. * output-file.h (output_file_create): Adjust. (output_file_close): Likewise. * depend.c (quote_string_for_make): Make src argument const char *. (register_dependency): Likewise. (wrap_output): Likewise. * as.h (register_dependency): Adjust. * config/tc-xtensa.c (finish_vinsn): Remove unnecessary calls to as_where (); * symbols.c (S_SET_EXTERNAL): Likewise. * input-scrub.c (as_where): Return the file name. * as.h (as_where): Adjust prototype. * app.c (do_scrub_chars): Adjust. * cond.c (s_elseif): Likewise. (s_else): Likewise. (initialize_cframe): Likewise. * config/obj-coff.c (obj_coff_init_stab_section): Likewise. * config/obj-elf.c (obj_elf_init_stab_section): Likewise. * config/obj-som.c (obj_som_init_stab_section): Likewise. * config/tc-aarch64.c (output_info): Likewise. * config/tc-ia64.c (md_assemble): Likewise. (dot_alias): Likewise. * config/tc-m68k.c (m68k_frob_label): Likewise. * config/tc-mmix.c (s_bspec): Likewise. (mmix_handle_mmixal): Likewise. * config/tc-rx.c (rx_include): Likewise. * config/tc-tic54x.c (tic54x_set_default_include): Likewise. (tic54x_adjust_symtab): Likewise. * config/tc-xtensa.c (directive_push): Likewise. (xtensa_sanity_check): Likewise. (xtensa_relax_frag): Likewise. (md_convert_frag): Likewise. (tinsn_to_slotbuf): Likewise. * dwarf2dbg.c (dwarf2_where): Likewise. * ecoff.c (add_file): Likewise. (ecoff_generate_asm_lineno): Likewise. * expr.c (make_expr_symbol): Likewise. * frags.c (frag_new): Likewise. (frag_var_init): Likewise. * listing.c (listing_newline): Likewise. * messages.c (identify): Likewise. (as_show_where): Likewise. (as_warn_internal): Likewise. (as_bad_internal): Likewise. * read.c (s_irp): Likewise. (s_macro): Likewise. (s_reloc): Likewise. * stabs.c (stabs_generate_asm_file): Likewise. (stabs_generate_asm_lineno): Likewise. (stabs_generate_asm_func): Likewise. * write.c (fix_new_internal): Likewise. * as.h (PRINTF_WHERE_LIKE): Make file name argument const. (as_warn_value_out_of_range): Adjust prototype. (as_bad_value_out_of_range): Adjust prototype. * messages.c (identify): Make file name argument const char *. (as_warn_internal): Likewise. (as_warn_where): Likewise. (as_bad_internal): Likewise. (as_bad_where): Likewise. (as_internal_value_out_of_range): Likewise. (as_warn_value_out_of_range): Likewise. (as_bad_value_out_of_range): Likewise. * as.h (found_comment_file): Change type to const char *. * cond.c (file_line::file): Likewise. * config/obj-coff.c (obj_coff_init_stab_section): Make variable const. * config/obj-elf.c (obj_elf_init_stab_section): Likewise. * config/obj-som.c (obj_som_init_stab_section): Likewise. * config/tc-aarch64.c (output_info): Likewise. * config/tc-alpha.c (insert_operand): Likewise. * config/tc-arc.c (insert_operand): Likewise. * config/tc-d30v.c (check_size): Likewise. * config/tc-ia64.c (struct alias): Likewise. * config/tc-m68k.c (struct label_line): Likewise. * config/tc-mcore.c (md_apply_fix): Likewise. * config/tc-microblaze.c (md_estimate_size_before_relax): Likewise. * config/tc-mips.c (mips16_immed): Likewise. * config/tc-mmix.c (mmix_handle_mmixal): Likewise. * config/tc-ppc.c (ppc_insert_operand): Likewise. * config/tc-rx.c (rx_include): Likewise. * config/tc-s390.c (s390_insert_operand): Likewise. * config/tc-tic54x.c (tic54x_set_default_include): Likewise. (tic54x_adjust_symtab): Likewise. * config/tc-tilegx.c (insert_operand): Likewise. (apply_special_operator): Likewise. * config/tc-tilepro.c (insert_operand): Likewise. * config/tc-xtensa.c (directive_push): Likewise. * ecoff.c (add_file): Likewise. (ecoff_generate_asm_lineno): Likewise. * listing.c (listing_newline): Likewise. * read.c (s_irp): Likewise. * write.c (install_reloc): Likewise. * write.h (struct fix): Likewise. * input-file.c (file_name): Change type to const char *. (saved_file::file_name): Likewise. (input_file_open): Change type of argument to const char *. * input-file.h (input_file_open): Adjust. * input-scrub.c (logical_input_file): change type to const char *. (physical_input_file): Likewise. (struct input_save): Adjust. (input_scrub_push): Adjust. (input_scrub_begin): Adjust. (as_where): Adjust. * input-scrub.c (input_scrub_new_file): Make file name argument const. (input_scrub_include_file): Likewise. (new_logical_line_flags): Likewise. (new_logical_line): Likewise. * as.h: Adjust. * frags.h (struct frag): Change type of fr_file to const char *. * expr.c (expr_symbol_where): Change type of file argument to const char **. * expr.h (expr_symbol_where): Likewise. * config/tc-i370.c (md_apply_fix): adjust. * config/tc-mmix.c (mmix_md_end): Likewise. * config/tc-ppc.c (md_apply_fix): Likewise. * config/tc-s390.c (md_apply_fix): Likewise. * symbols.c (report_op_error): Likewise. (resolve_symbol_value): Likewise. * config/tc-ia64.c (slot::src_file): Change type to const char *. (rsrc::file): Likewise. * config/tc-xtensa.c (xtensa_sanity_check): Change type of variable to const char *. (xtensa_relax_frag): Likewise. (md_convert_frag): Likewise. (tinsn_to_slotbuf): Likewise. * expr.c (expr_symbol_line): Likewise. * macro.c (define_macro): Likewise. * macro.h (macro_struct): Likewise. * messages.c (as_show_where): Likewise. * read.c (s_macro): Likewise. * stabs.c (stabs_generate_asm_file): Likewise. (generate_asm_file): Likewise. (stabs_generate_asm_lineno): Likewise. * write.h (struct reloc_list): Likewise. * input-scrub.c (as_where): Change return type to const char *. * as.h (as_wheree): Adjust.
208 lines
4.6 KiB
C
208 lines
4.6 KiB
C
/* depend.c - Handle dependency tracking.
|
||
Copyright (C) 1997-2016 Free Software Foundation, Inc.
|
||
|
||
This file is part of GAS, the GNU Assembler.
|
||
|
||
GAS is free software; you can redistribute it and/or modify
|
||
it under the terms of the GNU General Public License as published by
|
||
the Free Software Foundation; either version 3, or (at your option)
|
||
any later version.
|
||
|
||
GAS is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU General Public License for more details.
|
||
|
||
You should have received a copy of the GNU General Public License
|
||
along with GAS; see the file COPYING. If not, write to the Free
|
||
Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
|
||
02110-1301, USA. */
|
||
|
||
#include "as.h"
|
||
#include "filenames.h"
|
||
|
||
/* The file to write to, or NULL if no dependencies being kept. */
|
||
static char * dep_file = NULL;
|
||
|
||
struct dependency
|
||
{
|
||
char * file;
|
||
struct dependency * next;
|
||
};
|
||
|
||
/* All the files we depend on. */
|
||
static struct dependency * dep_chain = NULL;
|
||
|
||
/* Current column in output file. */
|
||
static int column = 0;
|
||
|
||
static int quote_string_for_make (FILE *, const char *);
|
||
static void wrap_output (FILE *, const char *, int);
|
||
|
||
/* Number of columns allowable. */
|
||
#define MAX_COLUMNS 72
|
||
|
||
/* Start saving dependencies, to be written to FILENAME. If this is
|
||
never called, then dependency tracking is simply skipped. */
|
||
|
||
void
|
||
start_dependencies (char *filename)
|
||
{
|
||
dep_file = filename;
|
||
}
|
||
|
||
/* Noticed a new filename, so try to register it. */
|
||
|
||
void
|
||
register_dependency (const char *filename)
|
||
{
|
||
struct dependency *dep;
|
||
|
||
if (dep_file == NULL)
|
||
return;
|
||
|
||
for (dep = dep_chain; dep != NULL; dep = dep->next)
|
||
{
|
||
if (!filename_cmp (filename, dep->file))
|
||
return;
|
||
}
|
||
|
||
dep = (struct dependency *) xmalloc (sizeof (struct dependency));
|
||
dep->file = xstrdup (filename);
|
||
dep->next = dep_chain;
|
||
dep_chain = dep;
|
||
}
|
||
|
||
/* Quote a file name the way `make' wants it, and print it to FILE.
|
||
If FILE is NULL, do no printing, but return the length of the
|
||
quoted string.
|
||
|
||
This code is taken from gcc with only minor changes. */
|
||
|
||
static int
|
||
quote_string_for_make (FILE *file, const char *src)
|
||
{
|
||
const char *p = src;
|
||
int i = 0;
|
||
|
||
for (;;)
|
||
{
|
||
char c = *p++;
|
||
|
||
switch (c)
|
||
{
|
||
case '\0':
|
||
case ' ':
|
||
case '\t':
|
||
{
|
||
/* GNU make uses a weird quoting scheme for white space.
|
||
A space or tab preceded by 2N+1 backslashes represents
|
||
N backslashes followed by space; a space or tab
|
||
preceded by 2N backslashes represents N backslashes at
|
||
the end of a file name; and backslashes in other
|
||
contexts should not be doubled. */
|
||
const char *q;
|
||
|
||
for (q = p - 1; src < q && q[-1] == '\\'; q--)
|
||
{
|
||
if (file)
|
||
putc ('\\', file);
|
||
i++;
|
||
}
|
||
}
|
||
if (!c)
|
||
return i;
|
||
if (file)
|
||
putc ('\\', file);
|
||
i++;
|
||
goto ordinary_char;
|
||
|
||
case '$':
|
||
if (file)
|
||
putc (c, file);
|
||
i++;
|
||
/* Fall through. This can mishandle things like "$(" but
|
||
there's no easy fix. */
|
||
default:
|
||
ordinary_char:
|
||
/* This can mishandle characters in the string "\0\n%*?[\\~";
|
||
exactly which chars are mishandled depends on the `make' version.
|
||
We know of no portable solution for this;
|
||
even GNU make 3.76.1 doesn't solve the problem entirely.
|
||
(Also, '\0' is mishandled due to our calling conventions.) */
|
||
if (file)
|
||
putc (c, file);
|
||
i++;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
/* Append some output to the file, keeping track of columns and doing
|
||
wrapping as necessary. */
|
||
|
||
static void
|
||
wrap_output (FILE *f, const char *string, int spacer)
|
||
{
|
||
int len = quote_string_for_make (NULL, string);
|
||
|
||
if (len == 0)
|
||
return;
|
||
|
||
if (column
|
||
&& (MAX_COLUMNS
|
||
- 1 /* spacer */
|
||
- 2 /* ` \' */
|
||
< column + len))
|
||
{
|
||
fprintf (f, " \\\n ");
|
||
column = 0;
|
||
if (spacer == ' ')
|
||
spacer = '\0';
|
||
}
|
||
|
||
if (spacer == ' ')
|
||
{
|
||
putc (spacer, f);
|
||
++column;
|
||
}
|
||
|
||
quote_string_for_make (f, string);
|
||
column += len;
|
||
|
||
if (spacer == ':')
|
||
{
|
||
putc (spacer, f);
|
||
++column;
|
||
}
|
||
}
|
||
|
||
/* Print dependency file. */
|
||
|
||
void
|
||
print_dependencies (void)
|
||
{
|
||
FILE *f;
|
||
struct dependency *dep;
|
||
|
||
if (dep_file == NULL)
|
||
return;
|
||
|
||
f = fopen (dep_file, FOPEN_WT);
|
||
if (f == NULL)
|
||
{
|
||
as_warn (_("can't open `%s' for writing"), dep_file);
|
||
return;
|
||
}
|
||
|
||
column = 0;
|
||
wrap_output (f, out_file_name, ':');
|
||
for (dep = dep_chain; dep != NULL; dep = dep->next)
|
||
wrap_output (f, dep->file, ' ');
|
||
|
||
putc ('\n', f);
|
||
|
||
if (fclose (f))
|
||
as_warn (_("can't close `%s'"), dep_file);
|
||
}
|