+if test x$host_shared = xyes; then
+ case $host in
+ *-*-darwin*)
+ # Since host shared is the default for 64b Darwin, and also enabled for
+ # host_pie, ensure that we present the PIE flag when host_pie is active.
+ if test x$host_pie = xyes; then
+ PICFLAG=-fPIE
+ fi
+ ;;
+ *)
+ PICFLAG=-fPIC
+ ;;
+ esac
+elif test x$host_pie = xyes; then
+ PICFLAG=-fPIE
+else
+ PICFLAG=
+fi
+
+AC_SUBST(PICFLAG)
+
+# Rust requires -ldl and -lpthread if you are using an old glibc that does not include them by
+# default, so we check for them here
+
+missing_rust_dynlibs=none
+
+AC_SEARCH_LIBS([dlopen], [dl])
+AC_SEARCH_LIBS([pthread_create], [pthread])
+
+if test $ac_cv_search_dlopen = -ldl; then
+ CRAB1_LIBS="$CRAB1_LIBS -ldl"
+elif test $ac_cv_search_dlopen = no; then
+ missing_rust_dynlibs="libdl"
+fi
+
+if test $ac_cv_search_pthread_create = -lpthread; then
+ CRAB1_LIBS="$CRAB1_LIBS -lpthread"
+elif test $ac_cv_search_pthread_crate = no; then
+ missing_rust_dynlibs="$missing_rust_dynlibs, libpthread"
+fi
+
+AC_SUBST(CRAB1_LIBS, "$CRAB1_LIBS")
+
+# If we are building PIC/PIE host executables, and we are building dependent
+# libs (e.g. GMP) in-tree those libs need to be configured to generate PIC
+# code.
+host_libs_picflag=
+if test "$host_shared" = "yes" -o "$host_pie" = "yes"; then
+host_libs_picflag='--with-pic'
+fi
+AC_SUBST(host_libs_picflag)
+