Commit 70c4fc41 authored by Dimitrie O. Paun's avatar Dimitrie O. Paun Committed by Alexandre Julliard

Better handling of errors while fork/execing.

Add verbose command line switch. Add -z defs at link stage, to catch missing symbols.
parent 8efafbde
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/stat.h> #include <sys/stat.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
...@@ -75,7 +76,7 @@ static const char *app_loader_script = ...@@ -75,7 +76,7 @@ static const char *app_loader_script =
static char *output_name; static char *output_name;
static char **lib_files, **obj_files; static char **lib_files, **obj_files;
static int nb_lib_files, nb_obj_files; static int nb_lib_files, nb_obj_files;
static int debug = 1; static int verbose = 0;
void error(const char *s, ...) void error(const char *s, ...)
{ {
...@@ -111,22 +112,25 @@ char *strmake(const char *fmt, ...) ...@@ -111,22 +112,25 @@ char *strmake(const char *fmt, ...)
void spawn(char *const argv[]) void spawn(char *const argv[])
{ {
int pid, status, i; int pid, status, wret, i;
if (debug) if (verbose)
{ {
for(i = 0; argv[i]; i++) printf("%s ", argv[i]); for(i = 0; argv[i]; i++) printf("%s ", argv[i]);
printf("\n"); printf("\n");
} }
if ((pid = fork()) == 0) execvp(argv[0], argv); if ((pid = fork()) == 0) execvp(argv[0], argv);
else if (waitpid(pid, &status, 0) > 0) else if (pid > 0)
{ {
if (WIFEXITED(status) && WEXITSTATUS(status) == 0) return; while (pid != (wret = waitpid(pid, &status, 0)))
if (wret == -1 && errno != EINTR) break;
if (pid == wret && WIFEXITED(status) && WEXITSTATUS(status) == 0) return;
error("%s failed.", argv[0]); error("%s failed.", argv[0]);
} }
perror("Error:"); perror("Error:");
exit(1); exit(3);
} }
int is_resource(const char* file) int is_resource(const char* file)
...@@ -173,7 +177,12 @@ int main(int argc, char **argv) ...@@ -173,7 +177,12 @@ int main(int argc, char **argv)
break; break;
case 'm': case 'm':
if (strcmp("-mwindows", argv[i]) == 0) gui_mode = 1; if (strcmp("-mwindows", argv[i]) == 0) gui_mode = 1;
else if (strcmp("-mgui", argv[i]) == 0) gui_mode = 1;
else error("Unknown option %s\n", argv[i]); else error("Unknown option %s\n", argv[i]);
break;
case 'v': /* verbose */
if (argv[i][2] == 0) verbose = 1;
break;
case '-': case '-':
if (argv[i][2]) error("No long option supported."); if (argv[i][2]) error("No long option supported.");
no_opt = 1; no_opt = 1;
...@@ -202,14 +211,12 @@ int main(int argc, char **argv) ...@@ -202,14 +211,12 @@ int main(int argc, char **argv)
spec_args[j++] = strmake("%s.c", spec_name); spec_args[j++] = strmake("%s.c", spec_name);
spec_args[j++] = "--exe"; spec_args[j++] = "--exe";
spec_args[j++] = output_name; spec_args[j++] = output_name;
spec_args[j++] = "-m"; spec_args[j++] = gui_mode ? "-mgui" : "-mcui";
spec_args[j++] = gui_mode ? "gui" : "cui";
for (i = 0; i < nb_obj_files; i++) for (i = 0; i < nb_obj_files; i++)
spec_args[j++] = obj_files[i]; spec_args[j++] = obj_files[i];
spec_args[j++] = "-L" WINEDLLS; spec_args[j++] = "-L" WINEDLLS;
for (i = 0; i < nb_lib_files; i++) for (i = 0; i < nb_lib_files; i++)
spec_args[j++] = strmake("-l%s", lib_files[i]); spec_args[j++] = strmake("-l%s", lib_files[i]);
spec_args[j++] = "-lmsvcrt";
spec_args[j] = 0; spec_args[j] = 0;
/* build gcc's argument list */ /* build gcc's argument list */
...@@ -227,7 +234,7 @@ int main(int argc, char **argv) ...@@ -227,7 +234,7 @@ int main(int argc, char **argv)
j = 0; j = 0;
link_args[j++] = "gcc"; link_args[j++] = "gcc";
link_args[j++] = "-shared"; link_args[j++] = "-shared";
link_args[j++] = "-Wl,-Bsymbolic"; link_args[j++] = "-Wl,-Bsymbolic,-z,defs";
link_args[j++] = "-lwine"; link_args[j++] = "-lwine";
link_args[j++] = "-lm"; link_args[j++] = "-lm";
link_args[j++] = "-o"; link_args[j++] = "-o";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment