Index: configure.in
===================================================================
--- configure.in	(revision 2048)
+++ configure.in	(working copy)
@@ -197,28 +197,39 @@
 ################################################################################
 
 
-# On some OSs, AC_PATH_XTRA doesn't work right(?), so let the user specify
-# X_PRE_LIBS and X_EXTRA_LIBS to add even more libraries, and add -lX11 to
-# the list of libraries for grins.
-AC_PATH_XTRA([X11], [X11/Xlib.h], [XFlush(NULL)])
-if test "$have_x" = yes ; then
-	if test -d "$x_includes" ; then
-		X_CFLAGS="-I$x_includes $X_CFLAGS"
-	elif test -d "$ac_x_includes" ; then
-		X_CFLAGS="-I$ac_x_includes $X_CFLAGS"
+# Unfortunately, we can't just rely on AC_PATH_XTRA to check for X11 support or
+# not, because when cross-compiling with mingw32, it screws with things, adding
+# -I/usr/include to our CFLAGS, causing build breakage. Ugh.
+AC_ARG_ENABLE(x11,
+	      [AS_HELP_STRING([--disable-x11],
+			      [disable X11 support]
+			      )],
+	      enable_x11=$enableval, enable_x11=yes)
+if test "x$enable_x11" = "xyes"; then
+	# On some OSs, AC_PATH_XTRA doesn't work right(?), so let the user
+	# specify X_PRE_LIBS and X_EXTRA_LIBS to add even more libraries, and
+	# add -lX11 to the list of libraries for grins.
+	AC_PATH_XTRA([X11], [X11/Xlib.h], [XFlush(NULL)])
+	if test "$have_x" = yes ; then
+		if test -d "$x_includes" ; then
+			X_CFLAGS="-I$x_includes $X_CFLAGS"
+		elif test -d "$ac_x_includes" ; then
+			X_CFLAGS="-I$ac_x_includes $X_CFLAGS"
+		fi
+		X_LIBS="$X_PRE_LIBS $X_LIBS -lX11 $X_EXTRA_LIBS"
+		if test -d "$ac_x_libraries" ; then
+			X_LIBS="-L$x_libraries $X_LIBS"
+		elif test -d "$ac_x_libraries" ; then
+			X_LIBS="-L$ac_x_libraries $X_LIBS"
+		fi
 	fi
-	X_LIBS="$X_PRE_LIBS $X_LIBS -lX11 $X_EXTRA_LIBS"
-	if test -d "$ac_x_libraries" ; then
-		X_LIBS="-L$x_libraries $X_LIBS"
-	elif test -d "$ac_x_libraries" ; then
-		X_LIBS="-L$ac_x_libraries $X_LIBS"
-	fi
+else
+	AC_DEFINE(X_DISPLAY_MISSING,1,[No X11 support.])
 fi
 AC_SUBST([X_CFLAGS])
 AC_SUBST([X_LIBS])
 
 
