diff -Paur --no-dereference -- emacs.upstream/configure emacs/configure
--- emacs.upstream/configure
+++ emacs/configure
@@ -1,4 +1,124 @@
 #! /bin/sh
+# Make gnulib assume the best about unknown operating systems when cross-compiling.
+export ac_cv_func_calloc_0_nonnull=yes
+export ac_cv_func_chown_works=yes
+export ac_cv_func_getgroups_works=yes
+export ac_cv_func_malloc_0_nonnull=yes
+export gl_cv_func_cbrtl_ieee=yes
+export gl_cv_func_ceilf_ieee=yes
+export gl_cv_func_ceil_ieee=yes
+export gl_cv_func_ceill_ieee=yes
+export gl_cv_func_chown_ctime_works=yes
+export gl_cv_func_chown_slash_works=yes
+export gl_cv_func_exp2l_ieee=yes
+export gl_cv_func_expm1_ieee=yes
+export gl_cv_func_fcntl_f_dupfd_works=yes # Not needed since February 2015
+export gl_cv_func_fdopendir_works=yes
+export gl_cv_func_floorf_ieee=yes
+export gl_cv_func_fmaf_works=yes
+export gl_cv_func_fmal_works=yes
+export gl_cv_func_fma_works=yes
+export gl_cv_func_fmodf_ieee=yes
+export gl_cv_func_fmod_ieee=yes
+export gl_cv_func_fmodl_ieee=yes
+export gl_cv_func_fpurge_works=yes
+export gl_cv_func_futimens_works=yes
+export gl_cv_func_futimesat_works=yes
+export gl_cv_func_getgroups_works=yes
+export gl_cv_func_gettimeofday_clobber=no
+export gl_cv_func_hypotf_ieee=yes
+export gl_cv_func_hypotl_ieee=yes
+export gl_cv_func_hypot_ieee=yes
+export gl_cv_func_isfinitel_works=yes
+export gl_cv_func_isnanl_works=yes
+export gl_cv_func_linkat_slash=yes
+export gl_cv_func_link_works=yes
+export gl_cv_func_log10f_ieee=yes
+export gl_cv_func_log10_ieee=yes
+export gl_cv_func_log1pf_ieee=yes
+export gl_cv_func_log1p_ieee=yes
+export gl_cv_func_log1pl_ieee=yes
+export gl_cv_func_log2f_ieee=yes
+export gl_cv_func_log2_ieee=yes
+export gl_cv_func_logf_ieee=yes
+export gl_cv_func_log_ieee=yes
+export gl_cv_func_lstat_dereferences_slashed_symlink=yes
+export gl_cv_func_mbrlen_empty_input=yes
+export gl_cv_func_mbrtowc_empty_input=yes
+export gl_cv_func_memchr_works=yes
+export gl_cv_func_memmem_works_fast=yes
+export gl_cv_func_mkdir_trailing_dot_works=yes
+export gl_cv_func_mkdir_trailing_slash_works=yes
+export gl_cv_func_mkfifo_works=yes
+export gl_cv_func_mknod_works=yes
+export gl_cv_func_modff_ieee=yes
+export gl_cv_func_modf_ieee=yes
+export gl_cv_func_modfl_ieee=yes
+export gl_cv_func_nanosleep=yes
+export gl_cv_func_open_directory_works=yes
+export gl_cv_func_perror_works=yes
+export gl_cv_func_printf_directive_a=yes
+export gl_cv_func_printf_directive_f=yes
+export gl_cv_func_printf_directive_n=yes
+export gl_cv_func_printf_enomem=yes
+export gl_cv_func_printf_flag_zero=yes
+export gl_cv_func_printf_infinite_long_double=yes
+export gl_cv_func_printf_infinite=yes
+export gl_cv_func_printf_sizes_c99=yes
+export gl_cv_func_pselect_detects_ebadf=yes
+export gl_cv_func_ptsname_sets_errno=yes
+export gl_cv_func_readlink_works=yes
+export gl_cv_func_realpath_works=yes
+export gl_cv_func_remainderf_ieee=yes
+export gl_cv_func_remainder_ieee=yes
+export gl_cv_func_remainderl_ieee=yes
+export gl_cv_func_rename_dest_works=yes
+export gl_cv_func_rename_link_works=yes
+export gl_cv_func_rename_slash_dst_works=yes
+export gl_cv_func_rename_slash_src_works=yes
+export gl_cv_func_rmdir_works=yes
+export gl_cv_func_roundf_ieee=yes
+export gl_cv_func_round_ieee=yes
+export gl_cv_func_select_detects_ebadf=yes
+export gl_cv_func_setenv_works=yes
+export gl_cv_func_signbit_gcc=yes
+export gl_cv_func_signbit=yes
+export gl_cv_func_sleep_works=yes
+export gl_cv_func_snprintf_directive_n=yes
+export gl_cv_func_snprintf_retval_c99=yes
+export gl_cv_func_snprintf_truncation_c99=yes
+export gl_cv_func_stat_dir_slash=yes
+export gl_cv_func_stat_file_slash=yes
+export gl_cv_func_stpncpy=yes
+export gl_cv_func_strcasestr_linear=yes
+export gl_cv_func_strchrnul_works=yes
+export gl_cv_func_strerror_0_works=yes
+export gl_cv_func_strstr_linear=yes
+export gl_cv_func_strtod_works=yes
+export gl_cv_func_svid_putenv=yes
+export gl_cv_func_symlink_works=yes
+export gl_cv_func_tdelete_works=yes
+export gl_cv_func_truncf_ieee=yes
+export gl_cv_func_trunc_ieee=yes
+export gl_cv_func_truncl_ieee=yes
+export gl_cv_func_tzset_clobber=no
+export gl_cv_func_ungetc_works=yes
+export gl_cv_func_unlink_honors_slashes=yes
+export gl_cv_func_unsetenv_works=yes
+export gl_cv_func_usleep_works=yes
+export gl_cv_func_utimensat_works=yes
+export gl_cv_func_vsnprintf_posix=yes
+export gl_cv_func_vsnprintf_zerosize_c99=yes
+export gl_cv_func_vsprintf_posix=yes
+export gl_cv_func_wcwidth_works=yes
+export gl_cv_func_working_getdelim=yes
+export gl_cv_func_working_mkstemp=yes
+export gl_cv_func_working_mktime=yes
+export gl_cv_func_working_strerror=yes
+export ac_cv_func___fseterr=yes # Only if the OS actually supports this, Sortix does.
+export gl_cv_func_getcwd_null=yes # Only if the OS actually supports this, Sortix does.
+export gl_cv_struct_dirent_d_ino=yes # Only if the OS actually supports this, Sortix does.
+export ac_cv_func_realloc_0_nonnull=yes # TODO: Investigate this, found in flex.
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.69 for GNU Emacs 26.2.
 #
