Added entry for DirectSoundFullDuplexCreate.
[wine] / tools / winewrap.c
1 /*
2  * Wine wrapper: takes care of internal details for linking.
3  *
4  * Copyright 2000 Francois Gouget
5  * Copyright 2002 Dimitrie O. Paun
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdarg.h>
28 #include <stdlib.h>
29 #include <errno.h>
30 #ifdef HAVE_SYS_WAIT_H
31 #include <sys/wait.h>
32 #endif
33 #include <sys/stat.h>
34 #ifdef HAVE_UNISTD_H
35 # include <unistd.h>
36 #endif
37
38 #ifndef WINEDLLS
39 #define WINEDLLS "/usr/local/lib/wine"
40 #endif
41
42 static const char *app_loader_script =
43     "#!/bin/sh\n"
44     "\n"
45     "appname=\"%s\"\n"
46     "# determine the application directory\n"
47     "appdir=''\n"
48     "case \"$0\" in\n"
49     "  */*)\n"
50     "    # $0 contains a path, use it\n"
51     "    appdir=`dirname \"$0\"`\n"
52     "    ;;\n"
53     "  *)\n"
54     "    # no directory in $0, search in PATH\n"
55     "    saved_ifs=$IFS\n"
56     "    IFS=:\n"
57     "    for d in $PATH\n"
58     "    do\n"
59     "      IFS=$saved_ifs\n"
60     "      if [ -x \"$d/$appname\" ]; then appdir=\"$d\"; break; fi\n"
61     "    done\n"
62     "    ;;\n"
63     "esac\n"
64     "\n"
65     "while true; do\n"
66     "  case \"$1\" in\n"
67     "    --debugmsg)\n"
68     "      debugmsg=\"$1 $2\"\n"
69     "      shift; shift;\n"
70     "      ;;\n"
71     "    --dll)\n"
72     "      dll=\"$1 $2\"\n"
73     "      shift; shift;\n"
74     "      ;;\n"
75     "    *)\n"
76     "      break\n"
77     "      ;;\n"
78     "  esac\n"
79     "done\n"
80     "\n"
81     "# figure out the full app path\n"
82     "if [ -n \"$appdir\" ]; then\n"
83     "    apppath=\"$appdir/$appname.exe.so\"\n"
84     "else\n"
85     "    apppath=\"$appname.exe.so\"\n"
86     "fi\n"
87     "\n"
88     "# determine the WINELOADER\n"
89     "if [ ! -x \"$WINELOADER\" ]; then WINELOADER=\"wine\"; fi\n"
90     "\n"
91     "# and try to start the app\n"
92     "exec \"$WINELOADER\" $debugmsg $dll -- \"$apppath\" \"$@\"\n"
93 ;
94
95 static const char *app_gui_spec =
96     "@ stdcall WinMain(ptr long ptr long) WinMain\n"
97 ;
98
99 static const char *app_cui_spec =
100     "@ stdcall main(long ptr ptr) main\n"
101 ;
102
103 static const char *wrapper_code =
104     "/*\n"
105     " * Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers\n"
106     " * Copyright 2002 Dimitrie O. Paun <dpaun@rogers.com>\n"
107     " */\n"
108     "\n"
109     "#include <dlfcn.h>\n"
110     "#include <windows.h>\n"
111     "\n"
112     "\n"
113     "/*\n"
114     " * Describe the wrapped application\n"
115     " */\n"
116     "\n"
117     "/* The app name */\n"
118     "#define APPNAME \"%s\"\n"
119     "/**\n"
120     " * This is either 0 for a console based application or\n"
121     " * 1 for a regular windows application.\n"
122     " */\n"
123     "#define GUIEXE %d\n"
124     "\n"
125     "/**\n"
126     " * This is the name of the library containing the application,\n"
127     " * e.g. 'hello.dll' if the application is called 'hello.exe'.\n"
128     " */\n"
129     "static char* appName     = APPNAME \".dll\";\n"
130     "\n"
131     "/**\n"
132     " * This is the name of the application's Windows module. If left NULL\n"
133     " * then appName is used.\n"
134     " */\n"
135     "static char* appModule   = NULL;\n"
136     "\n"
137     "/**\n"
138     " * This is the application's entry point. This is usually 'WinMain' for a\n"
139     " * gui app and 'main' for a console application.\n"
140     " */\n"
141     "#if GUIEXE\n"
142     "static char* appInit     = \"WinMain\";\n"
143     "#else\n"
144     "static char* appInit     = \"main\";\n"
145     "#endif\n"
146     "\n"
147     "/**\n"
148     " * This is either non-NULL for MFC-based applications and is the name of the\n"
149     " * MFC's module. This is the module in which we will take the 'WinMain'\n"
150     " * function.\n"
151     " */\n"
152     "static char* mfcModule   = NULL;\n"
153     "\n"
154     "\n"
155     "void error(const char *format, ...)\n"
156     "{\n"
157     "    va_list ap;\n"
158     "    char msg[4096];\n"
159     "\n"
160     "    va_start(ap, format);\n"
161     "    vsnprintf(msg, sizeof(msg), format, ap);\n"
162     "    MessageBox(NULL, msg, \"Error\", MB_OK);\n"
163     "    va_end(ap);\n"
164     "    exit(1);\n"
165     "}\n"
166     "\n"
167     "\n"
168     "#if GUIEXE\n"
169     "typedef int WINAPI (*WinMainFunc)(HINSTANCE hInstance, HINSTANCE hPrevInstance,\n"
170     "                             PSTR szCmdLine, int iCmdShow);\n"
171     "#else\n"
172     "typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp);\n"
173     "#endif\n"
174     "\n"
175     "#if GUIEXE\n"
176     "int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,\n"
177     "                   PSTR szCmdLine, int iCmdShow)\n"
178     "#else\n"
179     "int WINAPI main(int argc, char** argv, char** envp)\n"
180     "#endif\n"
181     "{\n"
182     "    void* appLibrary;\n"
183     "    HINSTANCE hApp = 0, hMFC = 0, hMain = 0;\n"
184     "    void* appMain;\n"
185     "    char* libName;\n"
186     "    int retcode;\n"
187     "\n"
188     "    /* Load the application's library */\n"
189     "    libName=(char*)malloc(2+strlen(appName)+3+1);\n"
190     "    /* FIXME: we should get the wrapper's path and use that as the base for\n"
191     "     * the library\n"
192     "     */\n"
193     "    sprintf(libName,\"./%%s.so\",appName);\n"
194     "    appLibrary=dlopen(libName,RTLD_NOW);\n"
195     "    if (appLibrary==NULL) {\n"
196     "        sprintf(libName,\"%%s.so\",appName);\n"
197     "        appLibrary=dlopen(libName,RTLD_NOW);\n"
198     "    }\n"
199     "    if (!appLibrary) error(\"Could not load the %%s library: %%s\", libName, dlerror());\n"
200     "\n"
201     "    /* Then if this application is MFC based, load the MFC module */\n"
202     "    /* FIXME: I'm not sure this is really necessary */\n"
203     "    if (mfcModule) {\n"
204     "        hMFC = LoadLibrary(mfcModule);\n"
205     "        if (!hMFC) error(\"Could not load the MFC module %%s (%%d)\", mfcModule, GetLastError());\n"
206     "        /* MFC is a special case: the WinMain is in the MFC library,\n"
207     "         * instead of the application's library.\n"
208     "         */\n"
209     "        hMain = hMFC;\n"
210     "    }\n"
211     "\n"
212     "    /* Load the application's module */\n"
213     "    if (!appModule) appModule = appName;\n"
214     "    hApp = LoadLibrary(appModule);\n"
215     "    if (!hApp) error(\"Could not load the application's module %%s (%%d)\", appModule, GetLastError());\n"
216     "    if (!hMain) hMain = hApp;\n"
217     "\n"
218     "    /* Get the address of the application's entry point */\n"
219     "    appMain = GetProcAddress(hMain, appInit);\n"
220     "    if (!appMain) error(\"Could not get the address of %%s (%%d)\", appInit, GetLastError());\n"
221     "\n"
222     "    /* And finally invoke the application's entry point */\n"
223     "#if GUIEXE\n"
224     "    retcode = (*((WinMainFunc)appMain))(hApp, hPrevInstance, szCmdLine, iCmdShow);\n"
225     "#else\n"
226     "    retcode = (*((MainFunc)appMain))(argc, argv, envp);\n"
227     "#endif\n"
228     "\n"
229     "    /* Cleanup and done */\n"
230     "    FreeLibrary(hApp);\n"
231     "    FreeLibrary(hMFC);\n"
232     "    dlclose(appLibrary);\n"
233     "    free(libName);\n"
234     "\n"
235     "    return retcode;\n"
236     "}\n"
237 ;
238
239 static char *output_name;
240 static char **arh_files,  **dll_files,  **lib_files,  **lib_paths,  **obj_files;
241 static int nb_arh_files, nb_dll_files, nb_lib_files, nb_lib_paths, nb_obj_files;
242 static int verbose = 0;
243 static int keep_generated = 0;
244
245 void error(const char *s, ...)
246 {
247     va_list ap;
248     
249     va_start(ap, s);
250     fprintf(stderr, "Error: ");
251     vfprintf(stderr, s, ap);
252     fprintf(stderr, "\n");
253     va_end(ap);
254     exit(2);
255 }
256
257 char *strmake(const char *fmt, ...) 
258 {
259     int n, size = 100;
260     char *p;
261     va_list ap;
262
263     if ((p = malloc (size)) == NULL)
264         error("Can not malloc %d bytes.", size);
265     
266     while (1) 
267     {
268         va_start(ap, fmt);
269         n = vsnprintf (p, size, fmt, ap);
270         va_end(ap);
271         if (n > -1 && n < size) return p;
272         size *= 2;
273         if ((p = realloc (p, size)) == NULL)
274             error("Can not realloc %d bytes.", size);
275     }
276 }
277
278 void rm_temp_file(const char *file)
279 {
280     if (!keep_generated) unlink(file);
281 }
282
283 void create_file(const char *name, const char *fmt, ...)
284 {
285     va_list ap;
286     FILE *file;
287
288     if (verbose) printf("Creating file %s\n", name);
289     va_start(ap, fmt);
290     if ( !(file = fopen(name, "w")) )
291         error ("Can not create %s.", name);
292     vfprintf(file, fmt, ap);
293     va_end(ap);
294     fclose(file);
295 }
296
297 void spawn(char *const argv[])
298 {
299 #ifdef HAVE__SPAWNVP
300     if (!_spawnvp( _P_WAIT, argv[0], argv)) return;
301 #else
302     int pid, status, wret, i;
303
304     if (verbose)
305     {   
306         for(i = 0; argv[i]; i++) printf("%s ", argv[i]);
307         printf("\n");
308     }
309     
310     if ((pid = fork()) == 0) execvp(argv[0], argv);
311     else if (pid > 0)
312     {
313         while (pid != (wret = waitpid(pid, &status, 0)))
314             if (wret == -1 && errno != EINTR) break;
315         
316         if (pid == wret && WIFEXITED(status) && WEXITSTATUS(status) == 0) return;
317         error("%s failed.", argv[0]);
318     }
319 #endif  /* HAVE__SPAWNVP */
320
321     perror("Error:");
322     exit(3);
323 }
324
325 int is_resource(const char* file)
326 {
327     /* see tools/winebuild/res32.c: check_header for details */
328     static const char res_sig[] = { 0,0,0,0, 32,0,0,0, 0xff,0xff, 0,0, 0xff,0xff, 0,0, 0,0,0,0, 0,0, 0,0, 0,0,0,0, 0,0,0,0 };
329     char buf[sizeof(res_sig)];
330     FILE *fin;
331     
332     if (!(fin = fopen(file, "r"))) error("Can not open %s", file);
333     if (fread(buf, sizeof(buf), 1, fin) != 1) error("Truncated file %s", file);
334     fclose(fin);
335
336     return !memcmp(buf, res_sig, sizeof(buf));
337 }
338
339 /* open the file for a given name, in a specified path, with the given extension */
340 static char *try_path( const char *path, const char *name, const char *ext )
341 {
342     char *fullname;
343     int fd;
344
345     fullname = strmake("%s/lib%s.%s", path, name, ext);
346     if (verbose > 1) fprintf(stderr, "Try %s...", fullname);
347
348     /* check if the file exists */
349     if ((fd = open( fullname, O_RDONLY )) != -1)
350     {
351         close( fd );
352         if (verbose > 1) fprintf(stderr, "FOUND!\n");
353         return fullname;
354     }
355     free( fullname );
356     if (verbose > 1) fprintf(stderr, "\n");
357     return NULL;
358 }
359
360 /* open the .def library for a given dll in a specified path */
361 static char *try_dll_path( const char *path, const char *name )
362 {
363     return try_path(path, name, "def");
364 }
365
366 /* open the .a library for a given lib in a specified path */
367 static char *try_lib_path( const char *path, const char *name )
368 {
369     return try_path(path, name, "a");
370 }
371
372 /* open the .def library for a given dll */
373 static char *open_dll(const char *name)
374 {
375     char *fullname;
376     int i;
377
378     for (i = 0; i < nb_lib_paths; i++)
379     {
380         if ((fullname = try_dll_path( lib_paths[i], name ))) return fullname;
381     }
382     return try_dll_path( ".", name );
383 }
384
385 /* find a static library */
386 static char *find_lib(const char *name)
387 {
388     static const char* std_paths[] = { ".", "/usr/lib", "/usr/local/lib" };
389     char *fullname;
390     int i;
391     
392     for (i = 0; i < nb_lib_paths; i++)
393     {
394         if ((fullname = try_lib_path( lib_paths[i], name ))) return fullname;
395     }
396
397     for (i = 0; i < sizeof(std_paths)/sizeof(std_paths[0]); i++)
398     {
399         if ((fullname = try_lib_path( std_paths[i], name ))) return fullname;
400     }
401
402     return 0;
403 }
404
405 void add_lib_path(const char* path)
406 {
407     lib_paths = realloc( lib_paths, (nb_lib_paths+1) * sizeof(*lib_paths) );
408     lib_paths[nb_lib_paths++] = strdup(path);
409     dll_files = realloc( dll_files, (nb_dll_files+1) * sizeof(*dll_files) );
410     dll_files[nb_dll_files++] = strmake("-L%s", path);
411     lib_files = realloc( lib_files, (nb_lib_files+1) * sizeof(*lib_files) );
412     lib_files[nb_lib_files++] = strmake("-L%s", path);
413 }
414
415 void add_lib_file(const char* library)
416 {
417     char *lib;
418     
419     if (open_dll(library))
420     {
421         dll_files = realloc( dll_files, (nb_dll_files+1) * sizeof(*dll_files) );
422         dll_files[nb_dll_files++] = strmake("-l%s", library);
423     }
424     else if ((lib = find_lib(library)))
425     {
426         arh_files = realloc( arh_files, (nb_arh_files+1) * sizeof(*arh_files) );
427         arh_files[nb_arh_files++] = lib;
428     }
429     else
430     {
431         lib_files = realloc( lib_files, (nb_lib_files+1) * sizeof(*lib_files) );
432         lib_files[nb_lib_files++] = strmake("-l%s", library);
433     }
434 }
435
436 int main(int argc, char **argv)
437 {
438     char *library = 0, *path = 0;
439     int i, j, len, cpp = 0, no_opt = 0, gui_mode = 0, create_wrapper = -1;
440     char *base_name, *base_file, *app_temp_name, *wrp_temp_name;
441     char *spec_name, *spec_c_name, *spec_o_name;
442     char *wspec_name, *wspec_c_name, *wspec_o_name;
443     char *wrap_c_name, *wrap_o_name;
444     char **spec_args, **comp_args, **link_args;
445     char **wwrap_args, **wspec_args, **wcomp_args, **wlink_args;
446    
447     /* include the standard DLL path first */
448     add_lib_path(WINEDLLS);
449         
450     for (i = 1; i < argc; i++)
451     {
452         if (!no_opt && argv[i][0] == '-')
453         {
454             switch (argv[i][1])
455             {
456             case 'k':
457                 keep_generated = 1;
458                 break;
459             case 'o':
460                 if (argv[i][2]) output_name = strdup(argv[i]+ 2);
461                 else if (i + 1 < argc) output_name = strdup(argv[++i]);
462                 else error("The -o switch takes an argument.");
463                 break;
464             case 'L':
465                 if (argv[i][2]) path = argv[i] + 2;
466                 else if (i + 1 < argc) path = argv[++i];
467                 else error("The -L switch takes an argument\n.");
468                 add_lib_path(path);
469                 break;
470             case 'l':
471                 if (argv[i][2]) library = argv[i] + 2;
472                 else if (i + 1 < argc) library = argv[++i];
473                 else error("The -l switch takes an argument\n.");
474                 add_lib_file(library);
475                 break;
476             case 'm':
477                 if (strcmp("-mgui", argv[i]) == 0) gui_mode = 1;
478                 else error("Unknown option %s\n", argv[i]);
479                 break;
480             case 'v':        /* verbose */
481                 if (argv[i][2] == 0) verbose++;
482                 break;
483             case 'V':
484                 printf("winewrap v0.40\n");
485                 exit(0);
486                 break;
487             case 'C':
488                 cpp = 1;
489                 break;
490             case 'w':
491                 create_wrapper = 1;
492                 break;
493             case 'W':
494                 create_wrapper = 0;
495                 break;
496             case '-':
497                 if (argv[i][2]) error("No long option supported.");
498                 no_opt = 1;
499                 break;
500             default:
501                 error("Unknown option -%c", argv[i][1]);
502             }
503             continue;
504         }
505         
506         /* it's a filename, add it to its list */
507         obj_files = realloc( obj_files, (nb_obj_files+1) * sizeof(*obj_files) );
508         obj_files[nb_obj_files++] = strdup(argv[i]);
509     }
510
511     /* create wrapper only in C++ by default */
512     if (create_wrapper == -1) create_wrapper = cpp;
513     
514     /* link in by default the big three */
515     if (gui_mode) add_lib_file("gdi32");
516     add_lib_file("user32");
517     add_lib_file("kernel32");
518
519     app_temp_name = tempnam(0, "wapp");
520     wrp_temp_name = tempnam(0, "wwrp");
521    
522     /* get base filename by removing the .exe extension, if present */ 
523     base_file = strdup(output_name);
524     len = strlen(base_file);
525     if (len > 4 && strcmp(base_file + len - 4, ".exe") == 0)
526         base_file[len - 4 ] = 0; /* remove the .exe extension */
527
528     /* we need to get rid of the directory part to get the base name */
529     if ( (base_name = strrchr(base_file, '/')) ) base_name++;
530     else base_name = base_file;
531     
532     spec_name = strmake("%s.spec", app_temp_name);
533     spec_c_name = strmake("%s.c", spec_name);
534     spec_o_name = strmake("%s.o", spec_name);
535
536     wspec_name = strmake("%s.spec", wrp_temp_name);
537     wspec_c_name = strmake("%s.c", wspec_name);
538     wspec_o_name = strmake("%s.o", wspec_name);
539
540     wrap_c_name = strmake("%s.c", wrp_temp_name);
541     wrap_o_name = strmake("%s.o", wrp_temp_name);
542
543     /* build winebuild's argument list */
544     spec_args = malloc( (nb_arh_files + nb_dll_files + nb_obj_files + 20) * sizeof (char *) );
545     j = 0;
546     spec_args[j++] = BINDIR "/winebuild";
547     spec_args[j++] = "-o";
548     spec_args[j++] = spec_c_name;
549     if (create_wrapper)
550     {
551         spec_args[j++] = "-F";
552         spec_args[j++] = strmake("%s.dll", base_name);
553         spec_args[j++] = "--spec";
554         spec_args[j++] = spec_name;
555     }
556     else
557     {
558         spec_args[j++] = "--exe";
559         spec_args[j++] = strmake("%s.exe", base_name);
560         spec_args[j++] = gui_mode ? "-mgui" : "-mcui";
561     }
562     for (i = 0; i < nb_dll_files; i++)
563         spec_args[j++] = dll_files[i];
564     for (i = 0; i < nb_obj_files; i++)
565         spec_args[j++] = obj_files[i];
566     for (i = 0; i < nb_arh_files; i++)
567         spec_args[j++] = arh_files[i];
568     spec_args[j] = 0;
569
570     /* build gcc's argument list */
571     comp_args = malloc ( 20 * sizeof (char *) );
572     j = 0;
573     comp_args[j++] = "gcc";
574     comp_args[j++] = "-fPIC";
575     comp_args[j++] = "-o";
576     comp_args[j++] = spec_o_name;
577     comp_args[j++] = "-c";
578     comp_args[j++] = spec_c_name;
579     comp_args[j] = 0;
580     
581     /* build ld's argument list */
582     link_args = malloc( (nb_arh_files + nb_obj_files + nb_lib_files + 20) * sizeof (char *) );
583     j = 0;
584     link_args[j++] = cpp ? "g++" : "gcc";
585     link_args[j++] = "-shared";
586     link_args[j++] = "-Wl,-Bsymbolic,-z,defs";
587     link_args[j++] = "-lwine";
588     link_args[j++] = "-lm";
589     for (i = 0; i < nb_lib_files; i++)
590         link_args[j++] = lib_files[i];
591     link_args[j++] = "-o";
592     link_args[j++] = strmake("%s.%s.so", base_file, create_wrapper ? "dll" : "exe");
593     link_args[j++] = spec_o_name;
594     for (i = 0; i < nb_obj_files; i++)
595         if (!is_resource(obj_files[i])) link_args[j++] = obj_files[i];
596     for (i = 0; i < nb_arh_files; i++)
597         link_args[j++] = arh_files[i];
598     link_args[j] = 0;
599   
600     /* build wrapper compile argument list */
601     wwrap_args = malloc ( 20 * sizeof (char *) );
602     j = 0;
603     wwrap_args[j++] = "gcc";
604     wwrap_args[j++] = "-fPIC";
605     wwrap_args[j++] = "-I" INCLUDEDIR "/windows";
606     wwrap_args[j++] = "-o";
607     wwrap_args[j++] = wrap_o_name;
608     wwrap_args[j++] = "-c";
609     wwrap_args[j++] = wrap_c_name;
610     wwrap_args[j] = 0;
611      
612     /* build wrapper winebuild's argument list */
613     wspec_args = malloc( (nb_dll_files + 20) * sizeof (char *) );
614     j = 0;
615     wspec_args[j++] = BINDIR "/winebuild";
616     wspec_args[j++] = "-o";
617     wspec_args[j++] = wspec_c_name;
618     wspec_args[j++] = "--exe";
619     wspec_args[j++] = strmake("%s.exe", base_name);
620     wspec_args[j++] = gui_mode ? "-mgui" : "-mcui";
621     wspec_args[j++] = wrap_o_name;
622     for (i = 0; i < nb_dll_files; i++)
623         wspec_args[j++] = dll_files[i];
624     wspec_args[j] = 0;
625
626     /* build wrapper gcc's argument list */
627     wcomp_args = malloc ( 20 * sizeof (char *) );
628     j = 0;
629     wcomp_args[j++] = "gcc";
630     wcomp_args[j++] = "-fPIC";
631     wcomp_args[j++] = "-o";
632     wcomp_args[j++] = wspec_o_name;
633     wcomp_args[j++] = "-c";
634     wcomp_args[j++] = wspec_c_name;
635     wcomp_args[j] = 0;
636     
637     /* build wrapper ld's argument list */
638     wlink_args = malloc( 20 * sizeof (char *) );
639     j = 0;
640     wlink_args[j++] = cpp ? "g++" : "gcc";
641     wlink_args[j++] = "-shared";
642     wlink_args[j++] = "-Wl,-Bsymbolic,-z,defs";
643     wlink_args[j++] = "-lwine";
644     wlink_args[j++] = "-ldl";
645     wlink_args[j++] = "-o";
646     wlink_args[j++] = strmake("%s.exe.so", base_file);
647     wlink_args[j++] = wspec_o_name;
648     wlink_args[j++] = wrap_o_name;
649     wlink_args[j] = 0;
650     
651     /* run winebuild to get the .spec.c file */
652     if (create_wrapper)
653     {
654         create_file(spec_name, gui_mode ? app_gui_spec : app_cui_spec);
655         spawn(spec_args);
656         rm_temp_file(spec_name);
657         spawn(comp_args);
658         rm_temp_file(spec_c_name);
659         spawn(link_args);
660         rm_temp_file(spec_o_name);
661
662         create_file(wrap_c_name, wrapper_code, base_name, gui_mode);
663         spawn(wwrap_args);
664         rm_temp_file(wrap_c_name);
665         spawn(wspec_args);
666         spawn(wcomp_args);
667         rm_temp_file(wspec_c_name);
668         spawn(wlink_args);
669         rm_temp_file(wspec_o_name);
670         rm_temp_file(wrap_o_name);
671     }
672     else
673     {
674         spawn(spec_args);
675         spawn(comp_args);
676         rm_temp_file(spec_c_name);
677         spawn(link_args);
678         rm_temp_file(spec_o_name);
679     }
680
681     /* create the loader script */
682     create_file(base_file, app_loader_script, base_name);
683     chmod(base_file, 0755);
684
685     return 0;    
686