Make Windows cross compile again

But this is broken as the utf8/utf16 conversions in windows.c are gone
without glib.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-10-06 21:04:25 -07:00
parent 34db6dc2be
commit 475e058d40
5 changed files with 39 additions and 18 deletions

View file

@ -144,6 +144,10 @@ create-macosx-bundle: all
sign-macosx-bundle: all sign-macosx-bundle: all
codesign -s "3A8CE62A483083EDEA5581A61E770EC1FA8BECE8" /Applications/$(CAPITALIZED_NAME).app/Contents/MacOS/$(NAME)-bin codesign -s "3A8CE62A483083EDEA5581A61E770EC1FA8BECE8" /Applications/$(CAPITALIZED_NAME).app/Contents/MacOS/$(NAME)-bin
$(RESFILE): packaging/windows/subsurface.rc
@$(PRETTYECHO) ' WINDRES' $<
@i686-w64-mingw32-windres -O coff -i $< -o $@
install-cross-windows: all install-cross-windows: all
$(INSTALL) -d -m 755 $(WINDOWSSTAGING)/share/locale $(INSTALL) -d -m 755 $(WINDOWSSTAGING)/share/locale
for MSG in $(WINMSGDIRS); do\ for MSG in $(WINMSGDIRS); do\

14
dive.h
View file

@ -5,7 +5,19 @@
#include <stdint.h> #include <stdint.h>
#include <time.h> #include <time.h>
#include <math.h> #include <math.h>
#include <sys/param.h>
/* Windows has no MIN/MAX macros - so let's just roll our own */
#define MIN(x, y) ({ \
typeof(x) _min1 = (x); \
typeof(y) _min2 = (y); \
(void) (&_min1 == &_min2); \
_min1 < _min2 ? _min1 : _min2; })
#define MAX(x, y) ({ \
typeof(x) _max1 = (x); \
typeof(y) _max2 = (y); \
(void) (&_max1 == &_max2); \
_max1 > _max2 ? _max1 : _max2; })
#include <libxml/tree.h> #include <libxml/tree.h>
#include <libxslt/transform.h> #include <libxslt/transform.h>

View file

@ -92,7 +92,7 @@ int get_maxdepth(struct plot_info *pi)
md = ROUND_UP(mm+3000, 10000); md = ROUND_UP(mm+3000, 10000);
} else { } else {
/* Minimum 30m, rounded up to 10m, with at least 3m to spare */ /* Minimum 30m, rounded up to 10m, with at least 3m to spare */
md = MAX(30000, ROUND_UP(mm+3000, 10000)); md = MAX((unsigned)30000, ROUND_UP(mm+3000, 10000));
} }
md += pi->maxpp * 9000; md += pi->maxpp * 9000;
return md; return md;

View file

@ -148,9 +148,11 @@ static int number_of_file(char *path)
dirp = opendir(path); dirp = opendir(path);
while ((entry = readdir(dirp)) != NULL) { while ((entry = readdir(dirp)) != NULL) {
if (entry->d_type == DT_REG) { /* If the entry is a regular file */ #ifndef WIN32
if (entry->d_type == DT_REG) /* If the entry is a regular file */
#endif
count++; count++;
}
} }
closedir(dirp); closedir(dirp);
return count; return count;

View file

@ -14,7 +14,8 @@ const char *system_default_filename(void)
char *buffer; char *buffer;
int len; int len;
user = g_get_user_name(); /* I don't think this works on Windows */
user = getenv("LOGNAME");
if (! SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, datapath))) { if (! SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, datapath))) {
datapath[0] = '.'; datapath[0] = '.';
datapath[1] = '\0'; datapath[1] = '\0';
@ -29,14 +30,14 @@ const char *system_default_filename(void)
extern int __wgetmainargs(int *, wchar_t ***, wchar_t ***, int, int *); extern int __wgetmainargs(int *, wchar_t ***, wchar_t ***, int, int *);
/* expand-convert the UTF-16 argument list to a list of UTF-8 strings */ /* expand-convert the UTF-16 argument list to a list of UTF-8 strings */
void subsurface_command_line_init(gint *argc, gchar ***argv) void subsurface_command_line_init(int *argc, char ***argv)
{ {
wchar_t **wargv, **wenviron, *p, path[MAX_PATH] = {0}; wchar_t **wargv, **wenviron, *p, path[MAX_PATH] = {0};
gchar **argv_new; char **argv_new;
gchar *s; char *s;
/* for si we assume that a struct address will equal the address /* for si we assume that a struct address will equal the address
* of its first and only int member */ * of its first and only int member */
gint i, n, ret, si; int i, n, ret, si;
/* change the current process path to the module path, so that we can /* change the current process path to the module path, so that we can
* access relative folders such as ./share and ./xslt */ * access relative folders such as ./share and ./xslt */
@ -51,23 +52,25 @@ void subsurface_command_line_init(gint *argc, gchar ***argv)
* lifespan as the process heap. */ * lifespan as the process heap. */
ret = __wgetmainargs(&n, &wargv, &wenviron, TRUE, &si); ret = __wgetmainargs(&n, &wargv, &wenviron, TRUE, &si);
if (ret < 0) { if (ret < 0) {
g_warning("Cannot convert command line"); fprintf(stderr, "Cannot convert command line");
return; return;
} }
argv_new = g_malloc(sizeof(gchar *) * (n + 1)); argv_new = malloc(sizeof(char *) * (n + 1));
#if MISSING_GLIB_FUNCTIONS
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
s = g_utf16_to_utf8((gunichar2 *)wargv[i], -1, NULL, NULL, NULL); s = g_utf16_to_utf8((gunichar2 *)wargv[i], -1, NULL, NULL, NULL);
if (!s) { if (!s) {
g_warning("Cannot convert command line argument (%d) to UTF-8", (i + 1)); fprintf(stderr, "Cannot convert command line argument (%d) to UTF-8", (i + 1));
s = "\0"; s = "\0";
} else if (!g_utf8_validate(s, -1, NULL)) { } else if (!g_utf8_validate(s, -1, NULL)) {
g_warning("Cannot validate command line argument '%s' (%d)", s, (i + 1)); fprintf(stderr,"Cannot validate command line argument '%s' (%d)", s, (i + 1));
g_free(s); free(s);
s = "\0"; s = "\0";
} }
argv_new[i] = s; argv_new[i] = s;
} }
#endif
argv_new[n] = NULL; argv_new[n] = NULL;
/* update the argument list and count */ /* update the argument list and count */
@ -78,12 +81,12 @@ void subsurface_command_line_init(gint *argc, gchar ***argv)
} }
/* once done, free the argument list */ /* once done, free the argument list */
void subsurface_command_line_exit(gint *argc, gchar ***argv) void subsurface_command_line_exit(int *argc, char ***argv)
{ {
int i; int i;
for (i = 0; i < *argc; i++) for (i = 0; i < *argc; i++)
g_free((*argv)[i]); free((*argv)[i]);
g_free(*argv); free(*argv);
} }
/* check if we are running a newer OS version */ /* check if we are running a newer OS version */