@@ -626,6 +746,7 @@
 ac_header_list=
 gl_getopt_required=POSIX
 ac_subst_vars='gltests_LTLIBOBJS
+cross_compiling
 gltests_LIBOBJS
 gl_LTLIBOBJS
 gl_LIBOBJS
@@ -3979,11 +4100,11 @@
 fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_MAKE" >&5
 $as_echo "$ac_cv_path_MAKE" >&6; }
-$ac_path_MAKE_found || {
-as_fn_error $? "Building Emacs requires GNU Make, at least version 3.81.
-If you have it installed under another name, configure with 'MAKE=...'.
-For example, run '$0 MAKE=gnu-make'." "$LINENO" 5
-}
+#$ac_path_MAKE_found || {
+#as_fn_error $? "Building Emacs requires GNU Make, at least version 3.81.
+#If you have it installed under another name, configure with 'MAKE=...'.
+#For example, run '$0 MAKE=gnu-make'." "$LINENO" 5
+#}
 MAKE=$ac_cv_path_MAKE
 export MAKE
 
@@ -4791,6 +4912,11 @@
     opsys=openbsd
   ;;
 
+  ## Sortix ports
+  *-sortix)
+    opsys=sortix
+  ;;
+
   ## Apple Darwin / macOS
   *-apple-darwin* )
     case "${canonical}" in
@@ -9190,6 +9316,7 @@
 test "x$CANNOT_DUMP" = "x" && CANNOT_DUMP=no
 case "$opsys" in
   nacl) CANNOT_DUMP=yes ;;