-
 # Use all available features under glibc, and disable accidental use of
 # deprecated functionality.
 AC_EGREP_CPP(glibc,
@@ -272,13 +283,31 @@
 AC_DEFINE(VTE_INVALID_SOURCE,(guint)-1,[A number which can never be a valid source ID.])
 AC_DEFINE_UNQUOTED(PACKAGE,"$PACKAGE",[Package name.])
 
+# Check for Win32 headers.
+AC_CHECK_HEADERS(windows.h winsock.h)
+
 # Check for headers.
-AC_CHECK_HEADERS(sys/select.h sys/syslimits.h sys/termios.h sys/un.h sys/wait.h stropts.h termios.h wchar.h)
+AC_CHECK_HEADERS(sys/select.h sys/syslimits.h sys/termios.h sys/un.h sys/wait.h sys/ioctl.h sys/fcntl.h stropts.h termios.h wchar.h pwd.h)
 AC_HEADER_TIOCGWINSZ
 
 # Check for PTY handling functions.
-AC_CHECK_FUNCS([cfmakeraw fork setsid setpgid getpgid getpt grantpt unlockpt ptsname ptsname_r tcgetattr tcsetattr])
+AC_CHECK_FUNCS([cfmakeraw fork sigaction kill setsid setpgid getpgid getpwuid getpt grantpt unlockpt ptsname ptsname_r tcgetattr tcsetattr ttyname select fcntl fsync sleep usleep waitpid])
 
+AC_ARG_ENABLE(pty,
+	      [AS_HELP_STRING([--disable-pty],
+			      [Disable support for PTYs (disable's libvte's PTY functionality)])
+	      ],
+	      enable_pty=$enableval, enable_pty=yes)
+
+if test "x$enable_pty" = "xyes" ; then
+	# We use fcntl to check, since _vte_pty_getpt requires it to function.
+	if test "x$ac_cv_func_fcntl" != "xyes"; then
+		AC_MSG_ERROR([Missing POSIX support for PTYs. You must explicitly pass --disable-pty if you want to build with no PTY support.])
+	fi
+fi
+
+AM_CONDITIONAL(BUILD_VTE_PROGRAM,[test "x$enable_pty" = "xyes"])
+
 # Pull in the right libraries for various functions which might not be
 # bundled into an exploded libc.
 AC_CHECK_FUNC(socket,[have_socket=1],AC_CHECK_LIB(socket,socket,[have_socket=1; LIBS="$LIBS -lsocket"]))
@@ -295,23 +324,27 @@
 fi
 AC_CHECK_FUNC(floor,,AC_CHECK_LIB(m,floor,LIBS=["$LIBS -lm"]))
 AC_CHECK_FUNCS([ceil floor])
+# Use gnurx from Tor (tml) for regex support on win32 if regcomp can't be found
+AC_CHECK_FUNC(regcomp,,AC_CHECK_LIB(gnurx,regcomp,LIBS=["$LIBS -lgnurx"]))
 
-# Look for ncurses or curses or termcap.
-AC_CHECK_HEADER(ncurses.h,[AC_CHECK_HEADER(term.h,[AC_CHECK_LIB(ncurses,tgetent,[LIBS="-lncurses $LIBS";AC_DEFINE(HAVE_NCURSES,1,[Define if you have ncurses.h and libncurses])])])])
-if test x$ac_cv_lib_ncurses_tgetent != xyes ; then
-	AC_CHECK_HEADER(ncurses/curses.h,[AC_CHECK_HEADER(ncurses/term.h,[AC_CHECK_LIB(ncurses,tgetent,[LIBS="-lncurses $LIBS";AC_DEFINE(HAVE_NCURSES_CURSES,1,[Define if you have ncurses/curses.h and libncurses])])])])
+AC_ARG_ENABLE(curses, [AS_HELP_STRING(--enable-curses Enable support for including curses/ncurses/libtermcap support [default=yes])], enable_curses="$enableval", enable_curses=yes)
+if test "$enable_curses" != no; then
+	# Look for ncurses or curses or termcap.
+	AC_CHECK_HEADER(ncurses.h,[AC_CHECK_HEADER(term.h,[AC_CHECK_LIB(ncurses,tgetent,[LIBS="-lncurses $LIBS";AC_DEFINE(HAVE_NCURSES,1,[Define if you have ncurses.h and libncurses])])])])
 	if test x$ac_cv_lib_ncurses_tgetent != xyes ; then
-		AC_CHECK_HEADER(curses.h,[AC_CHECK_HEADER(term.h,[AC_CHECK_LIB(curses,tgetent,[LIBS="-lcurses $LIBS";AC_DEFINE(HAVE_CURSES,1,[Define if you have curses.h and libcurses])])])])
-		if test x$ac_cv_lib_curses_tgetent != xyes ; then
-			AC_CHECK_HEADER(termcap.h,[AC_CHECK_LIB(termcap,tgetent,[LIBS="-ltermcap $LIBS";AC_DEFINE(HAVE_TERMCAP,1,[Define if you have termcap.h and libtermcap])])])
-			if test x$ac_cv_header_termcap_h != xyes ; then
-				AC_MSG_ERROR([You must have at least one of ncurses, curses, or libtermcap installed to build vte.])
+		AC_CHECK_HEADER(ncurses/curses.h,[AC_CHECK_HEADER(ncurses/term.h,[AC_CHECK_LIB(ncurses,tgetent,[LIBS="-lncurses $LIBS";AC_DEFINE(HAVE_NCURSES_CURSES,1,[Define if you have ncurses/curses.h and libncurses])])])])
+		if test x$ac_cv_lib_ncurses_tgetent != xyes ; then
+			AC_CHECK_HEADER(curses.h,[AC_CHECK_HEADER(term.h,[AC_CHECK_LIB(curses,tgetent,[LIBS="-lcurses $LIBS";AC_DEFINE(HAVE_CURSES,1,[Define if you have curses.h and libcurses])])])])
+			if test x$ac_cv_lib_curses_tgetent != xyes ; then
+				AC_CHECK_HEADER(termcap.h,[AC_CHECK_LIB(termcap,tgetent,[LIBS="-ltermcap $LIBS";AC_DEFINE(HAVE_TERMCAP,1,[Define if you have termcap.h and libtermcap])])])
+				if test x$ac_cv_header_termcap_h != xyes ; then
+					AC_MSG_ERROR([You must have at least one of ncurses, curses, or libtermcap installed to build vte.])
+				fi
 			fi
 		fi
 	fi
 fi
 
-
 ################################################################################
 # Backends
 ################################################################################
Index: src/vteglyph.c
===================================================================
--- src/vteglyph.c	(revision 2048)
+++ src/vteglyph.c	(working copy)
@@ -23,6 +23,7 @@
 #include <math.h>
 #include <gdk/gdk.h>
 #include <glib.h>
+#include "debug.h"
 #include "iso2022.h"
 #include "vtedraw.h"
 #include "vtefc.h"
@@ -30,6 +31,10 @@
 
 #include <glib/gi18n-lib.h>
 
+#ifndef howmany
+#define howmany(x, y) (((x) + ((y) - 1)) / (y))
+#endif
+
 #define FONT_INDEX_FUDGE 10
 #define CHAR_WIDTH_FUDGE 10
 #define INVALID_GLYPH    GINT_TO_POINTER(-1)
Index: src/trie.c
===================================================================
--- src/trie.c	(revision 2048)
+++ src/trie.c	(working copy)
@@ -41,6 +41,10 @@
 typedef gunichar wint_t;
 #endif
 
+#ifndef LINE_MAX
+#define LINE_MAX 1024
+#endif
+
 #include <glib/gi18n-lib.h>
 
 #ifndef TRIE_MAYBE_STATIC
Index: src/vte-private.h
===================================================================
--- src/vte-private.h	(revision 2048)
+++ src/vte-private.h	(working copy)
@@ -19,7 +19,9 @@
 #ifndef vte_vte_private_h_included
 #define vte_vte_private_h_included
 
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/stat.h>
@@ -30,7 +32,9 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <math.h>
+#ifdef HAVE_PWD_H
 #include <pwd.h>
+#endif
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -50,6 +54,10 @@
 #include "ring.h"
 #include "caps.h"
 
+#ifndef LINE_MAX
+#define LINE_MAX 1024
+#endif
+
 G_BEGIN_DECLS
 
 #define VTE_CURSOR_OUTLINE		1
@@ -419,6 +427,9 @@
 
 void _vte_terminal_inline_error_message(VteTerminal *terminal, const char *format, ...) G_GNUC_PRINTF(2,3);
 
+
+const gchar *_vte_get_datadir ();
+
 G_END_DECLS
 
 #endif
Index: src/utf8echo.c
===================================================================
--- src/utf8echo.c	(revision 2048)
+++ src/utf8echo.c	(working copy)
@@ -30,6 +30,10 @@
 #include "vteconv.h"
 #define ESC "\033"
 
+#ifndef LINE_MAX
+#define LINE_MAX 1024
+#endif
+
 int
 main(int argc, char **argv)
 {
Index: src/vteapp.c
===================================================================
--- src/vteapp.c	(revision 2048)
+++ src/vteapp.c	(working copy)
@@ -20,11 +20,35 @@
 #include "../config.h"
 
 #include <stdlib.h>
+
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
+
 #include <sys/stat.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <string.h>
+
+#ifdef HAVE_SLEEP
+#define SLEEP(n) sleep(n)
+#endif
+
+#ifdef __MINGW32__
+#define _OLE2_H /* hack to avoid conflicts with mingw32 headers */
+#endif
+
+/* Used for gethostname and Sleep on win32 */
+#ifdef HAVE_WINSOCK_H
+
+#define STRICT
+#include <winsock.h>
+#undef STRICT
+
+#define SLEEP(n) Sleep(n*1000)
+
+#endif
+
 #include <unistd.h>
 #include <gtk/gtk.h>
 #include <glib-object.h>
@@ -737,7 +761,9 @@
 		/* Open a "console" connection. */
 		int consolefd = -1, yes = 1, watch;
 		GIOChannel *channel;
+#ifdef O_NOCTTY
 		consolefd = open("/dev/console", O_RDONLY | O_NOCTTY);
+#endif
 		if (consolefd != -1) {
 			/* Assume failure. */
 			console = FALSE;
@@ -816,7 +842,7 @@
 						g_printerr("%ld\n", i);
 						break;
 					}
-					sleep(1);
+					SLEEP(1);
 				}
 				_exit(0);
 				break;
@@ -850,7 +876,7 @@
 
 	if (keep) {
 		while (TRUE) {
-			sleep(60);
+			SLEEP(60);
 		}
 	}
 
Index: src/slowcat.c
===================================================================
--- src/slowcat.c	(revision 2048)
+++ src/slowcat.c	(working copy)
@@ -27,6 +27,26 @@
 #include <unistd.h>
 #include <glib.h>
 
+#ifdef HAVE_USLEEP
+#define USLEEP(n) usleep(n)
+#endif
+
+#ifdef __MINGW32__
+#define _OLE2_H /* hack to avoid conflicts with mingw32 headers */
+#endif
+
+/* Used for Sleep on win32 */
+#ifdef HAVE_WINDOWS_H
+
+#define STRICT
+#include <windows.h>
+#undef STRICT
+
+#define USLEEP(n) Sleep(n)
+
+#endif /* HAVE_WINDOWS_H */
+
+
 static void
 catfile(const char *pathname, long delay, long chunksize)
 {
@@ -52,7 +72,11 @@
 	while (!feof(fp)) {
 		tv.tv_sec = delay / 1000000;
 		tv.tv_usec = delay % 1000000;
+#ifdef HAVE_SELECT
 		select(0, NULL, NULL, NULL, &tv);
+#else
+		USLEEP (delay/1000);
+#endif
 		for (i = 0; i < chunksize; i++) {
 			c = fgetc(fp);
 			if (c != EOF) {
@@ -63,7 +87,9 @@
 		}
 		if (i > 0) {
 			write(STDOUT_FILENO, buf, i);
+#ifdef HAVE_FSYNC
 			fsync(STDOUT_FILENO);
+#endif
 		}
 	}
 
Index: src/reaper.c
===================================================================
--- src/reaper.c	(revision 2048)
+++ src/reaper.c	(working copy)
@@ -18,7 +18,9 @@
 
 #include "../config.h"
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -53,13 +55,16 @@
 
 	/* This might become more general-purpose in the future, but for now
 	 * just forget about signals other than SIGCHLD. */
+#ifdef SIGCHLD
 	info.signum = signum;
 	if (signum != SIGCHLD) {
 		return;
 	}
 
 	if ((singleton_reaper != NULL) && (singleton_reaper->iopipe[0] != -1)) {
+#ifdef HAVE_WAITPID
 		info.pid = waitpid(-1, &status, WNOHANG);
+#endif
 		if (info.pid != -1) {
 			info.status = status;
 			if (write(singleton_reaper->iopipe[1], "", 0) == 0) {
@@ -68,6 +73,7 @@
 			}
 		}
 	}
+#endif
 }
 
 static gboolean
@@ -80,12 +86,14 @@
 	}
 	g_assert(data == singleton_reaper);
 	read(singleton_reaper->iopipe[0], &info, sizeof(info));
+#ifdef SIGCHLD
 	if (info.signum == SIGCHLD) {
 		_vte_debug_print(VTE_DEBUG_SIGNALS,
 				"Reaper emitting child-exited signal.\n");
 		g_signal_emit_by_name(data, "child-exited",
 				      info.pid, info.status);
 	}
+#endif
 	return TRUE;
 }
 
