diff -Paur --no-dereference -- flex.upstream/build-aux/config.sub flex/build-aux/config.sub
--- flex.upstream/build-aux/config.sub
+++ flex/build-aux/config.sub
@@ -1373,7 +1373,7 @@
 	      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
 	      | -sym* | -kopensolaris* | -plan9* \
 	      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
-	      | -aos* | -aros* \
+	      | -aos* | -aros* | -sortix* \
 	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
 	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
 	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
diff -Paur --no-dereference -- flex.upstream/configure flex/configure
--- flex.upstream/configure
+++ flex/configure
@@ -1,4 +1,6 @@
 #! /bin/sh
+export ac_cv_func_malloc_0_nonnull=yes
+export ac_cv_func_realloc_0_nonnull=yes
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.69 for the fast lexical analyser generator 2.6.0.
 #
diff -Paur --no-dereference -- flex.upstream/Makefile.in flex/Makefile.in
--- flex.upstream/Makefile.in
+++ flex/Makefile.in
@@ -227,7 +227,7 @@
 ETAGS = etags
 CTAGS = ctags
 CSCOPE = cscope
-DIST_SUBDIRS = $(SUBDIRS)
+DIST_SUBDIRS = $(SUBDIRS_REAL)
 am__DIST_COMMON = $(srcdir)/Makefile.in \
 	$(top_srcdir)/build-aux/compile \
 	$(top_srcdir)/build-aux/config.guess \
@@ -444,15 +444,16 @@
 	.indent.pro \
 	autogen.sh
 
+# PATCH: Building documentation and test causes problems when cross-compiling.
 SUBDIRS = \
 	lib \
 	src \
-	doc \
 	examples \
 	po \
-	tests \
 	tools
 
+SUBDIRS_REAL = lib src doc examples po tests tools
+
 all: all-recursive
 
 .SUFFIXES:
diff -Paur --no-dereference -- flex.upstream/src/main.c flex/src/main.c
--- flex.upstream/src/main.c
+++ flex/src/main.c
@@ -364,7 +364,7 @@
     /* Setup the filter chain. */
     output_chain = filter_create_int(NULL, filter_tee_header, headerfilename);
     if ( !(m4 = getenv("M4")))
-        m4 = M4;
+        m4 = "m4";
     filter_create_ext(output_chain, m4, "-P", 0);
     filter_create_int(output_chain, filter_fix_linedirs, NULL);
 