+  sortix) CANNOT_DUMP=yes ;;
 esac
 
 if test "$CANNOT_DUMP" = "yes"; then
@@ -11306,8 +11433,8 @@
 fi
 
 # Does the opsystem file prohibit the use of the GNU malloc?
-# Assume not, until told otherwise.
-GNU_MALLOC=yes
+GNU_MALLOC_reason=" because that would undermine the system malloc's improvements"
+GNU_MALLOC=no
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether malloc is Doug Lea style" >&5
 $as_echo_n "checking whether malloc is Doug Lea style... " >&6; }
@@ -15813,8 +15940,10 @@
   test "${with_tiff}" != "no" && test "${HAVE_TIFF}" != "yes" &&
     MISSING="$MISSING libtiff" && WITH_NO="$WITH_NO --with-tiff=no"
 fi
-test "${with_gnutls}" != "no" && test "${HAVE_GNUTLS}" != "yes" &&
-  MISSING="$MISSING gnutls" && WITH_NO="$WITH_NO --with-gnutls=no"
+# PATCH: Emacs works without libgnutls and there's an option --with-gnutls=no,
+# so this hard error is just in the way, so this patch removes the error.
+#test "${with_gnutls}" != "no" && test "${HAVE_GNUTLS}" != "yes" &&
+#  MISSING="$MISSING gnutls" && WITH_NO="$WITH_NO --with-gnutls=no"
 if test "X${MISSING}" != X; then
   as_fn_error $? "The following required libraries were not found:
     $MISSING
@@ -18588,7 +18717,7 @@
 
     ;;
 
-  gnu-linux | gnu-kfreebsd | dragonfly | freebsd | netbsd | darwin | nacl )
+  gnu-linux | gnu-kfreebsd | dragonfly | freebsd | netbsd | darwin | nacl | sortix )
         if test "x$ac_cv_func_grantpt" = xyes; then
 
 $as_echo "#define UNIX98_PTYS 1" >>confdefs.h
@@ -18598,7 +18727,7 @@
                   $as_echo "#define PTY_TTY_NAME_SPRINTF { char *ptyname = 0; sigset_t blocked; sigemptyset (&blocked); sigaddset (&blocked, SIGCHLD); pthread_sigmask (SIG_BLOCK, &blocked, 0); if (grantpt (fd) != -1 && unlockpt (fd) != -1) ptyname = ptsname(fd); pthread_sigmask (SIG_UNBLOCK, &blocked, 0); if (!ptyname) { emacs_close (fd); return -1; } snprintf (pty_name, PTY_NAME_SIZE, \"%s\", ptyname); }" >>confdefs.h
 
             if test "x$ac_cv_func_posix_openpt" = xyes; then
-        $as_echo "#define PTY_OPEN do { fd = posix_openpt (O_RDWR | O_CLOEXEC | O_NOCTTY); if (fd < 0 && errno == EINVAL) fd = posix_openpt (O_RDWR | O_NOCTTY); } while (false)" >>confdefs.h
+        $as_echo "#define PTY_OPEN do { fd = posix_openpt (O_RDWR | O_CLOEXEC | O_NOCTTY); } while (false)" >>confdefs.h
 
         $as_echo "#define PTY_NAME_SPRINTF /**/" >>confdefs.h
 
diff -Paur --no-dereference -- emacs.upstream/lib-src/emacsclient.c emacs/lib-src/emacsclient.c
--- emacs.upstream/lib-src/emacsclient.c
+++ emacs/lib-src/emacsclient.c
@@ -1008,7 +1008,8 @@
     }
 
   server->sin_family = AF_INET;
-  server->sin_addr.s_addr = inet_addr (dotted);
+  /* PATCH: Sortix only has the modern inet_pton. */
+  inet_pton (AF_INET, dotted, &server->sin_addr.s_addr);
   server->sin_port = htons (atoi (port));
 
   if (! fread (authentication, AUTH_KEY_LENGTH, 1, config))
@@ -1029,13 +1030,18 @@
   struct sockaddr_in server;
   struct linger l_arg = {1, 1};
   char auth_string[AUTH_KEY_LENGTH + 1];
+  char addr[INET_ADDRSTRLEN];
 
   if (! get_server_config (local_server_file, &server, auth_string))
     return INVALID_SOCKET;
 