@@ -127,6 +135,7 @@
 static void
 vte_reaper_init(VteReaper *reaper)
 {
+#ifdef HAVE_SIGACTION
 	struct sigaction action;
 	int ret;
 
@@ -161,6 +170,7 @@
 	sigaction(SIGCHLD, &action, NULL);
 	_vte_debug_print(VTE_DEBUG_SIGNALS,
 			"Hooked SIGCHLD signal in reaper.\n");
+#endif
 }
 
 static GObject*
@@ -182,6 +192,7 @@
 static void
 vte_reaper_finalize(GObject *reaper)
 {
+#ifdef HAVE_SIGACTION
 	struct sigaction action, old_action;
 
 	/* Reset the signal handler if we still have it hooked. */
@@ -207,6 +218,7 @@
 
 	G_OBJECT_CLASS(vte_reaper_parent_class)->finalize(reaper);
 	singleton_reaper = NULL;
+#endif
 }
 
 static void
Index: src/reaper.h
===================================================================
--- src/reaper.h	(revision 2048)
+++ src/reaper.h	(working copy)
@@ -20,7 +20,9 @@
 #define vte_reaper_h_included
 
 
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <signal.h>
 #include <glib.h>
 #include <glib-object.h>
Index: src/vtepango.c
===================================================================
--- src/vtepango.c	(revision 2048)
+++ src/vtepango.c	(working copy)
@@ -30,6 +30,10 @@
 #include "vtedraw.h"
 #include "vtepango.h"
 
