From 08956bc9bb0ac54c04f300c9b9a2911665fe6227 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Mon, 23 Sep 2019 13:43:18 +0200 Subject: [PATCH] winegcc: Add --wine-objdir and --winebuild options for the Wine build. This avoids overloading the meaning of the -B and --sysroot options. Signed-off-by: Alexandre Julliard --- tools/makedep.c | 9 ++++- tools/winegcc/winegcc.c | 74 +++++++++++++++++++++--------------- tools/winegcc/winegcc.man.in | 22 +++++------ 3 files changed, 60 insertions(+), 45 deletions(-) diff --git a/tools/makedep.c b/tools/makedep.c index e37bd8d63a9..67dfea43bb3 100644 --- a/tools/makedep.c +++ b/tools/makedep.c @@ -2321,8 +2321,13 @@ static struct strarray get_source_defines( struct makefile *make, struct incl_fi static void output_winegcc_command( struct makefile *make ) { output( "\t%s -o $@", tools_path( make, "winegcc" )); - output_filename( strmake( "-B%s", tools_dir_path( make, "winebuild" ))); - if (tools_dir) output_filename( strmake( "--sysroot=%s", top_obj_dir_path( make, "" ))); + output_filename( "--wine-objdir" ); + output_filename( top_obj_dir_path( make, "" )); + if (tools_dir) + { + output_filename( "--winebuild" ); + output_filename( tools_path( make, "winebuild" )); + } if (make->is_cross) { output_filename( "-b" ); diff --git a/tools/winegcc/winegcc.c b/tools/winegcc/winegcc.c index 506096795e6..1af94ca63be 100644 --- a/tools/winegcc/winegcc.c +++ b/tools/winegcc/winegcc.c @@ -210,6 +210,7 @@ struct options int strip; int pic; const char* wine_objdir; + const char* winebuild; const char* output_name; const char* image_base; const char* section_align; @@ -845,11 +846,17 @@ static const char* compile_to_object(struct options* opts, const char* file, con static strarray *get_winebuild_args(struct options *opts) { const char* winebuild = getenv("WINEBUILD"); + const char *binary = NULL; strarray *spec_args = strarray_alloc(); unsigned int i; - if (!winebuild) winebuild = "winebuild"; - strarray_add( spec_args, find_binary( opts->prefix, winebuild )); + if (opts->winebuild) + binary = opts->winebuild; + else if (opts->wine_objdir) + binary = strmake( "%s/tools/winebuild/winebuild%s", opts->wine_objdir, EXEEXT ); + else + binary = find_binary( opts->prefix, winebuild ? winebuild : "winebuild" ); + strarray_add( spec_args, binary ); if (verbose) strarray_add( spec_args, "-v" ); if (keep_generated) strarray_add( spec_args, "--save-temps" ); if (opts->target) @@ -860,10 +867,7 @@ static strarray *get_winebuild_args(struct options *opts) if (opts->prefix) { for (i = 0; i < opts->prefix->size; i++) - { - if (strendswith( opts->prefix->base[i], "/tools/winebuild" )) continue; strarray_add( spec_args, strmake( "-B%s", opts->prefix->base[i] )); - } } if (!opts->use_msvcrt) strarray_add( spec_args, "-munix" ); if (opts->unwind_tables) strarray_add( spec_args, "-fasynchronous-unwind-tables" ); @@ -1352,6 +1356,22 @@ static void parse_target_option( struct options *opts, const char *target ) opts->target = xstrdup( target ); } +static int is_option( char **argv, int i, const char *option, const char **option_arg ) +{ + if (!strcmp( argv[i], option )) + { + if (!argv[i + 1]) error( "option %s requires an argument\n", argv[i] ); + *option_arg = argv[i + 1]; + return 1; + } + if (!strncmp( argv[i], option, strlen(option) ) && argv[i][strlen(option)] == '=') + { + *option_arg = argv[i] + strlen(option) + 1; + return 1; + } + return 0; +} + int main(int argc, char **argv) { int i, c, next_is_arg = 0, linking = 1; @@ -1438,6 +1458,8 @@ int main(int argc, char **argv) next_is_arg = (strcmp("--param", argv[i]) == 0 || strcmp("--sysroot", argv[i]) == 0 || strcmp("--target", argv[i]) == 0 || + strcmp("--wine-objdir", argv[i]) == 0 || + strcmp("--winebuild", argv[i]) == 0 || strcmp("--lib-suffix", argv[i]) == 0); break; } @@ -1474,19 +1496,6 @@ int main(int argc, char **argv) case 'B': str = strdup(option_arg); if (strendswith(str, "/")) str[strlen(str) - 1] = 0; - if (strendswith(str, "/tools/winebuild")) - { - char *objdir = strdup(str); - objdir[strlen(objdir) - sizeof("/tools/winebuild") + 1] = 0; - opts.wine_objdir = objdir; - /* don't pass it to the compiler, this generates warnings */ - raw_compiler_arg = raw_linker_arg = 0; - } - else if (!strcmp(str, "tools/winebuild")) - { - opts.wine_objdir = "."; - raw_compiler_arg = raw_linker_arg = 0; - } if (!opts.prefix) opts.prefix = strarray_alloc(); strarray_add(opts.prefix, str); break; @@ -1659,22 +1668,26 @@ int main(int argc, char **argv) case '-': if (strcmp("-static", argv[i]+1) == 0) linking = -1; - else if (!strncmp("--sysroot", argv[i], 9)) + else if (is_option( argv, i, "--sysroot", &option_arg )) + opts.sysroot = option_arg; + else if (is_option( argv, i, "--target", &option_arg )) { - if (argv[i][9] == '=') opts.sysroot = argv[i] + 10; - else opts.sysroot = argv[i + 1]; - if (opts.wine_objdir) raw_compiler_arg = raw_linker_arg = 0; - } - else if (!strncmp("--target", argv[i], 8)) - { - if (argv[i][8] == '=') parse_target_option( &opts, argv[i] + 9 ); - else parse_target_option( &opts, argv[i + 1] ); + parse_target_option( &opts, option_arg ); raw_compiler_arg = raw_linker_arg = 0; } - else if (!strncmp("--lib-suffix", argv[i], 12) && opts.wine_objdir) + else if (is_option( argv, i, "--wine-objdir", &option_arg )) { - if (argv[i][12] == '=') opts.lib_suffix = argv[i] + 13; - else opts.lib_suffix = argv[i + 1]; + opts.wine_objdir = option_arg; + raw_compiler_arg = raw_linker_arg = 0; + } + else if (is_option( argv, i, "--winebuild", &option_arg )) + { + opts.winebuild = option_arg; + raw_compiler_arg = raw_linker_arg = 0; + } + else if (is_option( argv, i, "--lib-suffix", &option_arg )) + { + opts.lib_suffix = option_arg; raw_compiler_arg = raw_linker_arg = 0; } break; @@ -1703,7 +1716,6 @@ int main(int argc, char **argv) } } - if (opts.wine_objdir && opts.sysroot) opts.wine_objdir = opts.sysroot; if (opts.processor == proc_cpp) linking = 0; if (linking == -1) error("Static linking is not supported\n"); diff --git a/tools/winegcc/winegcc.man.in b/tools/winegcc/winegcc.man.in index 3fcd6f95f31..5550767299b 100644 --- a/tools/winegcc/winegcc.man.in +++ b/tools/winegcc/winegcc.man.in @@ -26,18 +26,17 @@ the gcc manual for more information on those options. .B gcc options: All gcc options are supported, and are passed along to the backend compiler. -.IP "\fB-B\fIprefix\fR" -This option specifies where to find the executables, libraries, -include files, and data files of the compiler itself. This is a -standard gcc option that has been extended to recognize a -\fIprefix\fR ending with '/tools/winebuild', in which case winegcc -enters a special mode for building Wine itself. Developers should -avoid prefixes ending with the magic suffix, or if that is not -possible, simply express it differently, such as '/tools/winebuild/', -to avoid the special behaviour. .IP "\fB-b,--target \fItarget\fR" Specify the target architecture triplet for cross-compiling. winegcc will then invoke \fItarget\fR-gcc instead of gcc. +.IP "\fB--wine-objdir \fIdir\fR" +Specify the Wine object directory. This is used when building Wine +itself, to use the includes and libraries from inside the build tree. +.IP "\fB--winebuild \fIname\fR" +Specifies the path and name of the \fBwinebuild\fR binary that will be +launched automatically by \fBwinegcc\fR. If not set, \fBwinegcc\fR +will look for a file named \fIwinebuild\fR in the path. This takes +precedence over the \fBWINEBUILD\fR environment variable. .IP \fB-fno-short-wchar\fR Override the underlying type for wchar_t to be the default for the target, instead of using short unsigned int, which is the default @@ -74,9 +73,8 @@ commas, it is split into multiple options at the commas. .TP .B WINEBUILD Specifies the path and name of the \fBwinebuild\fR binary that will be -launched automatically by \fBwinegcc\fR. -If not set, \fBwinegcc\fR will look for a file named \fIwinebuild\fR -in the path. +launched automatically by \fBwinegcc\fR. If not set, \fBwinegcc\fR +will look for a file named \fIwinebuild\fR in the path. .SH DEFINES winegcc defines __WINE__, for code that needs to know when it is being compiled under Wine. It also defines WIN32, _WIN32, __WIN32,