$NetBSD$

All kinds of OS-specific changes to configure
Honor LDFLAGS.

Add SunOS -lnsl -lsocket
Recognise SunOS/amd64 as amd64
Recognise SunOS as having shared libraries

--- configure.orig	2022-02-21 15:57:25.000000000 +0000
+++ configure
@@ -14081,7 +14081,7 @@ sharedlib_cflags=''
 mksharedlib='shared-libs-not-available'
 rpath=''
 mksharedlibrpath=''
-natdynlinkopts=""
+natdynlinkopts="-L/usr/lib -R/usr/lib -R${PREFIX}/lib"
 
 if test x"$enable_shared" != "xno"; then :
   case $host in #(
@@ -14157,6 +14157,8 @@ if test x"$supports_shared_libraries" = 
     natdynlink=true ;; #(
   *-pc-windows) :
     natdynlink=true ;; #(
+  *-*-solaris*) :
+    natdynlink=true ;; #(
   i[3456]86-*-linux*) :
     natdynlink=true ;; #(
   i[3456]86-*-gnu*) :
@@ -14191,6 +14193,8 @@ if test x"$supports_shared_libraries" = 
     natdynlink=true ;; #(
   i[3456]86-*-netbsd*) :
     natdynlink=true ;; #(
+  powerpc-*-netbsd*) :
+    natdynlink=true ;; #(
   x86_64-*-netbsd*) :
     natdynlink=true ;; #(
   i386-*-gnu0.3) :
@@ -14201,12 +14205,16 @@ if test x"$supports_shared_libraries" = 
     natdynlink=true ;; #(
   arm*-*-freebsd*) :
     natdynlink=true ;; #(
+  arm*-*-netbsd*) :
+    natdynlink=true ;; #(
   earm*-*-netbsd*) :
     natdynlink=true ;; #(
   aarch64-*-linux*) :
     natdynlink=true ;; #(
   aarch64-*-freebsd*) :
     natdynlink=true ;; #(
+  aarch64-*-netbsd*) :
+    natdynlink=true ;; #(
   aarch64-*-openbsd*) :
     natdynlink=true ;; #(
   riscv*-*-linux*) :
@@ -14315,6 +14323,8 @@ case $host in #(
     arch=i386; system=beos ;; #(
   i[3456]86-*-cygwin) :
     arch=i386; system=cygwin ;; #(
+  i[3456]86-*-interix3) :
+    arch=i386; system=interix3 ;; #(
   i[3456]86-*-gnu*) :
     arch=i386; system=gnu ;; #(
   i[3456]86-*-mingw32) :
@@ -14331,6 +14341,8 @@ case $host in #(
 else
   model=ppc
 fi; system=elf ;; #(
+  powerpc-*-netbsd*) :
+    arch=power; model=ppc; system=netbsd ;; #(
   s390x*-*-linux*) :
     arch=s390x; model=z10; system=elf ;; #(
   # expected to match "gnueabihf" as well as "musleabihf"
@@ -14350,6 +14362,10 @@ fi; system=elf ;; #(
     arch=arm; model=armv6; system=linux_eabi ;; #(
   armv6*-*-freebsd*) :
     arch=arm; model=armv6; system=freebsd ;; #(
+  armv6*-*-netbsd*) :
+    arch=arm; model=armv6; system=netbsd ;; #(
+  armv7*-*-netbsd*) :
+    arch=arm; model=armv7; system=netbsd ;; #(
   earmv6*-*-netbsd*) :
     arch=arm; model=armv6; system=netbsd ;; #(
   earmv7*-*-netbsd*) :
@@ -14394,10 +14410,14 @@ fi; system=elf ;; #(
     arch=arm64; system=linux ;; #(
   aarch64-*-freebsd*) :
     arch=arm64; system=freebsd ;; #(
+  aarch64-*-netbsd*) :
+    arch=arm64; system=netbsd ;; #(
   aarch64-*-openbsd*) :
     arch=arm64; system=openbsd ;; #(
   x86_64-*-cygwin*) :
     arch=amd64; system=cygwin ;; #(
+  x86_64-*-solaris*) :
+    arch=arm64; system=solaris ;; #(
   riscv64-*-linux*) :
     arch=riscv; model=riscv64; system=linux
  ;; #(
@@ -14613,6 +14633,9 @@ case $as_target,$ocaml_cv_cc_vendor in #
   *) :
      ;;
 esac ;; #(
+  power,netbsd):
+    default_as="${toolpref}as -mppc"
+    default_aspp="${toolpref}gcc -c " ;; #(
   i686-pc-windows,*) :
     default_as="ml -nologo -coff -Cp -c -Fo"
     default_aspp="$default_as" ;; #(
@@ -15223,6 +15246,64 @@ if test "x$ac_cv_func_socketpair" = xyes
 
 fi
  ;; #(
+  *-*-solaris*) :
+    cclibs="$cclibs -lnsl -lsocket"
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing socket" >&5
+$as_echo_n "checking for library containing socket... " >&6; }
+if ${ac_cv_search_socket+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char socket ();
+int
+main ()
+{
+return socket ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' ws2_32; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search_socket=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext
+  if ${ac_cv_search_socket+:} false; then :
+  break
+fi
+done
+if ${ac_cv_search_socket+:} false; then :
+
+else
+  ac_cv_search_socket=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_socket" >&5
+$as_echo "$ac_cv_search_socket" >&6; }
+ac_res=$ac_cv_search_socket
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+fi
+ ;; #(
   *-*-haiku) :
     cclibs="$cclibs -lnetwork"
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing socket" >&5
@@ -17374,7 +17455,7 @@ as_has_debug_prefix_map=false
 asm_cfi_supported=false
 if $native_compiler; then :
   case $host in #(
-  *-*-mingw32|*-pc-windows) :
+  *-*-mingw32|*-pc-windows|*-*-netbsd*) :
      ;; #(
   *) :
 
