Module Name: src Committed By: joerg Date: Wed Nov 11 19:03:53 UTC 2009
Modified Files: src/gnu/dist/gcc4/gcc: c-opts.c c.opt gcc.h src/gnu/dist/gcc4/gcc/doc: cpp.texi cppopts.texi invoke.texi src/gnu/dist/gcc4/libcpp: macro.c src/gnu/dist/gcc4/libcpp/include: cpplib.h src/gnu/usr.bin/gcc4/cpp: cpp.1 src/gnu/usr.bin/gcc4/gcc: gcc.1 Log Message: Add the -iremap option to gcc(1) and cpp(1). This option specifies a prefix transformation rule for __FILE__ and can be used to avoid hard-coding the location of the source tree in the resulting binary. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/gnu/dist/gcc4/gcc/c-opts.c cvs rdiff -u -r1.3 -r1.4 src/gnu/dist/gcc4/gcc/c.opt cvs rdiff -u -r1.2 -r1.3 src/gnu/dist/gcc4/gcc/gcc.h cvs rdiff -u -r1.4 -r1.5 src/gnu/dist/gcc4/gcc/doc/cpp.texi cvs rdiff -u -r1.2 -r1.3 src/gnu/dist/gcc4/gcc/doc/cppopts.texi cvs rdiff -u -r1.8 -r1.9 src/gnu/dist/gcc4/gcc/doc/invoke.texi cvs rdiff -u -r1.2 -r1.3 src/gnu/dist/gcc4/libcpp/macro.c cvs rdiff -u -r1.1.1.1 -r1.2 src/gnu/dist/gcc4/libcpp/include/cpplib.h cvs rdiff -u -r1.2 -r1.3 src/gnu/usr.bin/gcc4/cpp/cpp.1 cvs rdiff -u -r1.3 -r1.4 src/gnu/usr.bin/gcc4/gcc/gcc.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/gnu/dist/gcc4/gcc/c-opts.c diff -u src/gnu/dist/gcc4/gcc/c-opts.c:1.4 src/gnu/dist/gcc4/gcc/c-opts.c:1.5 --- src/gnu/dist/gcc4/gcc/c-opts.c:1.4 Thu Jun 21 04:02:00 2007 +++ src/gnu/dist/gcc4/gcc/c-opts.c Wed Nov 11 19:03:52 2009 @@ -163,6 +163,7 @@ case OPT_isysroot: case OPT_isystem: case OPT_iquote: + case OPT_iremap: error ("missing path after %qs", opt); break; @@ -841,6 +842,10 @@ add_path (xstrdup (arg), SYSTEM, 0, true); break; + case OPT_iremap: + add_cpp_remap_path (arg); + break; + case OPT_iwithprefix: add_prefixed_path (arg, SYSTEM); break; Index: src/gnu/dist/gcc4/gcc/c.opt diff -u src/gnu/dist/gcc4/gcc/c.opt:1.3 src/gnu/dist/gcc4/gcc/c.opt:1.4 --- src/gnu/dist/gcc4/gcc/c.opt:1.3 Thu Jun 21 04:02:00 2007 +++ src/gnu/dist/gcc4/gcc/c.opt Wed Nov 11 19:03:52 2009 @@ -783,6 +783,10 @@ C ObjC C++ ObjC++ Joined Separate -iquote <dir> Add <dir> to the end of the quote include path +iremap +C ObjC C++ ObjC++ Joined Separate +-iremap <src:dst> Convert <src> to <dst> if it occurs as prefix in __FILE__. + iwithprefix C ObjC C++ ObjC++ Joined Separate -iwithprefix <dir> Add <dir> to the end of the system include path Index: src/gnu/dist/gcc4/gcc/gcc.h diff -u src/gnu/dist/gcc4/gcc/gcc.h:1.2 src/gnu/dist/gcc4/gcc/gcc.h:1.3 --- src/gnu/dist/gcc4/gcc/gcc.h:1.2 Fri May 12 00:33:26 2006 +++ src/gnu/dist/gcc4/gcc/gcc.h Wed Nov 11 19:03:52 2009 @@ -50,7 +50,7 @@ || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \ || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \ || !strcmp (STR, "iquote") || !strcmp (STR, "isystem") \ - || !strcmp (STR, "isysroot") \ + || !strcmp (STR, "-iremap") || !strcmp (STR, "isysroot") \ || !strcmp (STR, "-param") || !strcmp (STR, "specs") \ || !strcmp (STR, "MF") || !strcmp (STR, "MT") || !strcmp (STR, "MQ")) Index: src/gnu/dist/gcc4/gcc/doc/cpp.texi diff -u src/gnu/dist/gcc4/gcc/doc/cpp.texi:1.4 src/gnu/dist/gcc4/gcc/doc/cpp.texi:1.5 --- src/gnu/dist/gcc4/gcc/doc/cpp.texi:1.4 Thu Jun 21 04:02:02 2007 +++ src/gnu/dist/gcc4/gcc/doc/cpp.texi Wed Nov 11 19:03:52 2009 @@ -4196,6 +4196,7 @@ @c man begin SYNOPSIS cpp [...@option{-d}@var{macro...@var{defn}]@dots{}] [...@option{-u}@var{macro}] [...@option{-i}@var{d...@dots{}] [...@option{-iquote}@var{d...@dots{}] + [...@option{-iremap}@var{src}:@var{dst}] [...@option{-w}@var{wa...@dots{}] [...@option{-m}|@option{-MM}] [...@option{-mg}] [...@option{-mf} @var{filename}] [...@option{-mp}] [...@option{-mq} @var{targ...@dots{}] Index: src/gnu/dist/gcc4/gcc/doc/cppopts.texi diff -u src/gnu/dist/gcc4/gcc/doc/cppopts.texi:1.2 src/gnu/dist/gcc4/gcc/doc/cppopts.texi:1.3 --- src/gnu/dist/gcc4/gcc/doc/cppopts.texi:1.2 Fri May 12 00:33:26 2006 +++ src/gnu/dist/gcc4/gcc/doc/cppopts.texi Wed Nov 11 19:03:52 2009 @@ -513,6 +513,12 @@ @xref{Search Path}. @end ifset +...@item -iremap @var{src}:@var{dst} +...@opindex iremap +Replace the prefix @var{src} in __FILE__ with @var{dst} at expansion time. +This option can be specified more than once. Processing stops at the first +match. + @item -fdollars-in-identifiers @opindex fdollars-in-identifiers @anchor{fdollars-in-identifiers} Index: src/gnu/dist/gcc4/gcc/doc/invoke.texi diff -u src/gnu/dist/gcc4/gcc/doc/invoke.texi:1.8 src/gnu/dist/gcc4/gcc/doc/invoke.texi:1.9 --- src/gnu/dist/gcc4/gcc/doc/invoke.texi:1.8 Wed Apr 29 23:53:28 2009 +++ src/gnu/dist/gcc4/gcc/doc/invoke.texi Wed Nov 11 19:03:52 2009 @@ -376,7 +376,8 @@ @item Directory Options @xref{Directory Options,,Options for Directory Search}. -...@gccoptlist{-b@var{prefix} -...@var{dir} -iqu...@var{dir} -...@var{dir} +...@gccoptlist{-b@var{prefix} -...@var{dir} -iqu...@var{dir} +-ire...@var{src}:@var{dst} -...@var{dir} -spe...@var{file} -I- --sysro...@var{dir}} @item Target Options @@ -6506,6 +6507,12 @@ "@var{file}"}; they are not searched for @samp{#include <@var{file}>}, otherwise just like @option{-I}. +...@item -iremap @var{src}:@var{dst} +...@opindex iremap +Replace the prefix @var{src} in __FILE__ with @var{dst} at expansion time. +This option can be specified more than once. Processing stops at the first +match. + @item -...@var{dir} @opindex L Add directory @var{dir} to the list of directories to be searched Index: src/gnu/dist/gcc4/libcpp/macro.c diff -u src/gnu/dist/gcc4/libcpp/macro.c:1.2 src/gnu/dist/gcc4/libcpp/macro.c:1.3 --- src/gnu/dist/gcc4/libcpp/macro.c:1.2 Fri May 30 15:12:24 2008 +++ src/gnu/dist/gcc4/libcpp/macro.c Wed Nov 11 19:03:52 2009 @@ -109,6 +109,61 @@ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; +static size_t remap_pairs; +static char **remap_src; +static char **remap_dst; + +void +add_cpp_remap_path (const char *arg) +{ + const char *arg_dst; + size_t len; + + arg_dst = strchr(arg, ':'); + if (arg_dst == NULL) { + fprintf(stderr, "Invalid argument for -iremap"); + exit(1); + } + len = arg_dst - arg; + ++arg_dst; + + remap_src = xrealloc(remap_src, sizeof(char *) * (remap_pairs + 1)); + remap_dst = xrealloc(remap_dst, sizeof(char *) * (remap_pairs + 1)); + + remap_src[remap_pairs] = xmalloc(len + 1); + memcpy(remap_src[remap_pairs], arg, len); + remap_src[remap_pairs][len] = '\0'; + remap_dst[remap_pairs] = xstrdup(arg_dst); + ++remap_pairs; +} + +static const char * +cpp_remap_file (const char *arg, char **tmp_name) +{ + char *result; + size_t i, len; + + for (i = 0; i < remap_pairs; ++i) { + len = strlen (remap_src[i]); + if (strncmp (remap_src[i], arg, len)) + continue; + if (arg[len] == '\0') + return xstrdup (remap_dst[i]); + if (arg[len] != '/') + continue; + arg += len; + len = strlen (remap_dst[i]); + result = xmalloc (len + strlen (arg) + 1); + memcpy(result, remap_dst[i], len); + strcpy(result + len, arg); + *tmp_name = result; + + return result; + } + + return arg; +} + /* Helper function for builtin_macro. Returns the text generated by a builtin macro. */ const uchar * @@ -130,6 +185,7 @@ { unsigned int len; const char *name; + char *tmp_name; uchar *buf; map = linemap_lookup (pfile->line_table, pfile->line_table->highest_line); @@ -137,12 +193,14 @@ while (! MAIN_FILE_P (map)) map = INCLUDED_FROM (pfile->line_table, map); - name = map->to_file; + tmp_name = NULL; + name = cpp_remap_file (map->to_file, &tmp_name); len = strlen (name); buf = _cpp_unaligned_alloc (pfile, len * 2 + 3); result = buf; *buf = '"'; buf = cpp_quote_string (buf + 1, (const unsigned char *) name, len); + free (tmp_name); *buf++ = '"'; *buf = '\0'; } Index: src/gnu/dist/gcc4/libcpp/include/cpplib.h diff -u src/gnu/dist/gcc4/libcpp/include/cpplib.h:1.1.1.1 src/gnu/dist/gcc4/libcpp/include/cpplib.h:1.2 --- src/gnu/dist/gcc4/libcpp/include/cpplib.h:1.1.1.1 Thu Apr 20 09:55:51 2006 +++ src/gnu/dist/gcc4/libcpp/include/cpplib.h Wed Nov 11 19:03:52 2009 @@ -623,6 +623,9 @@ /* Set the include paths. */ extern void cpp_set_include_chains (cpp_reader *, cpp_dir *, cpp_dir *, int); +/* Provide src:dst pair for __FILE__ remapping. */ +extern void add_cpp_remap_path (const char *); + /* Call these to get pointers to the options, callback, and deps structures for a given reader. These pointers are good until you call cpp_finish on that reader. You can either edit the callbacks Index: src/gnu/usr.bin/gcc4/cpp/cpp.1 diff -u src/gnu/usr.bin/gcc4/cpp/cpp.1:1.2 src/gnu/usr.bin/gcc4/cpp/cpp.1:1.3 --- src/gnu/usr.bin/gcc4/cpp/cpp.1:1.2 Thu Apr 30 00:45:47 2009 +++ src/gnu/usr.bin/gcc4/cpp/cpp.1 Wed Nov 11 19:03:53 2009 @@ -1,4 +1,4 @@ -.\" $NetBSD: cpp.1,v 1.2 2009/04/30 00:45:47 joerg Exp $ +.\" $NetBSD: cpp.1,v 1.3 2009/11/11 19:03:53 joerg Exp $ .Dd April 30, 2009 .Dt CPP 1 .Os @@ -11,6 +11,7 @@ .Op Fl U Ns Ar macro .Op Fl I Ns Ar dir... .Op Fl iquote Ns Ar dir... +.Op Fl iremap Ns Ar src Ns : Ns Ar dst .Op Fl W Ns Ar warn... .Op Fl M | Fl MM .Op Fl MG @@ -691,6 +692,16 @@ .Fl I and before the standard system directories. .Pp +.It Fl iremap Ns Ar src Ns : Ns Ar dst +Replace the prefix +.Ar src +in +.Va __FILE__ +with +.Ar dst +at expansion time. +This option can be specified more than once. +Processing stops at the first match. .It Fl fdollars-in-identifiers @anchor{fdollars-in-identifiers} Accept .Sy $ Index: src/gnu/usr.bin/gcc4/gcc/gcc.1 diff -u src/gnu/usr.bin/gcc4/gcc/gcc.1:1.3 src/gnu/usr.bin/gcc4/gcc/gcc.1:1.4 --- src/gnu/usr.bin/gcc4/gcc/gcc.1:1.3 Thu Apr 30 00:30:56 2009 +++ src/gnu/usr.bin/gcc4/gcc/gcc.1 Wed Nov 11 19:03:53 2009 @@ -1,4 +1,4 @@ -.\" $NetBSD: gcc.1,v 1.3 2009/04/30 00:30:56 joerg Exp $ +.\" $NetBSD: gcc.1,v 1.4 2009/11/11 19:03:53 joerg Exp $ .Dd April 30, 2009 .Dt GCC 1 .Os @@ -183,6 +183,7 @@ .Fl B Ns Ar prefix .Fl I Ns Ar dir .Fl iquote Ns Ar dir +.Fl iremap Ns Ar src Ns : Ns Ar dst .Fl L Ns Ar dir .Fl specs= Ns Ar file .Fl I- Fl -sysroot= Ns Ar dir @@ -6633,6 +6634,16 @@ .Fl I and before the standard system directories. .Pp +.It Fl iremap Ns Ar src Ns : Ns Ar dst +Replace the prefix +.Ar src +in +.Va __FILE__ +with +.Ar dst +at expansion time. +This option can be specified more than once. +Processing stops at the first match. .It Fl fdollars-in-identifiers @anchor{fdollars-in-identifiers} Accept .Sy $