wrc: Add support for target options, and define _WIN64 for 64-bit builds.

This commit is contained in:
Alexandre Julliard 2010-09-29 20:13:28 +02:00
parent c6e1a0c81e
commit e6340f1652
2 changed files with 74 additions and 55 deletions

View File

@ -52,41 +52,32 @@
static const char usage[] =
"Usage: wrc [options...] [infile[.rc|.res]]\n"
" -D id[=val] Define preprocessor identifier id=val\n"
" -E Preprocess only\n"
" -F target Ignored for compatibility with windres\n"
" -h Prints this summary\n"
" -i file The name of the input file\n"
" -I path Set include search dir to path (multiple -I allowed)\n"
" -J format The input format (either `rc' or `rc16')\n"
" -l lan Set default language to lan (default is neutral {0, 0})\n"
" -o file Output to file (default is infile.res)\n"
" -O format The output format (either `res' or `res16`)\n"
" -r Ignored for compatibility with rc\n"
" -U id Undefine preprocessor identifier id\n"
" -v Enable verbose mode\n"
"The following long options are supported:\n"
" --debug=nn Set debug level to 'nn'\n"
" --define Synonym for -D\n"
" --endianess=e Set output byte-order e={n[ative], l[ittle], b[ig]}\n"
" (win32 only; default is " ENDIAN "-endian)\n"
" --help Synonym for -h\n"
" --include-dir Synonym for -I\n"
" --input Synonym for -i\n"
" --input-format Synonym for -J\n"
" --language Synonym for -l\n"
" --no-use-temp-file Ignored for compatibility with windres\n"
" --nostdinc Disables searching the standard include path\n"
" --output -fo Synonym for -o\n"
" --output-format Synonym for -O\n"
" --pedantic Enable pedantic warnings\n"
" --preprocessor Specifies the preprocessor to use, including arguments\n"
" --target Synonym for -F\n"
" --undefine Synonym for -U\n"
" --use-temp-file Ignored for compatibility with windres\n"
" --verbose Synonym for -v\n"
" --verify-translations Check the status of the various translations\n"
" --version Print version and exit\n"
" -b, --target=TARGET Specify target CPU and platform when cross-compiling\n"
" -D, --define id[=val] Define preprocessor identifier id=val\n"
" --debug=nn Set debug level to 'nn'\n"
" -E Preprocess only\n"
" --endianess=e Set output byte-order e={n[ative], l[ittle], b[ig]}\n"
" (win32 only; default is " ENDIAN "-endian)\n"
" -F TARGET Synonym for -b for compatibility with windres\n"
" -fo FILE Synonym for -o for compatibility with windres\n"
" -h, --help Prints this summary\n"
" -i, --input=FILE The name of the input file\n"
" -I, --include-dir=PATH Set include search dir to path (multiple -I allowed)\n"
" -J, --input-format=FORMAT The input format (either `rc' or `rc16')\n"
" -l, --language=LANG Set default language to LANG (default is neutral {0, 0})\n"
" -m16, -m32, -m64 Build for 16-bit, 32-bit resp. 64-bit platforms\n"
" --no-use-temp-file Ignored for compatibility with windres\n"
" --nostdinc Disables searching the standard include path\n"
" -o, --output=FILE Output to file (default is infile.res)\n"
" -O, --output-format=FORMAT The output format (either `res' or `res16`)\n"
" --pedantic Enable pedantic warnings\n"
" --preprocessor Specifies the preprocessor to use, including arguments\n"
" -r Ignored for compatibility with rc\n"
" -U, --undefine id Undefine preprocessor identifier id\n"
" --use-temp-file Ignored for compatibility with windres\n"
" -v, --verbose Enable verbose mode\n"
" --verify-translations Check the status of the various translations\n"
" --version Print version and exit\n"
"Input is taken from stdin if no sourcefile specified.\n"
"Debug level 'n' is a bitmask with following meaning:\n"
" * 0x01 Tell which resource is parsed (verbose mode)\n"
@ -153,6 +144,8 @@ int no_preprocess = 0;
int check_utf8 = 1; /* whether to check for valid utf8 */
static int pointer_size = sizeof(void *);
static int verify_translations_mode;
char *output_name = NULL; /* The name given by the -o option */
@ -187,7 +180,7 @@ enum long_options_values
};
static const char short_options[] =
"D:Ef:F:hi:I:J:l:o:O:rU:v";
"b:D:Ef:F:hi:I:J:l:m:o:O:rU:v";
static const struct option long_options[] = {
{ "debug", 1, NULL, LONG_OPT_DEBUG },
{ "define", 1, NULL, 'D' },
@ -320,6 +313,19 @@ static int load_file( const char *input_name, const char *output_name )
return ret;
}
static void set_target( const char *target )
{
char *p, *cpu = xstrdup( target );
/* target specification is in the form CPU-MANUFACTURER-OS or CPU-MANUFACTURER-KERNEL-OS */
if (!(p = strchr( cpu, '-' ))) error( "Invalid target specification '%s'\n", target );
*p = 0;
if (!strcmp( cpu, "amd64" ) || !strcmp( cpu, "x86_64" ) || !strcmp( cpu, "ia64" ))
pointer_size = 8;
else
pointer_size = 4;
free( cpu );
}
int main(int argc,char *argv[])
{
@ -346,8 +352,6 @@ int main(int argc,char *argv[])
/* Set the default defined stuff */
set_version_defines();
wpp_add_cmdline_define("RC_INVOKED=1");
wpp_add_cmdline_define("__WIN32__=1");
wpp_add_cmdline_define("__FLAT__=1");
/* Microsoft RC always searches current directory */
wpp_add_include_path(".");
@ -422,8 +426,9 @@ int main(int argc,char *argv[])
case 'E':
preprocess_only = 1;
break;
case 'b':
case 'F':
/* ignored for compatibility with windres */
set_target( optarg );
break;
case 'h':
printf(usage);
@ -447,6 +452,12 @@ int main(int argc,char *argv[])
defaultlanguage = new_language(PRIMARYLANGID(lan), SUBLANGID(lan));
}
break;
case 'm':
if (!strcmp( optarg, "16" )) win32 = 0;
else if (!strcmp( optarg, "32" )) { win32 = 1; pointer_size = 4; }
else if (!strcmp( optarg, "64" )) { win32 = 1; pointer_size = 8; }
else error( "Invalid option: -m%s\n", optarg );
break;
case 'f':
if (*optarg != 'o') error("Unknown option: -f%s\n", optarg);
optarg++;
@ -456,12 +467,7 @@ int main(int argc,char *argv[])
else error("Too many output files.\n");
break;
case 'O':
if (strcmp(optarg, "res16") == 0)
{
win32 = 0;
wpp_del_define("__WIN32__");
wpp_del_define("__FLAT__");
}
if (strcmp(optarg, "res16") == 0) win32 = 0;
else if (strcmp(optarg, "res")) warning("Output format %s not supported.\n", optarg);
break;
case 'r':
@ -485,6 +491,12 @@ int main(int argc,char *argv[])
return 1;
}
if (win32)
{
wpp_add_cmdline_define("_WIN32=1");
if (pointer_size == 8) wpp_add_cmdline_define("_WIN64=1");
}
/* If we do need to search standard includes, add them to the path */
if (stdinc)
{

View File

@ -21,6 +21,17 @@ specified with \fI-o\fR, then \fBwrc\fR will write the output to
no inputfile was given.
.SH OPTIONS
.TP
.BI \-b,\ --target= cpu-manufacturer[-kernel]-os
Specify the target CPU and platform on which the generated code will
be built. The target specification is in the standard autoconf format
as returned by config.sub.
.TP
.I \fB\-D\fR, \fB\-\-define\fR=\fIid[=val]\fR
Define preprocessor identifier \fIid\fR to (optionally) value \fIval\fR.
See also
.B PREPROCESSOR
below.
.TP
.I \fB\-\-debug\fR=\fInn\fR
Set debug level to \fInn\fR. The value is a bitmask consisting of
1=verbose, 2=dump internals, 4=resource parser trace, 8=preprocessor
@ -32,20 +43,11 @@ l[ittle] or b[ig]. Only resources in source-form can be reorderd. Native
ordering depends on the system on which \fBwrc\fR was built. You can see
the native ordering by typing \fIwrc \-h\fR.
.TP
.I \fB\-D\fR, \fB\-\-define\fR=\fIid[=val]\fR
Define preprocessor identifier \fIid\fR to (optionally) value \fIval\fR.
See also
.B PREPROCESSOR
below.
.TP
.I \fB\-E\fR
Preprocess only. The output is written to standard output if no
outputfile was selected. The output is compatible with what gcc would
generate.
.TP
.I \fB\-F\fR, \fB\-\-target\fR
Ignored for compatibility with \fIwindres\fR.
.TP
.I \fB\-h\fR, \fB\-\-help\fR
Prints a summary message and exits.
.TP
@ -73,6 +75,11 @@ input to 'rc16' disables the recognition of win32 keywords.
Set default language to \fIlan\fR. Default is the neutral language 0
(i.e. "LANGUAGE 0, 0").
.TP
.B \-m16, -m32, -m64
Generate resources for 16-bit, 32-bit, respectively 64-bit
platforms. The only difference between 32-bit and 64-bit is whether
the _WIN64 preprocessor symbol is defined.
.TP
.I \fB\-\-nostdinc\fR
Do not search the standard include path, look for include files only
in the directories explicitly specified with the \fI\-I\fR option.
@ -136,7 +143,7 @@ __WRC_MINOR__ Minor version of wrc
.br
__WRC_PATCHLEVEL__ Patch level
.PP
Win32 compilation mode also sets __WIN32__ to 1 and __FLAT__ to 1.
Win32 compilation mode also sets _WIN32 to 1.
.PP
Special macros __FILE__, __LINE__, __TIME__ and __DATE__ are also
recognized and expand to their respective equivalent.