--- configure.orig	2017-07-13 08:56:44 UTC
+++ configure
@@ -838,6 +838,7 @@ if test $with_sharedlibs = "yes"; then
     x86_64-*-darwin*)             natdynlink=true;;
     s390x*-*-linux*)              natdynlink=true;;
     powerpc*-*-linux*)            natdynlink=true;;
+    powerpc*-*-freebsd*)          natdynlink=true;;
     i686-*-kfreebsd*)             natdynlink=true;;
     x86_64-*-kfreebsd*)           natdynlink=true;;
     x86_64-*-dragonfly*)          natdynlink=true;;
@@ -854,6 +855,7 @@ if test $with_sharedlibs = "yes"; then
     arm*-*-freebsd*)              natdynlink=true;;
     earm*-*-netbsd*)              natdynlink=true;;
     aarch64-*-linux*)             natdynlink=true;;
+    aarch64-*-freebsd*)           natdynlink=true;;
   esac
 fi
 
@@ -921,6 +923,10 @@ case "$target" in
   powerpc*-*-linux*)            arch=power;
                                 if $arch64; then model=ppc64; else model=ppc; fi
                                 system=elf;;
+  powerpc64le*-*-freebsd*)      arch=power; model=ppc64le; system=bsd_elf;;
+  powerpc*-*-freebsd*)          arch=power;
+                                if $arch64; then model=ppc64; else model=ppc; fi
+                                system=bsd_elf;;
   powerpc-*-netbsd*)            arch=power; model=ppc; system=netbsd;;
   powerpc-*-openbsd*)           arch=power; model=ppc; system=bsd_elf;;
   s390x*-*-linux*)              arch=s390x; model=z10; system=elf;;
@@ -930,6 +936,7 @@ case "$target" in
   armv6t2*-*-linux-gnueabi)     arch=arm; model=armv6t2; system=linux_eabi;;
   armv6*-*-linux-gnueabi)       arch=arm; model=armv6; system=linux_eabi;;
   armv6*-*-freebsd*)            arch=arm; model=armv6; system=freebsd;;
+  armv7*-*-freebsd*)            arch=arm; model=armv7; system=freebsd;;
   earmv6*-*-netbsd*)            arch=arm; model=armv6; system=netbsd;;
   earmv7*-*-netbsd*)            arch=arm; model=armv7; system=netbsd;;
   armv5te*-*-linux-gnueabi)     arch=arm; model=armv5te; system=linux_eabi;;
@@ -946,6 +953,7 @@ case "$target" in
   x86_64-*-darwin*)             arch=amd64; system=macosx;;
   x86_64-*-mingw*)              arch=amd64; system=mingw;;
   aarch64-*-linux*)             arch=arm64; system=linux;;
+  aarch64-*-freebsd*)           arch=arm64; system=freebsd;;
   x86_64-*-cygwin*)             arch=amd64; system=cygwin;;
 esac
 
@@ -1086,10 +1094,13 @@ case "$arch,$system" in
   i386,macosx) profiling='true';;
   amd64,linux) profiling='true';;
   amd64,openbsd) profiling='true';;
+  amd64,dragonfly) profiling='true';;
   amd64,freebsd) profiling='true';;
   amd64,netbsd) profiling='true';;
   arm,netbsd) profiling='true';;
   amd64,gnu) profiling='true';;
+  arm64,freebsd) profiling='true';;
+  arm,freebsd) profiling='true';;
   arm,linux*) profiling='true';;
   power,elf) profiling='true';;
   power,bsd*) profiling='true';;
@@ -2029,7 +2037,7 @@ MKLIB=${TOOLPREF}ar rc \$(1) \$(2); ${TOOLPREF}ranlib
 #ml   Printf.sprintf "${TOOLPREF}ar rc %s %s %s && ${TOOLPREF}ranlib %s"
 #ml                  out opts files out;;
 EOF
-config ARCH "$arch"
+config SYSTEM_ARCH "$arch"
 config MODEL "$model"
 config SYSTEM "$system"
 config OCAMLOPT_CFLAGS "$common_cflags"
@@ -2112,7 +2122,7 @@ config NATDYNLINK "$natdynlink"
 config CMXS "$cmxs"
 config MKEXE "$mkexe"
 config MKEXEDEBUGFLAG "$mkexedebugflag"
-config MKDLL "$mksharedlib"
+config MKDLL "$mksharedlib \$(LDFLAGS)"
 config MKMAINDLL "$mkmaindll"
 config RUNTIMED "${debugruntime}"
 config RUNTIMEI "${with_instrumented_runtime}"
