diff -Paur --no-dereference -- ag.upstream/config.sub ag/config.sub
--- ag.upstream/config.sub
+++ ag/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 -- ag.upstream/configure ag/configure
--- ag.upstream/configure
+++ ag/configure
@@ -4992,8 +4992,7 @@
                         pthread_create(&th, 0, start_routine, 0);
                         pthread_join(th, 0);
                         pthread_attr_init(&attr);
-                        pthread_cleanup_push(routine, 0);
-                        pthread_cleanup_pop(0) /* ; */
+                        /* ; */
   ;
   return 0;
 }
@@ -5216,7 +5215,7 @@
 
 
 # Run CFLAGS="-pg" ./configure if you want debug symbols
-CFLAGS="$CFLAGS $PTHREAD_CFLAGS $PCRE_CFLAGS -Wall -Wextra -Wformat=2 -Wno-format-nonliteral -Wshadow -Wpointer-arith -Wcast-qual -Wmissing-prototypes -Wno-missing-braces -std=gnu89 -D_GNU_SOURCE -O2"
+CFLAGS="$CFLAGS $PTHREAD_CFLAGS $PCRE_CFLAGS -Wall -Wextra -Wformat=2 -Wno-format-nonliteral -Wshadow -Wpointer-arith -Wmissing-prototypes -Wno-missing-braces -std=gnu89 -D_GNU_SOURCE"
 LDFLAGS="$LDFLAGS"
 
 case $host in
diff -Paur --no-dereference -- ag.upstream/src/main.c ag/src/main.c
--- ag.upstream/src/main.c
+++ ag/src/main.c
@@ -69,8 +69,10 @@
         GetSystemInfo(&si);
         num_cores = si.dwNumberOfProcessors;
     }
-#else
+#elif defined(_SC_NPROCESSORS_ONLN)
     num_cores = (int)sysconf(_SC_NPROCESSORS_ONLN);
+#else
+    num_cores = 1;
 #endif
 
     workers_len = num_cores < 8 ? num_cores : 8;
diff -Paur --no-dereference -- ag.upstream/src/options.c ag/src/options.c
--- ag.upstream/src/options.c
+++ ag/src/options.c
@@ -4,7 +4,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/param.h>
 #include <sys/stat.h>
 #include <unistd.h>
 
