diff --git a/ChangeLog b/ChangeLog
index 68eb0ef1..6d7f196f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2010-01-22  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
+
+	Cleanup Cygwin builds.
+	* windows/Makefile.am (loaddrv_LDFLAGS): remove, the -mno-cygwin
+	flag is supposed to be set in CFLAGS by ./configure
+	* configure.ac: add a check for the presence of usleep(), add a
+	check whether the linker accepts -static
+	* avrdude.h: protect prototype for usleep by !defined(HAVE_USLEEP)
+	* ppwin.c (usleep): protect by !defined(HAVE_USLEEP)
+	* main.c: silence "array subscript of type char" compiler warnings
+	by casting all arguments to tolower()/toupper() and isspace()/
+	isdigit()/ispunct() to "int"
+	* butterfly.c: (Dito.)
+	* avr910.c: (Dito.)
+
 2010-01-19  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
 
 	* configure.ac: Bump for post-5.10.
diff --git a/avr910.c b/avr910.c
index 9b3642ef..b428989d 100644
--- a/avr910.c
+++ b/avr910.c
@@ -624,7 +624,7 @@ static int avr910_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
     cmd = malloc(4 + blocksize);
     if (!cmd) rval = -1;
     cmd[0] = 'B';
-    cmd[3] = toupper(m->desc[0]);
+    cmd[3] = toupper((int)(m->desc[0]));
 
     while (addr < max_addr) {
       if ((max_addr - addr) < blocksize) {
@@ -714,7 +714,7 @@ static int avr910_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
     int blocksize = PDATA(pgm)->buffersize;
 
     cmd[0] = 'g';
-    cmd[3] = toupper(m->desc[0]);
+    cmd[3] = toupper((int)(m->desc[0]));
 
     avr910_set_addr(pgm, addr);
 
diff --git a/avrdude.h b/avrdude.h
index 2db9c9bd..0ef19cac 100644
--- a/avrdude.h
+++ b/avrdude.h
@@ -39,14 +39,9 @@ extern int quell_progress;	/* quiteness level (-q, -qq) */
 extern "C" {
 #endif
 
-/* usleep replacements */
-/* sleep Windows in ms, Unix usleep in us
- #define usleep(us) Sleep((us)<20000?20:us/1000)
- #define usleep(us) Sleep(us/1000)
- #define ANTIWARP 3
- #define usleep(us) Sleep(us/1000*ANTIWARP)
-*/
+#if !defined(HAVE_USLEEP)
 int usleep(unsigned int us);
+#endif
 
 #if !defined(HAVE_GETTIMEOFDAY)
 struct timezone;
diff --git a/butterfly.c b/butterfly.c
index bf9cf664..38149dfe 100644
--- a/butterfly.c
+++ b/butterfly.c
@@ -423,7 +423,7 @@ static int butterfly_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
   {
     cmd[0] = 'B';
     cmd[1] = 0;
-    if ((cmd[3] = toupper(m->desc[0])) == 'E') {	/* write to eeprom */
+    if ((cmd[3] = toupper((int)(m->desc[0]))) == 'E') {	/* write to eeprom */
       cmd[2] = 1;
       cmd[4] = value;
       size = 5;
@@ -572,7 +572,7 @@ static int butterfly_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
   cmd = malloc(4+blocksize);
   if (!cmd) return -1;
   cmd[0] = 'B';
-  cmd[3] = toupper(m->desc[0]);
+  cmd[3] = toupper((int)(m->desc[0]));
 
   while (addr < max_addr) {
     if ((max_addr - addr) < blocksize) {
@@ -613,7 +613,7 @@ static int butterfly_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
     int blocksize = PDATA(pgm)->buffersize;
 
     cmd[0] = 'g';
-    cmd[3] = toupper(m->desc[0]);
+    cmd[3] = toupper((int)(m->desc[0]));
 
     if (use_ext_addr) {
       butterfly_set_extaddr(pgm, addr);
diff --git a/configure.ac b/configure.ac
index cfbbfc04..595e6fa1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -77,7 +77,7 @@ AC_C_CONST
 AC_HEADER_TIME
 
 # Checks for library functions.
-AC_CHECK_FUNCS([memset select strcasecmp strdup strerror strncasecmp strtol strtoul gettimeofday])
+AC_CHECK_FUNCS([memset select strcasecmp strdup strerror strncasecmp strtol strtoul gettimeofday usleep])
 
 AC_MSG_CHECKING([for a Win32 HID libray])
 SAVED_LIBS="${LIBS}"
@@ -273,7 +273,7 @@ case $target in
 			# does this compiler support -mno-cygwin?
 			AC_MSG_CHECKING([if $CC accepts -mno-cygwin])
 
-			safe_CFLAGS=$CFLAGS
+			safe_CFLAGS="$CFLAGS"
 			CFLAGS="$ENABLE_WARNINGS -mno-cygwin"
 
 			AC_TRY_COMPILE(, [ int main () { return 0 ; } ], [
@@ -283,7 +283,7 @@ case $target in
 				no_cygwin=no
 				AC_MSG_RESULT([no])
 				])
-			CFLAGS=$safe_CFLAGS
+			CFLAGS="$safe_CFLAGS"
 
 			if test x$no_cygwin = xyes; then
 				CFLAGS="${CFLAGS} -mno-cygwin"
@@ -295,9 +295,26 @@ case $target in
 				AC_MSG_NOTICE([])
 			fi
 		fi
+
+		AC_MSG_CHECKING([if linker accepts -static])
+
+		safe_LDFLAGS="$LDFLAGS"
+		LDFLAGS="${LDFLAGS} -static"
+		AC_TRY_LINK(, [ int main () { return 0 ; } ], [
+			can_link_static=yes
+			AC_MSG_RESULT([yes])
+			], [
+			can_link_static_cygwin=no
+			AC_MSG_RESULT([no])
+			])
+		LDFLAGS="$safe_LDFLAGS"
+
+		if test x$can_link_static = xyes; then
+			LDFLAGS="${LDFLAGS} -static"
+		fi
+
 		WINDOWS_DIRS="windows"
 		CFLAGS="${CFLAGS} -DWIN32NATIVE"
-		LDFLAGS="${LDFLAGS} -static"
 		;;
 esac
 AC_SUBST(WINDOWS_DIRS,$WINDOWS_DIRS)
diff --git a/main.c b/main.c
index 98af95c5..4d1ee273 100644
--- a/main.c
+++ b/main.c
@@ -1131,7 +1131,7 @@ int main(int argc, char * argv [])
        else
             safemode_response = yes;
        
-       if (tolower(safemode_response[0]) == 'y') {
+       if (tolower((int)(safemode_response[0])) == 'y') {
               
             /* Enough chit-chat, time to program some fuses and check them */
             if (safemode_writefuse (safemode_fuse, "fuse", pgm, p,
@@ -1159,7 +1159,7 @@ int main(int argc, char * argv [])
        else
             safemode_response = yes;
        
-       if (tolower(safemode_response[0]) == 'y') {
+       if (tolower((int)(safemode_response[0])) == 'y') {
               
             /* Enough chit-chat, time to program some fuses and check them */
             if (safemode_writefuse (safemode_lfuse, "lfuse", pgm, p,
@@ -1184,7 +1184,7 @@ int main(int argc, char * argv [])
             safemode_response = terminal_get_input("Would you like this fuse to be changed back? [y/n] ");
        else
             safemode_response = yes;
-       if (tolower(safemode_response[0]) == 'y') {
+       if (tolower((int)(safemode_response[0])) == 'y') {
 
             /* Enough chit-chat, time to program some fuses and check them */
             if (safemode_writefuse(safemode_hfuse, "hfuse", pgm, p,
@@ -1209,7 +1209,7 @@ int main(int argc, char * argv [])
             safemode_response = terminal_get_input("Would you like this fuse to be changed back? [y/n] ");
        else
             safemode_response = yes;
-       if (tolower(safemode_response[0]) == 'y') {
+       if (tolower((int)(safemode_response[0])) == 'y') {
               
             /* Enough chit-chat, time to program some fuses and check them */
             if (safemode_writefuse (safemode_efuse, "efuse", pgm, p,
diff --git a/ppiwin.c b/ppiwin.c
index f9c51b54..bf9a3c39 100644
--- a/ppiwin.c
+++ b/ppiwin.c
@@ -374,6 +374,7 @@ int gettimeofday(struct timeval *tv, struct timezone *unused){
 
 #endif
 
+#if !defined(HAVE_USLEEP)
 int usleep(unsigned int us)
 {
 	int has_highperf;
@@ -384,7 +385,7 @@ int usleep(unsigned int us)
 	// verify - increasing the delay helps sometimes but not
 	// realiably. There must be some other problem. Maybe just
 	// with my test-hardware maybe in the code-base.
-	//// us=(unsigned long) (us*1.5);	
+	//// us=(unsigned long) (us*1.5);
 
 	has_highperf=QueryPerformanceFrequency(&freq);
 
@@ -393,7 +394,7 @@ int usleep(unsigned int us)
 	if (has_highperf) {
 		QueryPerformanceCounter(&start);
 		loopend.QuadPart=start.QuadPart+freq.QuadPart*us/(1000*1000);
-		do { 
+		do {
 			QueryPerformanceCounter(&stop);
 		} while (stop.QuadPart<=loopend.QuadPart);
 	}
@@ -405,11 +406,12 @@ int usleep(unsigned int us)
 
 		DEBUG_QueryPerformanceCounter(&stop);
 	}
-	
+
     DEBUG_DisplayTimingInfo(start, stop, freq, us, has_highperf);
 
     return 0;
 }
+#endif  /* !HAVE_USLEEP */
 
 #endif
 
diff --git a/term.c b/term.c
index 2edd857d..a2448f4e 100644
--- a/term.c
+++ b/term.c
@@ -125,12 +125,12 @@ static int nexttok(char * buf, char ** tok, char ** next)
   char * q, * n;
 
   q = buf;
-  while (isspace(*q))
+  while (isspace((int)*q))
     q++;
-  
+
   /* isolate first token */
   n = q+1;
-  while (*n && !isspace(*n))
+  while (*n && !isspace((int)*n))
     n++;
 
   if (*n) {
@@ -139,7 +139,7 @@ static int nexttok(char * buf, char ** tok, char ** next)
   }
 
   /* find start of next token */
-  while (isspace(*n))
+  while (isspace((int)*n))
     n++;
 
   *tok  = q;
@@ -189,9 +189,9 @@ static int chardump_line(char * buffer, unsigned char * p, int n, int pad)
   for (i=0; i<n; i++) {
     memcpy(b, p, n);
     buffer[i] = '.';
-    if (isalpha(b[i]) || isdigit(b[i]) || ispunct(b[i]))
+    if (isalpha((int)(b[i])) || isdigit((int)(b[i])) || ispunct((int)(b[i])))
       buffer[i] = b[i];
-    else if (isspace(b[i]))
+    else if (isspace((int)(b[i])))
       buffer[i] = ' ';
   }
 
@@ -909,7 +909,7 @@ int terminal_mode(PROGRAMMER * pgm, struct avrpart * p)
      * find the start of the command, skipping any white space
      */
     q = cmdbuf;
-    while (*q && isspace(*q))
+    while (*q && isspace((int)*q))
       q++;
 
     /* skip blank lines and comments */
diff --git a/windows/Makefile.am b/windows/Makefile.am
index 875e0440..6a03a18e 100644
--- a/windows/Makefile.am
+++ b/windows/Makefile.am
@@ -37,8 +37,6 @@ EXTRA_DIST   = \
 
 bin_PROGRAMS = loaddrv
 
-loaddrv_LDFLAGS = -mno-cygwin
-
 loaddrv_SOURCES = \
 	loaddrv.c \
 	loaddrv.h