+#ifndef howmany
+#define howmany(x, y) (((x) + ((y) - 1)) / (y))
+#endif
+
 struct _vte_pango_data
 {
 	GdkColor color;
@@ -370,7 +374,8 @@
 static gboolean
 _vte_pango_draw_has_char(struct _vte_draw *draw, gunichar c)
 {
-#if defined(PANGO_VERSION_CHECK) && PANGO_VERSION_CHECK(1,15,4)
+#if defined(PANGO_VERSION_CHECK)
+#if PANGO_VERSION_CHECK(1,15,4)
 	struct _vte_pango_data *data = (struct _vte_pango_data*) draw->impl_data;
 	char buf[VTE_UTF8_BPC];
 	gsize length;
@@ -382,6 +387,9 @@
 #else
 	return FALSE;
 #endif
+#else
+	return FALSE;
+#endif
 }
 
 static void
Index: src/vte.c
===================================================================
--- src/vte.c	(revision 2048)
+++ src/vte.c	(working copy)
@@ -50,6 +50,16 @@
 #include "vtetc.h"
 #include "vteseq.h"
 
+#ifdef __MINGW32__
+#define _OLE2_H /* hack to avoid conflicts with mingw32 headers */
+#endif
+
+#ifdef HAVE_WINDOWS_H
+#define STRICT
+#include <windows.h>
+#undef STRICT
+#endif
+
 #ifdef HAVE_LOCALE_H
 #include <locale.h>
 #endif
@@ -2970,6 +2980,7 @@
 
 	/* Make the user's shell the default command. */
 	if (command == NULL) {
+#ifdef HAVE_GETPWUID
 		if (terminal->pvt->shell == NULL) {
 			struct passwd *pwd;
 
@@ -2981,6 +2992,7 @@
 						terminal->pvt->shell);
 			}
 		}
