2002-12-13 01:38:42 +01:00
|
|
|
/*
|
|
|
|
* Wine wrapper: takes care of internal details for linking.
|
|
|
|
*
|
2003-01-02 20:24:03 +01:00
|
|
|
* Copyright 2000 Francois Gouget
|
2002-12-13 01:38:42 +01:00
|
|
|
* Copyright 2002 Dimitrie O. Paun
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
2002-12-17 05:15:59 +01:00
|
|
|
#include <errno.h>
|
2002-12-13 01:38:42 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2003-09-12 00:16:33 +02:00
|
|
|
#include "utils.h"
|
|
|
|
|
2002-12-13 01:38:42 +01:00
|
|
|
static const char *app_loader_script =
|
|
|
|
"#!/bin/sh\n"
|
|
|
|
"\n"
|
|
|
|
"appname=\"%s\"\n"
|
|
|
|
"# determine the application directory\n"
|
|
|
|
"appdir=''\n"
|
|
|
|
"case \"$0\" in\n"
|
|
|
|
" */*)\n"
|
|
|
|
" # $0 contains a path, use it\n"
|
|
|
|
" appdir=`dirname \"$0\"`\n"
|
|
|
|
" ;;\n"
|
|
|
|
" *)\n"
|
|
|
|
" # no directory in $0, search in PATH\n"
|
|
|
|
" saved_ifs=$IFS\n"
|
|
|
|
" IFS=:\n"
|
|
|
|
" for d in $PATH\n"
|
|
|
|
" do\n"
|
|
|
|
" IFS=$saved_ifs\n"
|
|
|
|
" if [ -x \"$d/$appname\" ]; then appdir=\"$d\"; break; fi\n"
|
|
|
|
" done\n"
|
|
|
|
" ;;\n"
|
|
|
|
"esac\n"
|
|
|
|
"\n"
|
2003-01-03 00:07:40 +01:00
|
|
|
"while true; do\n"
|
|
|
|
" case \"$1\" in\n"
|
|
|
|
" --debugmsg)\n"
|
|
|
|
" debugmsg=\"$1 $2\"\n"
|
|
|
|
" shift; shift;\n"
|
|
|
|
" ;;\n"
|
|
|
|
" --dll)\n"
|
|
|
|
" dll=\"$1 $2\"\n"
|
|
|
|
" shift; shift;\n"
|
|
|
|
" ;;\n"
|
|
|
|
" *)\n"
|
|
|
|
" break\n"
|
|
|
|
" ;;\n"
|
|
|
|
" esac\n"
|
|
|
|
"done\n"
|
|
|
|
"\n"
|
2002-12-13 01:38:42 +01:00
|
|
|
"# figure out the full app path\n"
|
|
|
|
"if [ -n \"$appdir\" ]; then\n"
|
|
|
|
" apppath=\"$appdir/$appname.exe.so\"\n"
|
2003-07-19 00:51:34 +02:00
|
|
|
" WINEDLLPATH=\"$appdir:$WINEDLLPATH\"\n"
|
|
|
|
" export WINEDLLPATH\n"
|
2002-12-13 01:38:42 +01:00
|
|
|
"else\n"
|
|
|
|
" apppath=\"$appname.exe.so\"\n"
|
|
|
|
"fi\n"
|
|
|
|
"\n"
|
|
|
|
"# determine the WINELOADER\n"
|
|
|
|
"if [ ! -x \"$WINELOADER\" ]; then WINELOADER=\"wine\"; fi\n"
|
|
|
|
"\n"
|
|
|
|
"# and try to start the app\n"
|
2003-01-03 22:02:53 +01:00
|
|
|
"exec \"$WINELOADER\" $debugmsg $dll -- \"$apppath\" \"$@\"\n"
|
2002-12-13 01:38:42 +01:00
|
|
|
;
|
2003-01-02 20:24:03 +01:00
|
|
|
|
|
|
|
static const char *app_gui_spec =
|
2003-01-03 22:02:53 +01:00
|
|
|
"@ stdcall WinMain(ptr long ptr long) WinMain\n"
|
2003-01-02 20:24:03 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
static const char *app_cui_spec =
|
2003-01-03 22:02:53 +01:00
|
|
|
"@ stdcall main(long ptr ptr) main\n"
|
2003-01-02 20:24:03 +01:00
|
|
|
;
|
|
|
|
|
|
|
|
static const char *wrapper_code =
|
|
|
|
"/*\n"
|
|
|
|
" * Copyright 2000 Francois Gouget <fgouget@codeweavers.com> for CodeWeavers\n"
|
|
|
|
" * Copyright 2002 Dimitrie O. Paun <dpaun@rogers.com>\n"
|
|
|
|
" */\n"
|
|
|
|
"\n"
|
2003-09-16 22:27:14 +02:00
|
|
|
"#include <stdio.h>\n"
|
2003-01-02 20:24:03 +01:00
|
|
|
"#include <windows.h>\n"
|
|
|
|
"\n"
|
|
|
|
"\n"
|
|
|
|
"/*\n"
|
|
|
|
" * Describe the wrapped application\n"
|
|
|
|
" */\n"
|
|
|
|
"\n"
|
|
|
|
"/* The app name */\n"
|
|
|
|
"#define APPNAME \"%s\"\n"
|
|
|
|
"/**\n"
|
|
|
|
" * This is either 0 for a console based application or\n"
|
|
|
|
" * 1 for a regular windows application.\n"
|
|
|
|
" */\n"
|
|
|
|
"#define GUIEXE %d\n"
|
|
|
|
"\n"
|
|
|
|
"/**\n"
|
|
|
|
" * This is the name of the library containing the application,\n"
|
2003-07-19 00:51:34 +02:00
|
|
|
" * e.g. 'hello-wrap.dll' if the application is called 'hello.exe'.\n"
|
2003-01-02 20:24:03 +01:00
|
|
|
" */\n"
|
2003-09-16 22:27:14 +02:00
|
|
|
"static char* appName = \"%s\";\n"
|
2003-01-02 20:24:03 +01:00
|
|
|
"\n"
|
|
|
|
"/**\n"
|
|
|
|
" * This is the name of the application's Windows module. If left NULL\n"
|
|
|
|
" * then appName is used.\n"
|
|
|
|
" */\n"
|
|
|
|
"static char* appModule = NULL;\n"
|
|
|
|
"\n"
|
|
|
|
"/**\n"
|
|
|
|
" * This is the application's entry point. This is usually 'WinMain' for a\n"
|
|
|
|
" * gui app and 'main' for a console application.\n"
|
|
|
|
" */\n"
|
|
|
|
"#if GUIEXE\n"
|
|
|
|
"static char* appInit = \"WinMain\";\n"
|
|
|
|
"#else\n"
|
|
|
|
"static char* appInit = \"main\";\n"
|
|
|
|
"#endif\n"
|
|
|
|
"\n"
|
|
|
|
"/**\n"
|
|
|
|
" * This is either non-NULL for MFC-based applications and is the name of the\n"
|
|
|
|
" * MFC's module. This is the module in which we will take the 'WinMain'\n"
|
|
|
|
" * function.\n"
|
|
|
|
" */\n"
|
|
|
|
"static char* mfcModule = NULL;\n"
|
|
|
|
"\n"
|
|
|
|
"\n"
|
2003-01-03 22:02:53 +01:00
|
|
|
"void error(const char *format, ...)\n"
|
|
|
|
"{\n"
|
|
|
|
" va_list ap;\n"
|
|
|
|
" char msg[4096];\n"
|
|
|
|
"\n"
|
|
|
|
" va_start(ap, format);\n"
|
|
|
|
" vsnprintf(msg, sizeof(msg), format, ap);\n"
|
2003-09-16 22:27:14 +02:00
|
|
|
" fprintf(stderr, \"Error: %%s\\n\", msg);\n"
|
2003-01-03 22:02:53 +01:00
|
|
|
" va_end(ap);\n"
|
|
|
|
" exit(1);\n"
|
|
|
|
"}\n"
|
2003-01-02 20:24:03 +01:00
|
|
|
"\n"
|
|
|
|
"\n"
|
|
|
|
"#if GUIEXE\n"
|
|
|
|
"typedef int WINAPI (*WinMainFunc)(HINSTANCE hInstance, HINSTANCE hPrevInstance,\n"
|
|
|
|
" PSTR szCmdLine, int iCmdShow);\n"
|
|
|
|
"#else\n"
|
|
|
|
"typedef int WINAPI (*MainFunc)(int argc, char** argv, char** envp);\n"
|
|
|
|
"#endif\n"
|
|
|
|
"\n"
|
|
|
|
"#if GUIEXE\n"
|
|
|
|
"int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,\n"
|
|
|
|
" PSTR szCmdLine, int iCmdShow)\n"
|
|
|
|
"#else\n"
|
|
|
|
"int WINAPI main(int argc, char** argv, char** envp)\n"
|
|
|
|
"#endif\n"
|
|
|
|
"{\n"
|
|
|
|
" HINSTANCE hApp = 0, hMFC = 0, hMain = 0;\n"
|
|
|
|
" void* appMain;\n"
|
|
|
|
" int retcode;\n"
|
|
|
|
"\n"
|
|
|
|
" /* Then if this application is MFC based, load the MFC module */\n"
|
2003-01-03 22:02:53 +01:00
|
|
|
" if (mfcModule) {\n"
|
|
|
|
" hMFC = LoadLibrary(mfcModule);\n"
|
|
|
|
" if (!hMFC) error(\"Could not load the MFC module %%s (%%d)\", mfcModule, GetLastError());\n"
|
2003-04-10 01:34:19 +02:00
|
|
|
" /* For MFC apps, WinMain is in the MFC library */\n"
|
2003-01-03 22:02:53 +01:00
|
|
|
" hMain = hMFC;\n"
|
2003-01-02 20:24:03 +01:00
|
|
|
" }\n"
|
|
|
|
"\n"
|
|
|
|
" /* Load the application's module */\n"
|
2003-01-03 22:02:53 +01:00
|
|
|
" if (!appModule) appModule = appName;\n"
|
|
|
|
" hApp = LoadLibrary(appModule);\n"
|
|
|
|
" if (!hApp) error(\"Could not load the application's module %%s (%%d)\", appModule, GetLastError());\n"
|
|
|
|
" if (!hMain) hMain = hApp;\n"
|
2003-01-02 20:24:03 +01:00
|
|
|
"\n"
|
|
|
|
" /* Get the address of the application's entry point */\n"
|
2003-01-03 22:02:53 +01:00
|
|
|
" appMain = GetProcAddress(hMain, appInit);\n"
|
|
|
|
" if (!appMain) error(\"Could not get the address of %%s (%%d)\", appInit, GetLastError());\n"
|
2003-01-02 20:24:03 +01:00
|
|
|
"\n"
|
|
|
|
" /* And finally invoke the application's entry point */\n"
|
|
|
|
"#if GUIEXE\n"
|
2003-01-03 22:02:53 +01:00
|
|
|
" retcode = (*((WinMainFunc)appMain))(hApp, hPrevInstance, szCmdLine, iCmdShow);\n"
|
2003-01-02 20:24:03 +01:00
|
|
|
"#else\n"
|
2003-01-03 22:02:53 +01:00
|
|
|
" retcode = (*((MainFunc)appMain))(argc, argv, envp);\n"
|
2003-01-02 20:24:03 +01:00
|
|
|
"#endif\n"
|
|
|
|
"\n"
|
|
|
|
" /* Cleanup and done */\n"
|
|
|
|
" FreeLibrary(hApp);\n"
|
2003-01-03 22:02:53 +01:00
|
|
|
" FreeLibrary(hMFC);\n"
|
2003-01-02 20:24:03 +01:00
|
|
|
"\n"
|
|
|
|
" return retcode;\n"
|
|
|
|
"}\n"
|
|
|
|
;
|
|
|
|
|
2003-09-19 02:19:36 +02:00
|
|
|
static char *output_name = "a.out";
|
2003-09-12 02:25:14 +02:00
|
|
|
static strarray *arh_files, *dll_files, *lib_files, *llib_paths, *lib_paths, *obj_files;
|
2003-01-02 20:24:03 +01:00
|
|
|
static int keep_generated = 0;
|
2002-12-13 01:38:42 +01:00
|
|
|
|
2003-09-12 00:16:33 +02:00
|
|
|
static void rm_temp_file(const char *file)
|
2003-01-02 20:24:03 +01:00
|
|
|
{
|
|
|
|
if (!keep_generated) unlink(file);
|
|
|
|
}
|
|
|
|
|
2003-09-12 00:16:33 +02:00
|
|
|
static void create_file(const char *name, const char *fmt, ...)
|
2003-01-02 20:24:03 +01:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
FILE *file;
|
|
|
|
|
|
|
|
if (verbose) printf("Creating file %s\n", name);
|
|
|
|
va_start(ap, fmt);
|
|
|
|
if ( !(file = fopen(name, "w")) )
|
|
|
|
error ("Can not create %s.", name);
|
|
|
|
vfprintf(file, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
|
2003-09-12 00:16:33 +02:00
|
|
|
static int is_resource(const char* file)
|
2002-12-13 01:38:42 +01:00
|
|
|
{
|
|
|
|
/* see tools/winebuild/res32.c: check_header for details */
|
|
|
|
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 };
|
|
|
|
char buf[sizeof(res_sig)];
|
|
|
|
FILE *fin;
|
|
|
|
|
|
|
|
if (!(fin = fopen(file, "r"))) error("Can not open %s", file);
|
|
|
|
if (fread(buf, sizeof(buf), 1, fin) != 1) error("Truncated file %s", file);
|
|
|
|
fclose(fin);
|
|
|
|
|
|
|
|
return !memcmp(buf, res_sig, sizeof(buf));
|
|
|
|
}
|
|
|
|
|
2003-01-03 23:31:45 +01:00
|
|
|
/* open the file for a given name, in a specified path, with the given extension */
|
|
|
|
static char *try_path( const char *path, const char *name, const char *ext )
|
2002-12-23 03:04:34 +01:00
|
|
|
{
|
|
|
|
char *fullname;
|
|
|
|
int fd;
|
|
|
|
|
2003-01-03 23:31:45 +01:00
|
|
|
fullname = strmake("%s/lib%s.%s", path, name, ext);
|
|
|
|
if (verbose > 1) fprintf(stderr, "Try %s...", fullname);
|
2002-12-23 03:04:34 +01:00
|
|
|
|
|
|
|
/* check if the file exists */
|
|
|
|
if ((fd = open( fullname, O_RDONLY )) != -1)
|
|
|
|
{
|
|
|
|
close( fd );
|
2003-01-03 23:31:45 +01:00
|
|
|
if (verbose > 1) fprintf(stderr, "FOUND!\n");
|
2002-12-23 03:04:34 +01:00
|
|
|
return fullname;
|
|
|
|
}
|
|
|
|
free( fullname );
|
2003-01-03 23:31:45 +01:00
|
|
|
if (verbose > 1) fprintf(stderr, "\n");
|
2002-12-23 03:04:34 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-01-03 23:31:45 +01:00
|
|
|
/* open the .def library for a given dll in a specified path */
|
|
|
|
static char *try_dll_path( const char *path, const char *name )
|
|
|
|
{
|
|
|
|
return try_path(path, name, "def");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open the .a library for a given lib in a specified path */
|
|
|
|
static char *try_lib_path( const char *path, const char *name )
|
|
|
|
{
|
|
|
|
return try_path(path, name, "a");
|
|
|
|
}
|
|
|
|
|
2002-12-23 03:04:34 +01:00
|
|
|
/* open the .def library for a given dll */
|
2003-09-12 00:16:33 +02:00
|
|
|
static char *find_dll(const char *name)
|
2002-12-23 03:04:34 +01:00
|
|
|
{
|
|
|
|
char *fullname;
|
|
|
|
int i;
|
|
|
|
|
2003-09-12 00:16:33 +02:00
|
|
|
for (i = 0; i < lib_paths->size; i++)
|
2002-12-23 03:04:34 +01:00
|
|
|
{
|
2003-09-12 00:16:33 +02:00
|
|
|
if ((fullname = try_dll_path( lib_paths->base[i], name ))) return fullname;
|
2002-12-23 03:04:34 +01:00
|
|
|
}
|
|
|
|
return try_dll_path( ".", name );
|
|
|
|
}
|
|
|
|
|
2003-01-03 23:31:45 +01:00
|
|
|
/* find a static library */
|
|
|
|
static char *find_lib(const char *name)
|
|
|
|
{
|
|
|
|
static const char* std_paths[] = { ".", "/usr/lib", "/usr/local/lib" };
|
|
|
|
char *fullname;
|
|
|
|
int i;
|
|
|
|
|
2003-09-12 00:16:33 +02:00
|
|
|
for (i = 0; i < lib_paths->size; i++)
|
2003-01-03 23:31:45 +01:00
|
|
|
{
|
2003-09-12 00:16:33 +02:00
|
|
|
if ((fullname = try_lib_path( lib_paths->base[i], name ))) return fullname;
|
2003-01-03 23:31:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(std_paths)/sizeof(std_paths[0]); i++)
|
|
|
|
{
|
|
|
|
if ((fullname = try_lib_path( std_paths[i], name ))) return fullname;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-09-12 00:16:33 +02:00
|
|
|
static void add_lib_path(const char* path)
|
2003-01-02 20:24:03 +01:00
|
|
|
{
|
2003-09-12 00:16:33 +02:00
|
|
|
strarray_add(lib_paths, strdup(path));
|
2003-09-12 02:25:14 +02:00
|
|
|
strarray_add(llib_paths, strmake("-L%s", path));
|
2003-01-02 20:24:03 +01:00
|
|
|
}
|
|
|
|
|
2003-09-12 00:16:33 +02:00
|
|
|
static void add_lib_file(const char* library)
|
2003-01-02 20:24:03 +01:00
|
|
|
{
|
2003-01-03 23:31:45 +01:00
|
|
|
char *lib;
|
|
|
|
|
2003-09-12 00:16:33 +02:00
|
|
|
if (find_dll(library))
|
2003-01-02 20:24:03 +01:00
|
|
|
{
|
2003-09-12 00:16:33 +02:00
|
|
|
strarray_add(dll_files, strmake("-l%s", library));
|
2003-01-02 20:24:03 +01:00
|
|
|
}
|
2003-01-03 23:31:45 +01:00
|
|
|
else if ((lib = find_lib(library)))
|
2003-01-05 02:07:09 +01:00
|
|
|
{
|
2003-09-12 00:16:33 +02:00
|
|
|
strarray_add(arh_files, lib);
|
2003-01-05 02:07:09 +01:00
|
|
|
}
|
|
|
|
else
|
2003-01-02 20:24:03 +01:00
|
|
|
{
|
2003-09-12 00:16:33 +02:00
|
|
|
strarray_add(lib_files, strmake("-l%s", library));
|
2003-01-02 20:24:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-16 22:27:14 +02:00
|
|
|
static void create_the_wrapper(char* base_file, char* base_name, char* app_name, int gui_mode)
|
2003-09-12 00:16:33 +02:00
|
|
|
{
|
|
|
|
char *wrp_temp_name, *wspec_name, *wspec_c_name, *wspec_o_name;
|
|
|
|
char *wrap_c_name, *wrap_o_name;
|
|
|
|
strarray *wwrap_args, *wspec_args, *wcomp_args, *wlink_args;
|
|
|
|
|
|
|
|
wrp_temp_name = tempnam(0, "wwrp");
|
|
|
|
wspec_name = strmake("%s.spec", wrp_temp_name);
|
|
|
|
wspec_c_name = strmake("%s.c", wspec_name);
|
|
|
|
wspec_o_name = strmake("%s.o", wspec_name);
|
|
|
|
|
|
|
|
wrap_c_name = strmake("%s.c", wrp_temp_name);
|
|
|
|
wrap_o_name = strmake("%s.o", wrp_temp_name);
|
|
|
|
|
|
|
|
/* build wrapper compile argument list */
|
|
|
|
wwrap_args = strarray_alloc();
|
|
|
|
strarray_add(wwrap_args, "gcc");
|
|
|
|
strarray_add(wwrap_args, "-fPIC");
|
|
|
|
strarray_add(wwrap_args, "-I" INCLUDEDIR "/windows");
|
|
|
|
strarray_add(wwrap_args, "-o");
|
|
|
|
strarray_add(wwrap_args, wrap_o_name);
|
|
|
|
strarray_add(wwrap_args, "-c");
|
|
|
|
strarray_add(wwrap_args, wrap_c_name);
|
|
|
|
strarray_add(wwrap_args, NULL);
|
|
|
|
|
2003-09-16 22:27:14 +02:00
|
|
|
create_file(wrap_c_name, wrapper_code, base_name, gui_mode, app_name);
|
2003-09-12 00:16:33 +02:00
|
|
|
spawn(wwrap_args);
|
|
|
|
strarray_free(wwrap_args);
|
|
|
|
rm_temp_file(wrap_c_name);
|
|
|
|
|
|
|
|
/* build wrapper winebuild's argument list */
|
|
|
|
wspec_args = strarray_alloc();
|
|
|
|
strarray_add(wspec_args, "winebuild");
|
|
|
|
strarray_add(wspec_args, "-o");
|
|
|
|
strarray_add(wspec_args, wspec_c_name);
|
|
|
|
strarray_add(wspec_args, "--exe");
|
|
|
|
strarray_add(wspec_args, strmake("%s.exe", base_name));
|
|
|
|
strarray_add(wspec_args, gui_mode ? "-mgui" : "-mcui");
|
|
|
|
strarray_add(wspec_args, wrap_o_name);
|
2003-09-16 22:27:14 +02:00
|
|
|
strarray_add(wspec_args, "-L" DLLDIR);
|
|
|
|
strarray_add(wspec_args, "-lkernel32");
|
2003-09-12 00:16:33 +02:00
|
|
|
strarray_add(wspec_args, NULL);
|
|
|
|
|
|
|
|
spawn(wspec_args);
|
|
|
|
strarray_free(wspec_args);
|
|
|
|
|
|
|
|
/* build wrapper gcc's argument list */
|
|
|
|
wcomp_args = strarray_alloc();
|
|
|
|
strarray_add(wcomp_args, "gcc");
|
|
|
|
strarray_add(wcomp_args, "-fPIC");
|
|
|
|
strarray_add(wcomp_args, "-o");
|
|
|
|
strarray_add(wcomp_args, wspec_o_name);
|
|
|
|
strarray_add(wcomp_args, "-c");
|
|
|
|
strarray_add(wcomp_args, wspec_c_name);
|
|
|
|
strarray_add(wcomp_args, NULL);
|
|
|
|
|
|
|
|
spawn(wcomp_args);
|
|
|
|
strarray_free(wcomp_args);
|
|
|
|
rm_temp_file(wspec_c_name);
|
|
|
|
|
|
|
|
/* build wrapper ld's argument list */
|
|
|
|
wlink_args = strarray_alloc();
|
2003-09-16 22:27:14 +02:00
|
|
|
strarray_add(wlink_args, "gcc");
|
2003-09-12 00:16:33 +02:00
|
|
|
strarray_add(wlink_args, "-shared");
|
|
|
|
strarray_add(wlink_args, "-Wl,-Bsymbolic,-z,defs");
|
|
|
|
strarray_add(wlink_args, "-lwine");
|
|
|
|
strarray_add(wlink_args, "-o");
|
|
|
|
strarray_add(wlink_args, strmake("%s.exe.so", base_file));
|
|
|
|
strarray_add(wlink_args, wspec_o_name);
|
|
|
|
strarray_add(wlink_args, wrap_o_name);
|
|
|
|
strarray_add(wlink_args, NULL);
|
|
|
|
|
|
|
|
spawn(wlink_args);
|
|
|
|
strarray_free(wlink_args);
|
|
|
|
rm_temp_file(wspec_o_name);
|
|
|
|
rm_temp_file(wrap_o_name);
|
|
|
|
}
|
|
|
|
|
2002-12-13 01:38:42 +01:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2003-01-03 04:06:02 +01:00
|
|
|
char *library = 0, *path = 0;
|
2003-09-12 00:16:33 +02:00
|
|
|
int i, len, cpp = 0, no_opt = 0, gui_mode = 0, create_wrapper = -1;
|
2003-09-16 22:27:14 +02:00
|
|
|
char *base_name, *base_file, *base_path, *app_temp_name, *app_name = 0;
|
2002-12-13 01:38:42 +01:00
|
|
|
char *spec_name, *spec_c_name, *spec_o_name;
|
2003-09-12 00:16:33 +02:00
|
|
|
strarray *spec_args, *comp_args, *link_args;
|
|
|
|
|
|
|
|
arh_files = strarray_alloc();
|
|
|
|
dll_files = strarray_alloc();
|
|
|
|
lib_files = strarray_alloc();
|
|
|
|
lib_paths = strarray_alloc();
|
|
|
|
obj_files = strarray_alloc();
|
2003-09-12 02:25:14 +02:00
|
|
|
llib_paths = strarray_alloc();
|
|
|
|
|
2002-12-23 03:04:34 +01:00
|
|
|
/* include the standard DLL path first */
|
2003-09-12 01:11:33 +02:00
|
|
|
add_lib_path(DLLDIR);
|
|
|
|
|
2002-12-13 01:38:42 +01:00
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (!no_opt && argv[i][0] == '-')
|
|
|
|
{
|
|
|
|
switch (argv[i][1])
|
|
|
|
{
|
2003-09-16 22:27:14 +02:00
|
|
|
case 'a':
|
|
|
|
if (argv[i][2]) app_name = strdup(argv[i]+ 2);
|
|
|
|
else if (i + 1 < argc) app_name = strdup(argv[++i]);
|
|
|
|
else error("The -a switch takes an argument.");
|
|
|
|
break;
|
2003-01-02 20:24:03 +01:00
|
|
|
case 'k':
|
|
|
|
keep_generated = 1;
|
|
|
|
break;
|
2002-12-13 01:38:42 +01:00
|
|
|
case 'o':
|
|
|
|
if (argv[i][2]) output_name = strdup(argv[i]+ 2);
|
|
|
|
else if (i + 1 < argc) output_name = strdup(argv[++i]);
|
|
|
|
else error("The -o switch takes an argument.");
|
|
|
|
break;
|
2002-12-23 03:04:34 +01:00
|
|
|
case 'L':
|
|
|
|
if (argv[i][2]) path = argv[i] + 2;
|
|
|
|
else if (i + 1 < argc) path = argv[++i];
|
|
|
|
else error("The -L switch takes an argument\n.");
|
2003-01-02 20:24:03 +01:00
|
|
|
add_lib_path(path);
|
2002-12-23 03:04:34 +01:00
|
|
|
break;
|
2002-12-13 01:38:42 +01:00
|
|
|
case 'l':
|
2002-12-23 03:04:34 +01:00
|
|
|
if (argv[i][2]) library = argv[i] + 2;
|
2002-12-13 01:38:42 +01:00
|
|
|
else if (i + 1 < argc) library = argv[++i];
|
|
|
|
else error("The -l switch takes an argument\n.");
|
2003-01-02 20:24:03 +01:00
|
|
|
add_lib_file(library);
|
2002-12-13 01:38:42 +01:00
|
|
|
break;
|
|
|
|
case 'm':
|
2003-02-25 04:57:09 +01:00
|
|
|
if (strcmp("-mgui", argv[i]) == 0) gui_mode = 1;
|
2002-12-13 01:38:42 +01:00
|
|
|
else error("Unknown option %s\n", argv[i]);
|
2002-12-17 05:15:59 +01:00
|
|
|
break;
|
|
|
|
case 'v': /* verbose */
|
2003-01-03 23:31:45 +01:00
|
|
|
if (argv[i][2] == 0) verbose++;
|
2002-12-17 05:15:59 +01:00
|
|
|
break;
|
2003-01-02 20:24:03 +01:00
|
|
|
case 'V':
|
2003-01-03 22:02:53 +01:00
|
|
|
printf("winewrap v0.40\n");
|
2003-01-02 20:24:03 +01:00
|
|
|
exit(0);
|
|
|
|
break;
|
2003-01-03 00:07:40 +01:00
|
|
|
case 'C':
|
|
|
|
cpp = 1;
|
2002-12-23 03:04:34 +01:00
|
|
|
break;
|
2003-01-03 23:31:45 +01:00
|
|
|
case 'w':
|
|
|
|
create_wrapper = 1;
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
create_wrapper = 0;
|
|
|
|
break;
|
2002-12-13 01:38:42 +01:00
|
|
|
case '-':
|
|
|
|
if (argv[i][2]) error("No long option supported.");
|
|
|
|
no_opt = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Unknown option -%c", argv[i][1]);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* it's a filename, add it to its list */
|
2003-09-12 00:16:33 +02:00
|
|
|
strarray_add(obj_files, strdup(argv[i]));
|
2002-12-13 01:38:42 +01:00
|
|
|
}
|
|
|
|
|
2003-01-03 23:31:45 +01:00
|
|
|
/* create wrapper only in C++ by default */
|
|
|
|
if (create_wrapper == -1) create_wrapper = cpp;
|
|
|
|
|
2003-01-02 20:24:03 +01:00
|
|
|
/* link in by default the big three */
|
2003-02-25 04:57:09 +01:00
|
|
|
if (gui_mode) add_lib_file("gdi32");
|
2003-01-02 20:24:03 +01:00
|
|
|
add_lib_file("user32");
|
|
|
|
add_lib_file("kernel32");
|
|
|
|
|
|
|
|
app_temp_name = tempnam(0, "wapp");
|
2003-01-03 04:06:02 +01:00
|
|
|
/* get base filename by removing the .exe extension, if present */
|
|
|
|
base_file = strdup(output_name);
|
|
|
|
len = strlen(base_file);
|
|
|
|
if (len > 4 && strcmp(base_file + len - 4, ".exe") == 0)
|
|
|
|
base_file[len - 4 ] = 0; /* remove the .exe extension */
|
|
|
|
|
|
|
|
/* we need to get rid of the directory part to get the base name */
|
2003-09-16 22:27:14 +02:00
|
|
|
if ( (base_name = strrchr(base_file, '/')) )
|
|
|
|
{
|
|
|
|
base_path = strdup(base_file);
|
|
|
|
*strrchr(base_path, '/') = 0;
|
|
|
|
base_name++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
base_path = strdup(".");
|
|
|
|
base_name = base_file;
|
|
|
|
}
|
2003-01-02 20:24:03 +01:00
|
|
|
|
2003-09-16 22:27:14 +02:00
|
|
|
/* create default name for the wrapper */
|
|
|
|
if (!app_name) app_name = strmake("%s-wrap.dll", base_name);
|
|
|
|
|
2003-01-02 20:24:03 +01:00
|
|
|
spec_name = strmake("%s.spec", app_temp_name);
|
2002-12-13 01:38:42 +01:00
|
|
|
spec_c_name = strmake("%s.c", spec_name);
|
|
|
|
spec_o_name = strmake("%s.o", spec_name);
|
2003-01-02 20:24:03 +01:00
|
|
|
|
2002-12-13 01:38:42 +01:00
|
|
|
/* build winebuild's argument list */
|
2003-09-12 00:16:33 +02:00
|
|
|
spec_args = strarray_alloc();
|
|
|
|
strarray_add(spec_args, "winebuild");
|
|
|
|
strarray_add(spec_args, "-o");
|
|
|
|
strarray_add(spec_args, spec_c_name);
|
2003-01-02 20:24:03 +01:00
|
|
|
if (create_wrapper)
|
|
|
|
{
|
2003-09-12 00:16:33 +02:00
|
|
|
create_file(spec_name, gui_mode ? app_gui_spec : app_cui_spec);
|
|
|
|
strarray_add(spec_args, "-F");
|
2003-09-16 22:27:14 +02:00
|
|
|
strarray_add(spec_args, app_name);
|
2003-09-12 00:16:33 +02:00
|
|
|
strarray_add(spec_args, "--spec");
|
|
|
|
strarray_add(spec_args, spec_name);
|
2003-01-02 20:24:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-09-12 00:16:33 +02:00
|
|
|
strarray_add(spec_args, "--exe");
|
|
|
|
strarray_add(spec_args, strmake("%s.exe", base_name));
|
|
|
|
strarray_add(spec_args, gui_mode ? "-mgui" : "-mcui");
|
2003-01-02 20:24:03 +01:00
|
|
|
}
|
2003-09-12 02:25:14 +02:00
|
|
|
for (i = 0; i < llib_paths->size; i++)
|
|
|
|
strarray_add(spec_args, llib_paths->base[i]);
|
2003-09-12 00:16:33 +02:00
|
|
|
for (i = 0; i < dll_files->size; i++)
|
|
|
|
strarray_add(spec_args, dll_files->base[i]);
|
|
|
|
for (i = 0; i < obj_files->size; i++)
|
|
|
|
strarray_add(spec_args, obj_files->base[i]);
|
|
|
|
for (i = 0; i < arh_files->size; i++)
|
|
|
|
strarray_add(spec_args, arh_files->base[i]);
|
|
|
|
strarray_add(spec_args, NULL);
|
|
|
|
|
|
|
|
/* run winebuild to get the .spec.c file */
|
|
|
|
spawn(spec_args);
|
|
|
|
strarray_free(spec_args);
|
|
|
|
|
|
|
|
if (create_wrapper)
|
|
|
|
rm_temp_file(spec_name);
|
2002-12-13 01:38:42 +01:00
|
|
|
|
|
|
|
/* build gcc's argument list */
|
2003-09-12 00:16:33 +02:00
|
|
|
comp_args = strarray_alloc();
|
|
|
|
strarray_add(comp_args, "gcc");
|
|
|
|
strarray_add(comp_args, "-fPIC");
|
|
|
|
strarray_add(comp_args, "-o");
|
|
|
|
strarray_add(comp_args, spec_o_name);
|
|
|
|
strarray_add(comp_args, "-c");
|
|
|
|
strarray_add(comp_args, spec_c_name);
|
|
|
|
strarray_add(comp_args, NULL);
|
|
|
|
|
|
|
|
spawn(comp_args);
|
|
|
|
strarray_free(comp_args);
|
|
|
|
rm_temp_file(spec_c_name);
|
2002-12-13 01:38:42 +01:00
|
|
|
|
|
|
|
/* build ld's argument list */
|
2003-09-12 00:16:33 +02:00
|
|
|
link_args = strarray_alloc();
|
|
|
|
strarray_add(link_args, cpp ? "g++" : "gcc");
|
|
|
|
strarray_add(link_args, "-shared");
|
|
|
|
strarray_add(link_args, "-Wl,-Bsymbolic,-z,defs");
|
|
|
|
strarray_add(link_args, "-lwine");
|
|
|
|
strarray_add(link_args, "-lm");
|
2003-09-12 02:25:14 +02:00
|
|
|
for (i = 0; i < llib_paths->size; i++)
|
|
|
|
strarray_add(link_args, llib_paths->base[i]);
|
2003-09-12 00:16:33 +02:00
|
|
|
strarray_add(link_args, "-o");
|
|
|
|
if (create_wrapper)
|
2003-09-16 22:27:14 +02:00
|
|
|
strarray_add(link_args, strmake("%s/%s.so", base_path, app_name));
|
2003-09-12 00:16:33 +02:00
|
|
|
else
|
|
|
|
strarray_add(link_args, strmake("%s.exe.so", base_file));
|
|
|
|
strarray_add(link_args, spec_o_name);
|
|
|
|
|
|
|
|
for (i = 0; i < obj_files->size; i++)
|
|
|
|
if (!is_resource(obj_files->base[i]))
|
|
|
|
strarray_add(link_args, obj_files->base[i]);
|
|
|
|
for (i = 0; i < arh_files->size; i++)
|
|
|
|
strarray_add(link_args, arh_files->base[i]);
|
|
|
|
strarray_add(link_args, NULL);
|
2003-01-02 20:24:03 +01:00
|
|
|
|
2003-09-12 00:16:33 +02:00
|
|
|
spawn(link_args);
|
|
|
|
strarray_free(link_args);
|
|
|
|
rm_temp_file(spec_o_name);
|
2003-01-02 20:24:03 +01:00
|
|
|
|
|
|
|
if (create_wrapper)
|
2003-09-16 22:27:14 +02:00
|
|
|
create_the_wrapper(base_file, base_name, app_name, gui_mode);
|
2002-12-13 01:38:42 +01:00
|
|
|
|
|
|
|
/* create the loader script */
|
2003-01-03 04:06:02 +01:00
|
|
|
create_file(base_file, app_loader_script, base_name);
|
2003-04-01 02:12:02 +02:00
|
|
|
chmod(base_file, 0755);
|
2002-12-13 01:38:42 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|