From 967c691e47f379454bec8023964f9712f7ea2064 Mon Sep 17 00:00:00 2001
From: joerg_wunsch <joerg_wunsch@81a1dc3b-b13d-400b-aceb-764788c761c2>
Date: Wed, 13 Jun 2012 20:45:22 +0000
Subject: [PATCH] Submitted by Rene Liebscher:

* configure.ac: Check for presence of <pthread.h>
* ft245r.c: Depend on HAVE_PTHREAD_H
* Makefile.am: Add -lpthread if needed.



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1092 81a1dc3b-b13d-400b-aceb-764788c761c2
---
 ChangeLog    |  6 ++++++
 Makefile.am  |  2 +-
 configure.ac | 16 +++++++++++++++-
 ft245r.c     | 22 ++++++++++++++++++++++
 4 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 052aa607..93c302eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2012-06-13  Rene Liebscher <R.Liebscher@gmx.de>
+
+	* configure.ac: Check for presence of <pthread.h>
+	* ft245r.c: Depend on HAVE_PTHREAD_H
+	* Makefile.am: Add -lpthread if needed.
+
 2012-06-07  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
 
 	* usbtiny.c (usbtiny_paged_load, usbtiny_paged_write):
diff --git a/Makefile.am b/Makefile.am
index 95b7bdab..aae9b9ec 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -61,7 +61,7 @@ avrdude_CFLAGS   = @ENABLE_WARNINGS@
 
 libavrdude_a_CFLAGS   = @ENABLE_WARNINGS@
 
-avrdude_LDADD  = $(top_builddir)/$(noinst_LIBRARIES) @LIBUSB@ @LIBUSB_1_0@ @LIBFTDI@ @LIBHID@ @LIBELF@ -lm
+avrdude_LDADD  = $(top_builddir)/$(noinst_LIBRARIES) @LIBUSB@ @LIBUSB_1_0@ @LIBFTDI@ @LIBHID@ @LIBELF@ @LIBPTHREAD@ -lm
 
 bin_PROGRAMS = avrdude
 
diff --git a/configure.ac b/configure.ac
index 68213e9b..98574826 100644
--- a/configure.ac
+++ b/configure.ac
@@ -149,10 +149,17 @@ AH_TEMPLATE([HAVE_LIBFTDI],
             [Define if FTDI support is enabled via libftdi])
 AC_CHECK_LIB([ftdi], [ftdi_usb_get_strings], [have_libftdi=yes], [], [-lusb])
 if test x$have_libftdi = xyes; then
-   LIBFTDI="-lftdi -lusb -lpthread"
+   LIBFTDI="-lftdi -lusb"
    AC_DEFINE([HAVE_LIBFTDI])
 fi
 AC_SUBST(LIBFTDI, $LIBFTDI)
+AC_CHECK_HEADERS([pthread.h])
+# as there exits header file only pthread implementations for Windows, check if we have a library
+AC_CHECK_LIB([pthread], [pthread_create], [have_pthread=yes])
+if test x$have_pthread = xyes; then
+   LIBPTHREAD="-lpthread"
+fi
+AC_SUBST(LIBPTHREAD, $LIBPTHREAD)
 # Checks for header files.
 AC_CHECK_HEADERS([limits.h stdlib.h string.h])
 AC_CHECK_HEADERS([fcntl.h sys/ioctl.h sys/time.h termios.h unistd.h])
@@ -460,3 +467,10 @@ if test x$have_libhid = xyes; then
 else
    echo "DON'T HAVE libhid"
 fi
+
+if test x$have_pthread = xyes; then
+   echo "DO HAVE    pthread"
+else
+   echo "DON'T HAVE pthread"
+fi
+
diff --git a/ft245r.c b/ft245r.c
index 01222d10..fa4f8f32 100644
--- a/ft245r.c
+++ b/ft245r.c
@@ -70,6 +70,8 @@
 #include "bitbang.h"
 #include "ft245r.h"
 
+#ifdef HAVE_PTHREAD_H
+
 #include <pthread.h>
 #include <semaphore.h>
 
@@ -829,6 +831,26 @@ void ft245r_initpgm(PROGRAMMER * pgm) {
     strcpy(pgm->type, "ftdi_syncbb");
     pgm->open = ft245r_noftdi_open;
 }
+#endif
+#else
+
+static int ft245r_nopthread_open (struct programmer_t *pgm, char * name) {
+    fprintf(stderr,
+            "%s: error: no pthread support. Please compile again with pthread installed."
+#if defined(_WIN32)
+            " See http://sourceware.org/pthreads-win32/."
+#endif
+            "\n",
+            progname);
+
+    exit(1);
+}
+
+void ft245r_initpgm(PROGRAMMER * pgm) {
+    strcpy(pgm->type, "ftdi_syncbb");
+    pgm->open = ft245r_nopthread_open;
+}
+
 #endif
 
 const char ft245r_desc[] = "FT245R/FT232R Synchronous BitBangMode Programmer";