+#endif
 		if (terminal->pvt->shell == NULL) {
 			if (getenv ("SHELL")) {
 				terminal->pvt->shell = getenv ("SHELL");
@@ -4173,7 +4185,9 @@
 	gssize normal_length = 0;
 	int i;
 	const char *special = NULL;
+#ifdef HAVE_TCGETATTR
 	struct termios tio;
+#endif
 	gboolean scrolled = FALSE, steal = FALSE, modifier = FALSE, handled,
 		 suppress_meta_esc = FALSE;
 	guint keyval = 0;
@@ -4319,12 +4333,14 @@
 			case VTE_ERASE_AUTO:
 			default:
 				if (terminal->pvt->pty_master != -1) {
+#ifdef HAVE_TCGETATTR
 					if (tcgetattr(terminal->pvt->pty_master,
 						      &tio) != -1) {
 						normal = g_strdup_printf("%c",
 									 tio.c_cc[VERASE]);
 						normal_length = 1;
 					}
+#endif
 				}
 				suppress_meta_esc = FALSE;
 				break;
@@ -7236,6 +7252,25 @@
 	g_free (str);
 }
 
+#ifdef G_OS_WIN32
+G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name)
+#endif
+
+const gchar *
+_vte_get_datadir ()
+{
+#ifdef G_OS_WIN32
+	static gchar *gtk_datadir = NULL;
+	if (gtk_datadir == NULL)
+		gtk_datadir = g_win32_get_package_installation_subdirectory
+			(NULL, dll_name, "share");
+	
+	return gtk_datadir;
+#else
+	return VTE_DATADIR;
+#endif
+}
+
 /* Set the path to the termcap file we read, and read it in. */
 static void
 vte_terminal_set_termcap(VteTerminal *terminal, const char *path,
@@ -7245,10 +7280,12 @@
 	char *wpath;
 
 	if (path == NULL) {
-		wpath = g_strdup_printf(DATADIR "/" PACKAGE "/termcap/%s",
+		wpath = g_build_filename (_vte_get_datadir (), PACKAGE, "termcap",
 					terminal->pvt->emulation ?
 					terminal->pvt->emulation :
-					vte_terminal_get_default_emulation(terminal));
+					vte_terminal_get_default_emulation(terminal),
+					NULL);
+
 		if (g_stat(wpath, &st) != 0) {
 			g_free(wpath);
 			wpath = g_strdup("/etc/termcap");
@@ -7892,7 +7929,8 @@
 	_vte_buffer_free(terminal->pvt->conv_buffer);
 
 	/* Stop the child and stop watching for input from the child. */
-	if (terminal->pvt->pty_pid != -1) {
+	if ((int)terminal->pvt->pty_pid != -1) {
+#ifdef HAVE_KILL
 #ifdef HAVE_GETPGID
 		pid_t pgrp;
 		pgrp = getpgid(terminal->pvt->pty_pid);
@@ -7901,6 +7939,7 @@
 		}
 #endif
 		kill(terminal->pvt->pty_pid, SIGHUP);
+#endif
 	}
 	_vte_terminal_disconnect_pty_read(terminal);
 	_vte_terminal_disconnect_pty_write(terminal);
@@ -12014,11 +12053,13 @@
        g_io_channel_set_close_on_unref (terminal->pvt->pty_channel, FALSE);
 
 
+#ifdef HAVE_FCNTL
        /* Set the pty to be non-blocking. */
        i = fcntl(terminal->pvt->pty_master, F_GETFL);
        if ((i & O_NONBLOCK) == 0) {
 	       fcntl(terminal->pvt->pty_master, F_SETFL, i | O_NONBLOCK);
        }
+#endif
 
        vte_terminal_set_size(terminal,
                              terminal->column_count,
Index: src/interpret.c
===================================================================
--- src/interpret.c	(revision 2048)
+++ src/interpret.c	(working copy)
@@ -33,6 +33,7 @@
 #include "iso2022.h"
 #include "matcher.h"
 #include "vtetc.h"
+#include "vte-private.h"
 
 int
 main(int argc, char **argv)
@@ -71,8 +72,8 @@
 
 	g_type_init();
 	terminal = argv[1];
-	termcap = _vte_termcap_new(g_strdup_printf(DATADIR "/" PACKAGE
-						   "/termcap/%s", terminal));
+	termcap = _vte_termcap_new(g_build_filename (VTE_DATADIR, PACKAGE
+						   "termcap", terminal, NULL));
 	if (termcap == NULL) {
 		termcap = _vte_termcap_new("/etc/termcap");
 	}
Index: src/pty.c
===================================================================
--- src/pty.c	(revision 2048)
+++ src/pty.c	(working copy)
@@ -18,7 +18,9 @@
 
 #include "../config.h"
 #include <sys/types.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #ifdef HAVE_SYS_TERMIOS_H
 #include <sys/termios.h>
 #endif
@@ -69,22 +71,42 @@
 static void
 _vte_pty_reset_signal_handlers(void)
 {
+#ifdef SIGHUP
 	signal(SIGHUP,  SIG_DFL);
+#endif
 	signal(SIGINT,  SIG_DFL);
 	signal(SIGILL,  SIG_DFL);
 	signal(SIGABRT, SIG_DFL);
 	signal(SIGFPE,  SIG_DFL);
+#ifdef SIGKILL
 	signal(SIGKILL, SIG_DFL);
+#endif
 	signal(SIGSEGV, SIG_DFL);
+#ifdef SIGPIPE
 	signal(SIGPIPE, SIG_DFL);
+#endif
+#ifdef SIGALRM
 	signal(SIGALRM, SIG_DFL);
+#endif
 	signal(SIGTERM, SIG_DFL);
+#ifdef SIGCHLD
 	signal(SIGCHLD, SIG_DFL);
+#endif
+#ifdef SIGCONT
 	signal(SIGCONT, SIG_DFL);
+#endif
+#ifdef SIGSTOP
 	signal(SIGSTOP, SIG_DFL);
+#endif
+#ifdef SIGTSTP
 	signal(SIGTSTP, SIG_DFL);
+#endif
+#ifdef SIGTTIN
 	signal(SIGTTIN, SIG_DFL);
+#endif
+#ifdef SIGTTOU
 	signal(SIGTTOU, SIG_DFL);
+#endif
 #ifdef SIGBUS
 	signal(SIGBUS,  SIG_DFL);
 #endif
@@ -168,10 +190,12 @@
 		case TTY_OPEN_BY_NAME:
 			tty = data->tty.name;
 			break;
+#ifdef HAVE_TTYNAME
 		case TTY_OPEN_BY_FD:
 			fd = data->tty.fd;
 			tty = ttyname(fd);
 			break;
+#endif
 	}
 
 	_vte_debug_print (VTE_DEBUG_PTY,
@@ -467,8 +491,9 @@
 int
 _vte_pty_set_size(int master, int columns, int rows)
 {
+	int ret = -1;
+#ifdef HAVE_SYS_IOCTL_H
 	struct winsize size;
-	int ret;
 	memset(&size, 0, sizeof(size));
 	size.ws_row = rows ? rows : 24;
 	size.ws_col = columns ? columns : 80;
@@ -481,6 +506,7 @@
 				"Failed to set size on %d: %s.\n",
 				master, strerror(errno));
 	}
+#endif
 	return ret;
 }
 
@@ -497,8 +523,9 @@
 int
 _vte_pty_get_size(int master, int *columns, int *rows)
 {
+	int ret = -1;
+#ifdef HAVE_SYS_IOCTL_H
 	struct winsize size;
-	int ret;
 	memset(&size, 0, sizeof(size));
 	ret = ioctl(master, TIOCGWINSZ, &size);
 	if (ret == 0) {
@@ -516,6 +543,7 @@
 				"Failed to read size from fd %d.\n",
 				master);
 	}
+#endif
 	return ret;
 }
 
@@ -563,7 +591,8 @@
 static int
 _vte_pty_getpt(void)
 {
-	int fd, flags;
+	int fd = -1, flags;
+#ifdef HAVE_FCNTL
 #ifdef HAVE_GETPT
 	/* Call the system's function for allocating a pty. */
 	fd = getpt();
@@ -578,6 +607,7 @@
 	flags = fcntl(fd, F_GETFL);
 	flags &= ~(O_NONBLOCK);
 	fcntl(fd, F_SETFL, flags);
+#endif
 	return fd;
 }
 
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision 2048)
+++ src/Makefile.am	(working copy)
@@ -1,4 +1,10 @@
+
+if BUILD_VTE_PROGRAM
 bin_PROGRAMS = vte
+else
+bin_PROGRAMS =
+endif
+
 pkginclude_HEADERS = pty.h reaper.h vte.h vteaccess.h
 lib_LTLIBRARIES = libvte.la
 pkglib_PROGRAMS = interpret utf8echo nativeecho utf8mode iso8859mode slowcat vterdb
@@ -35,6 +41,7 @@
 AM_CFLAGS = $(VTE_CFLAGS) $(FT2_CFLAGS) $(X_CFLAGS) $(PCRE_CFLAGS) \
 	    -DG_DISABLE_ASSERT -DG_LOG_DOMAIN=\"Vte\"
 AM_CPPFLAGS = -DDATADIR='"$(datadir)"' \
+	      -DVTE_DATADIR='"$(datadir)"' \
 	      -DLIBEXECDIR='"$(libexecdir)"' \
 	      -DLOCALEDIR='"$(localedir)"'
 AM_LDFLAGS = $(LDFLAGS)
Index: doc/openi18n/Makefile.am
===================================================================
--- doc/openi18n/Makefile.am	(revision 2048)
+++ doc/openi18n/Makefile.am	(working copy)
@@ -1,5 +1,10 @@
 EXTRA_DIST = UTF-8.txt  wrap.txt
 
 LIBS=
+
+if PLATFORM_WIN32
+else
 noinst_PROGRAMS = cursor
+endif
+
 cursor_SOURCES = cursor.c