-  if (server.sin_addr.s_addr != inet_addr ("127.0.0.1") && !quiet)
-    message (false, "%s: connected to remote socket at %s\n",
-             progname, inet_ntoa (server.sin_addr));
+  /* PATCH: Sortix doesn't have inet_addr and this is a constant anyway. */
+  if (server.sin_addr.s_addr != INADDR_LOOPBACK && !quiet)
+    {
+      inet_ntop (AF_INET, &server.sin_addr, addr, sizeof(addr));
+      message (false, "%s: connected to remote socket at %s\n",
+	       progname, addr);
+    }
 
   /* Open up an AF_INET socket.  */
   if ((s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
@@ -1179,7 +1185,7 @@
 handle_sigcont (int signalnum)
 {
   int old_errno = errno;
-  pid_t pgrp = getpgrp ();
+  pid_t pgrp = getpgid (0);
   pid_t tcpgrp = tcgetpgrp (1);
 
   if (tcpgrp == pgrp)
@@ -1704,7 +1710,7 @@
 #ifndef WINDOWSNT
   if (tty)
     {
-      pid_t pgrp = getpgrp ();
+      pid_t pgrp = getpgid (0);
       pid_t tcpgrp = tcgetpgrp (1);
       if (0 <= tcpgrp && tcpgrp != pgrp)
 	kill (-pgrp, SIGTTIN);
diff -Paur --no-dereference -- emacs.upstream/lib-src/Makefile.in emacs/lib-src/Makefile.in
--- emacs.upstream/lib-src/Makefile.in
+++ emacs/lib-src/Makefile.in
@@ -20,13 +20,20 @@
 
 SHELL = @SHELL@
 
+cross_compiling = @cross_compiling@
+
 # Following ../lisp/Makefile.in.
+ifeq ($(cross_compiling),yes)
+EMACS = emacs
+else
 EMACS = ../src/emacs${EXEEXT}
+endif
 EMACSOPT = -batch --no-site-file --no-site-lisp
 
 # ==================== Things 'configure' will edit ====================
 
 CC=@CC@
+CC_FOR_BUILD?=cc
 CFLAGS=@CFLAGS@
 CPPFLAGS = @CPPFLAGS@
 LDFLAGS = @LDFLAGS@
@@ -389,7 +396,7 @@
 	  $(NTLIB) $(LOADLIBES) $(LIB_CLOCK_GETTIME) -o $@
 
 make-docfile${EXEEXT}: ${srcdir}/make-docfile.c $(NTLIB) $(config_h)
-	$(AM_V_CCLD)$(CC) ${ALL_CFLAGS} $< $(NTLIB) $(LOADLIBES) -o $@
+	$(AM_V_CCLD)$(CC_FOR_BUILD) -std=gnu11 ${ALL_CFLAGS} $< $(NTLIB) $(LOADLIBES) -o $@
 
 movemail${EXEEXT}: ${srcdir}/movemail.c pop.o $(NTLIB) $(config_h)
 	$(AM_V_CCLD)$(CC) ${ALL_CFLAGS} ${MOVE_FLAGS} $< pop.o \
diff -Paur --no-dereference -- emacs.upstream/lib-src/movemail.c emacs/lib-src/movemail.c
--- emacs.upstream/lib-src/movemail.c
+++ emacs/lib-src/movemail.c
@@ -58,7 +58,9 @@
 #include <config.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#ifdef MAIL_USE_FLOCK
 #include <sys/file.h>
+#endif
 #include <stdlib.h>
 #include <errno.h>
 #include <time.h>
@@ -76,6 +78,10 @@
 #include "pop.h"
 #endif
 
+#if defined(__sortix__)
+#define setregid(a, b) (0 <= (a) ? setgid(a) : setgid(b))
+#endif
+
 #ifdef MSDOS
 #undef access
 #endif /* MSDOS */
diff -Paur --no-dereference -- emacs.upstream/lib-src/pop.c emacs/lib-src/pop.c
--- emacs.upstream/lib-src/pop.c
+++ emacs/lib-src/pop.c
@@ -240,7 +240,11 @@
     {
       if (! (flags & POP_NO_GETPASS))
 	{
+#if defined(__sortix__)
+	  password = NULL;
+#else
 	  password = getpass ("Enter POP password:");
+#endif
 	}
       if (! password)
 	{
diff -Paur --no-dereference -- emacs.upstream/lisp/Makefile.in emacs/lisp/Makefile.in
--- emacs.upstream/lisp/Makefile.in
+++ emacs/lisp/Makefile.in
@@ -56,7 +56,12 @@
 # We never change directory before running Emacs, so a relative file
 # name is fine, and makes life easier.  If we need to change
 # directory, we can use emacs --chdir.
+cross_compiling = @cross_compiling@
+ifeq ($(cross_compiling),yes)
+EMACS = emacs
+else
 EMACS = ../src/emacs${EXEEXT}
+endif
 
 # Command line flags for Emacs.
 
@@ -458,6 +463,7 @@
 
 distclean:
 	-rm -f ./Makefile $(lisp)/loaddefs.el~
+	-rm -f leim/leim-list.el
 
 maintainer-clean: distclean bootstrap-clean
 	rm -f TAGS
diff -Paur --no-dereference -- emacs.upstream/Makefile.in emacs/Makefile.in
--- emacs.upstream/Makefile.in
+++ emacs/Makefile.in
@@ -687,9 +687,6 @@
 	  dest=`echo "$${page}" | sed -e 's/\.1$$//' -e '$(TRANSFORM)'`.1; \
 	  (cd "$${thisdir}"; \
 	   ${INSTALL_DATA} ${mansrcdir}/$${page} "$(DESTDIR)${man1dir}/$${dest}"); \
-	  [ -n "${GZIP_PROG}" ] || continue ; \
-	  rm -f "$(DESTDIR)${man1dir}/$${dest}.gz"; \
-	  ${GZIP_PROG} -9n "$(DESTDIR)${man1dir}/$${dest}" || true; \
 	done
 
 ## Install those items from etc/ that need to end up elsewhere.
@@ -712,16 +709,7 @@
 	  ${srcdir}/etc/emacs.appdata.xml > $${tmp}; \
 	${INSTALL_DATA} $${tmp} "$(DESTDIR)${appdatadir}/${EMACS_NAME}.appdata.xml"; \
 	rm -f $${tmp}
-	umask 022; $(MKDIR_P) "$(DESTDIR)$(systemdunitdir)"
-	tmp=etc/emacs.tmpservice; rm -f $${tmp}; \
-	client_name=`echo emacsclient | sed '$(TRANSFORM)'`${EXEEXT}; \
-	sed -e '/^##/d' \
-	  -e "/^Documentation/ s/emacs(1)/${EMACS_NAME}(1)/" \
-	  -e "/^ExecStart/ s|emacs|${bindir}/${EMACS}|" \
-	  -e "/^ExecStop/ s|emacsclient|${bindir}/$${client_name}|" \
-	  ${srcdir}/etc/emacs.service > $${tmp}; \
-	$(INSTALL_DATA) $${tmp} "$(DESTDIR)$(systemdunitdir)/${EMACS_NAME}.service"; \
-	rm -f $${tmp}
+	# Patch: Don't install systemd emacs.service.
 	thisdir=`/bin/pwd`; \
 	cd ${iconsrcdir} || exit 1; umask 022 ; \
 	for dir in */*/apps */*/mimetypes; do \
diff -Paur --no-dereference -- emacs.upstream/src/buffer.c emacs/src/buffer.c
--- emacs.upstream/src/buffer.c
+++ emacs/src/buffer.c
@@ -22,7 +22,6 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/param.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
diff -Paur --no-dereference -- emacs.upstream/src/callproc.c emacs/src/callproc.c
--- emacs.upstream/src/callproc.c
+++ emacs/src/callproc.c
@@ -26,7 +26,6 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#include <sys/file.h>
 #include <fcntl.h>
 
 #include "lisp.h"
diff -Paur --no-dereference -- emacs.upstream/src/doc.c emacs/src/doc.c
--- emacs.upstream/src/doc.c
+++ emacs/src/doc.c
@@ -23,7 +23,6 @@
 
 #include <errno.h>
 #include <sys/types.h>
-#include <sys/file.h>	/* Must be after sys/types.h for USG.  */
 #include <fcntl.h>
 #include <unistd.h>
 
diff -Paur --no-dereference -- emacs.upstream/src/emacs.c emacs/src/emacs.c
--- emacs.upstream/src/emacs.c
+++ emacs/src/emacs.c
@@ -25,7 +25,6 @@
 #include <fcntl.h>
 #include <stdlib.h>
 
-#include <sys/file.h>
 #include <unistd.h>
 
 #include <close-stream.h>
@@ -2081,7 +2080,7 @@
   /* If we are controlling the terminal, reset terminal modes.  */
 #ifndef DOS_NT
   {
-    pid_t pgrp = getpgrp ();
+    pid_t pgrp = getpgid (0);
     pid_t tpgrp = tcgetpgrp (0);
     if ((tpgrp != -1) && tpgrp == pgrp)
       {
diff -Paur --no-dereference -- emacs.upstream/src/filelock.c emacs/src/filelock.c
--- emacs.upstream/src/filelock.c
+++ emacs/src/filelock.c
@@ -33,7 +33,6 @@
 #include <pwd.h>
 #endif
 
-#include <sys/file.h>
 #include <fcntl.h>
 #include <unistd.h>
 
diff -Paur --no-dereference -- emacs.upstream/src/fns.c emacs/src/fns.c
--- emacs.upstream/src/fns.c
+++ emacs/src/fns.c
@@ -4526,7 +4526,8 @@
   else if (FLOATP (args[i]) && 0 < (float) (XFLOAT_DATA (args[i]) - 1))
     rehash_size = (float) (XFLOAT_DATA (args[i]) - 1);
   else
-    signal_error ("Invalid hash table rehash size", args[i]);
+    /*signal_error ("Invalid hash table rehash size", args[i]);*/
+    rehash_size = make_float (DEFAULT_REHASH_SIZE);
 
   /* Look for `:rehash-threshold THRESHOLD'.  */
   i = get_key_arg (QCrehash_threshold, nargs, args, used);
@@ -4534,7 +4535,8 @@
 			    : !FLOATP (args[i]) ? 0
 			    : (float) XFLOAT_DATA (args[i]));
   if (! (0 < rehash_threshold && rehash_threshold <= 1))
-    signal_error ("Invalid hash table rehash threshold", args[i]);
+    /*signal_error ("Invalid hash table rehash threshold", args[i]);*/
+    rehash_threshold = make_float (DEFAULT_REHASH_THRESHOLD);
 
   /* Look for `:weakness WEAK'.  */
   i = get_key_arg (QCweakness, nargs, args, used);
diff -Paur --no-dereference -- emacs.upstream/src/keyboard.c emacs/src/keyboard.c
--- emacs.upstream/src/keyboard.c
+++ emacs/src/keyboard.c
@@ -7073,7 +7073,7 @@
     return 0;
   if (n_to_read > sizeof cbuf)
     n_to_read = sizeof cbuf;
-#elif defined USG || defined CYGWIN
+#elif defined USG || defined CYGWIN || defined (__sortix__)
   /* Read some input if available, but don't wait.  */
   n_to_read = sizeof cbuf;
   fcntl (fileno (tty->input), F_SETFL, O_NONBLOCK);
@@ -7107,7 +7107,7 @@
 #endif
 
 #ifndef USABLE_FIONREAD
-#if defined (USG) || defined (CYGWIN)
+#if defined (USG) || defined (CYGWIN) || defined (__sortix__)
   fcntl (fileno (tty->input), F_SETFL, 0);
 #endif /* USG or CYGWIN */
 #endif /* no FIONREAD */
diff -Paur --no-dereference -- emacs.upstream/src/lread.c emacs/src/lread.c
--- emacs.upstream/src/lread.c
+++ emacs/src/lread.c
@@ -26,7 +26,6 @@
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/file.h>
 #include <errno.h>
 #include <math.h>
 #include <stat-time.h>
diff -Paur --no-dereference -- emacs.upstream/src/Makefile.in emacs/src/Makefile.in
--- emacs.upstream/src/Makefile.in
+++ emacs/src/Makefile.in
@@ -25,6 +25,8 @@
 
 SHELL = @SHELL@
 
+cross_compiling = @cross_compiling@
+
 # Here are the things that we expect ../configure to edit.
 # We use $(srcdir) explicitly in dependencies so as not to depend on VPATH.
 srcdir = @srcdir@
@@ -501,7 +503,11 @@
 ## in practice this rule was always run anyway.
 $(srcdir)/macuvs.h $(lispsource)/international/charprop.el: \
   bootstrap-emacs$(EXEEXT) FORCE
+ifeq ($(cross_compiling),yes)
+	$(MAKE) -C ../admin/unidata all EMACS=emacs
+else
 	$(MAKE) -C ../admin/unidata all EMACS="../$(bootstrap_exe)"
+endif
 
 ## We require charprop.el to exist before ucs-normalize.el is
 ## byte-compiled, because ucs-normalize.el needs to load 2 uni-*.el files.
diff -Paur --no-dereference -- emacs.upstream/src/process.c emacs/src/process.c
--- emacs.upstream/src/process.c
+++ emacs/src/process.c
@@ -25,7 +25,6 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <sys/types.h>		/* Some typedefs are used in sys/file.h.  */
-#include <sys/file.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -2821,7 +2820,7 @@
 #ifdef SO_BINDTODEVICE
     case SOPT_IFNAME:
       {
-	char devname[IFNAMSIZ + 1];
+	char devname[IF_NAMESIZE + 1];
 
 	/* This is broken, at least in the Linux 2.4 kernel.
 	   To unbind, the arg must be a zero integer, not the empty string.
@@ -2830,13 +2829,13 @@
 	if (STRINGP (val))
 	  {
 	    char *arg = SSDATA (val);
-	    int len = min (strlen (arg), IFNAMSIZ);
+	    int len = min (strlen (arg), IF_NAMESIZE);
 	    memcpy (devname, arg, len);
 	  }
 	else if (!NILP (val))
 	  error ("Bad option value for %s", name);
 	ret = setsockopt (s, sopt->optlevel, sopt->optnum,
-			  devname, IFNAMSIZ);
+			  devname, IF_NAMESIZE);
 	break;
       }
 #endif
diff -Paur --no-dereference -- emacs.upstream/src/sysdep.c emacs/src/sysdep.c
--- emacs.upstream/src/sysdep.c
+++ emacs/src/sysdep.c
@@ -87,8 +87,6 @@
 #include "msdos.h"
 #endif
 
-#include <sys/param.h>
-#include <sys/file.h>
 #include <fcntl.h>
 
 #include "systty.h"
@@ -96,7 +94,6 @@
 
 #ifdef HAVE_SYS_UTSNAME_H
 #include <sys/utsname.h>
-#include <memory.h>
 #endif /* HAVE_SYS_UTSNAME_H */
 
 #include "keyboard.h"
@@ -529,7 +526,9 @@
 #ifdef OLCUC
   s.main.c_oflag &= ~OLCUC;	/* Disable upcasing on output.  */
 #endif
+#ifdef TAB3
   s.main.c_oflag &= ~TAB3;	/* Disable tab expansion */
+#endif
   s.main.c_cflag = (s.main.c_cflag & ~CSIZE) | CS8; /* Don't strip 8th bit */
   s.main.c_cc[VERASE] = CDISABLE;	/* disable erase processing */
   s.main.c_cc[VKILL] = CDISABLE;	/* disable kill processing */
@@ -877,7 +876,7 @@
 void
 init_foreground_group (void)
 {
-  pid_t pgrp = getpgrp ();
+  pid_t pgrp = getpgid (0);
   inherited_pgroup = getpid () == pgrp ? 0 : pgrp;
 }
 
@@ -1120,7 +1119,9 @@
     tty.main.c_iflag &= ~IXON;	/* Disable start/stop output control */
   tty.main.c_oflag &= ~ONLCR;	/* Disable map of NL to CR-NL
                                    on output */
+#ifdef TAB3
   tty.main.c_oflag &= ~TAB3;	/* Disable tab expansion */
+#endif
 #ifdef CS8
   if (tty_out->meta_key)
     {
diff -Paur --no-dereference -- emacs.upstream/src/term.c emacs/src/term.c
--- emacs.upstream/src/term.c
+++ emacs/src/term.c
@@ -23,7 +23,6 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <stdlib.h>
-#include <sys/file.h>
 #include <sys/time.h>
 #include <unistd.h>
 
