-# sometimes getopt_long cannot parse same arguments twice
-# e.g. on certain versions of CygWin32
-AC_CACHE_CHECK([for working getopt_long],rsync_cv_HAVE_GETOPT_LONG,[
-AC_TRY_RUN([#include <getopt.h>
-main() {
- int i, x = 0; char *argv[] = { "x", "--xx" };
- struct option o[] = {{"xx", 0, 0, 1}, {0,0,0,0}};
- getopt_long(2, argv, "x", o, &i) == 1 ? x++ : 0; optind = 0;
- getopt_long(2, argv, "x", o, &i) == 1 ? x++ : 0;
- exit(x == 2 ? 0 : 1);
-}], rsync_cv_HAVE_GETOPT_LONG=yes,rsync_cv_HAVE_GETOPT_LONG=no,
- rsync_cv_HAVE_GETOPT_LONG=cross)])
-if test x"$rsync_cv_HAVE_GETOPT_LONG" = x"yes"; then
- AC_DEFINE(HAVE_GETOPT_LONG)
+if test x"$with_included_popt" != x"yes"
+then
+ AC_CHECK_LIB(popt, poptGetContext, , [with_included_popt=yes])
+fi
+
+AC_MSG_CHECKING("whether to use included libpopt")
+if test x"$with_included_popt" = x"yes"
+then
+ AC_MSG_RESULT("$srcdir/popt")
+ BUILD_POPT='$(popt_OBJS)'
+ CFLAGS="$CFLAGS -I $srcdir/popt"
+else
+ AC_MSG_RESULT(no)