Implement support for the -x <lang> option.

This commit is contained in:
Dimitrie O. Paun 2004-04-16 23:30:32 +00:00 committed by Alexandre Julliard
parent 7214fdfca4
commit 46b1d49a88
1 changed files with 27 additions and 12 deletions

View File

@ -220,7 +220,7 @@ static const strarray* get_translator(struct options* opts)
error("Unknown processor"); error("Unknown processor");
} }
static void compile(struct options* opts) static void compile(struct options* opts, const char* lang)
{ {
strarray* comp_args = strarray_alloc(); strarray* comp_args = strarray_alloc();
int j, gcc_defs = 0; int j, gcc_defs = 0;
@ -313,14 +313,21 @@ static void compile(struct options* opts)
for ( j = 0 ; j < opts->compiler_args->size ; j++ ) for ( j = 0 ; j < opts->compiler_args->size ; j++ )
strarray_add(comp_args, opts->compiler_args->base[j]); strarray_add(comp_args, opts->compiler_args->base[j]);
/* the language option, if any */
if (lang && strcmp(lang, "-xnone"))
strarray_add(comp_args, lang);
/* last, but not least, the files */ /* last, but not least, the files */
for ( j = 0; j < opts->files->size; j++ ) for ( j = 0; j < opts->files->size; j++ )
strarray_add(comp_args, opts->files->base[j]); {
if (opts->files->base[j][0] != '-')
strarray_add(comp_args, opts->files->base[j]);
}
spawn(opts->prefix, comp_args); spawn(opts->prefix, comp_args);
} }
static const char* compile_to_object(struct options* opts, const char* file) static const char* compile_to_object(struct options* opts, const char* file, const char* lang)
{ {
struct options copts; struct options copts;
char* base_name; char* base_name;
@ -329,12 +336,11 @@ static const char* compile_to_object(struct options* opts, const char* file)
/* a shallow copy is exactly what we want in this case */ /* a shallow copy is exactly what we want in this case */
base_name = get_basename(file); base_name = get_basename(file);
copts = *opts; copts = *opts;
copts.processor = proc_cc;
copts.output_name = get_temp_file(base_name, ".o"); copts.output_name = get_temp_file(base_name, ".o");
copts.compile_only = 1; copts.compile_only = 1;
copts.files = strarray_alloc(); copts.files = strarray_alloc();
strarray_add(copts.files, file); strarray_add(copts.files, file);
compile(&copts); compile(&copts, lang);
strarray_free(copts.files); strarray_free(copts.files);
free(base_name); free(base_name);
@ -345,10 +351,10 @@ static void build(struct options* opts)
{ {
static const char *stdlibpath[] = { DLLDIR, LIBDIR, "/usr/lib", "/usr/local/lib", "/lib" }; static const char *stdlibpath[] = { DLLDIR, LIBDIR, "/usr/lib", "/usr/local/lib", "/lib" };
strarray *lib_dirs, *files; strarray *lib_dirs, *files;
strarray *spec_args, *comp_args, *link_args; strarray *spec_args, *link_args;
char *output_file; char *output_file;
const char *spec_c_name, *spec_o_name; const char *spec_c_name, *spec_o_name;
const char *output_name, *spec_file; const char *output_name, *spec_file, *lang;
const char* winebuild = getenv("WINEBUILD"); const char* winebuild = getenv("WINEBUILD");
int generate_app_loader = 1; int generate_app_loader = 1;
int j; int j;
@ -360,6 +366,7 @@ static void build(struct options* opts)
* -oxxx: xxx is an object (.o) * -oxxx: xxx is an object (.o)
* -rxxx: xxx is a resource (.res) * -rxxx: xxx is a resource (.res)
* -sxxx: xxx is a shared lib (.so) * -sxxx: xxx is a shared lib (.so)
* -xlll: lll is the language (c, c++, etc.)
*/ */
if (!winebuild) winebuild = "winebuild"; if (!winebuild) winebuild = "winebuild";
@ -403,7 +410,7 @@ static void build(struct options* opts)
} }
/* mark the files with their appropriate type */ /* mark the files with their appropriate type */
spec_file = 0; spec_file = lang = 0;
files = strarray_alloc(); files = strarray_alloc();
for ( j = 0; j < opts->files->size; j++ ) for ( j = 0; j < opts->files->size; j++ )
{ {
@ -440,7 +447,7 @@ static void build(struct options* opts)
error("File does not exist: %s", file); error("File does not exist: %s", file);
break; break;
default: default:
file = compile_to_object(opts, file); file = compile_to_object(opts, file, lang);
strarray_add(files, strmake("-o%s", file)); strarray_add(files, strmake("-o%s", file));
break; break;
} }
@ -466,6 +473,8 @@ static void build(struct options* opts)
} }
free(fullname); free(fullname);
} }
else if (file[1] == 'x')
lang = file;
} }
if (opts->shared && !spec_file) if (opts->shared && !spec_file)
error("A spec file is currently needed in shared mode"); error("A spec file is currently needed in shared mode");
@ -535,8 +544,7 @@ static void build(struct options* opts)
spawn(opts->prefix, spec_args); spawn(opts->prefix, spec_args);
/* compile the .spec.c file into a .spec.o file */ /* compile the .spec.c file into a .spec.o file */
comp_args = strarray_alloc(); spec_o_name = compile_to_object(opts, spec_c_name, 0);
spec_o_name = compile_to_object(opts, spec_c_name);
/* link everything together now */ /* link everything together now */
link_args = strarray_alloc(); link_args = strarray_alloc();
@ -678,6 +686,7 @@ int main(int argc, char **argv)
int raw_compiler_arg, raw_linker_arg; int raw_compiler_arg, raw_linker_arg;
const char* option_arg; const char* option_arg;
struct options opts; struct options opts;
char* lang = 0;
char* str; char* str;
/* setup tmp file removal at exit */ /* setup tmp file removal at exit */
@ -839,6 +848,12 @@ int main(int argc, char **argv)
raw_compiler_arg = raw_linker_arg = 0; raw_compiler_arg = raw_linker_arg = 0;
} }
break; break;
case 'x':
lang = strmake("-x%s", option_arg);
strarray_add(opts.files, lang);
/* we'll pass these flags ourselves, explicitely */
raw_compiler_arg = raw_linker_arg = 0;
break;
case '-': case '-':
if (strcmp("-static", argv[i]+1) == 0) if (strcmp("-static", argv[i]+1) == 0)
linking = -1; linking = -1;
@ -873,7 +888,7 @@ int main(int argc, char **argv)
if (opts.files->size == 0) forward(argc, argv, &opts); if (opts.files->size == 0) forward(argc, argv, &opts);
else if (linking) build(&opts); else if (linking) build(&opts);
else compile(&opts); else compile(&opts, lang);
return 0; return 0;
} }