Add support for building on Cygwin.

The symbol __Windows__ is defined when building a native (non-Cygwin)
binary.
This commit is contained in:
Daniel Beer 2012-04-25 11:02:22 +12:00
parent 97f8dce833
commit a914bc732d
18 changed files with 43 additions and 38 deletions

View File

@ -34,12 +34,14 @@ else
READLINE_LIBS = -lreadline READLINE_LIBS = -lreadline
endif endif
UNAME := $(shell sh -c 'uname -s') UNAME_S := $(shell sh -c 'uname -s')
ifeq ($(UNAME),Darwin) # Mac OS X/MacPorts stuff UNAME_O := $(shell sh -c 'uname -o 2> /dev/null')
ifeq ($(UNAME_S),Darwin) # Mac OS X/MacPorts stuff
PORTS_CFLAGS = -I/opt/local/include PORTS_CFLAGS = -I/opt/local/include
PORTS_LDFLAGS = -L/opt/local/lib PORTS_LDFLAGS = -L/opt/local/lib
else else
ifeq ($(UNAME),OpenBSD) # OpenBSD Ports stuff ifeq ($(UNAME_S),OpenBSD) # OpenBSD Ports stuff
PORTS_CFLAGS = `pkg-config --cflags libusb` PORTS_CFLAGS = `pkg-config --cflags libusb`
PORTS_LDFLAGS = `pkg-config --libs libusb` -ltermcap -pthread PORTS_LDFLAGS = `pkg-config --libs libusb` -ltermcap -pthread
else else
@ -52,12 +54,15 @@ ifeq ($(OS),Windows_NT)
MSPDEBUG_CC = gcc MSPDEBUG_CC = gcc
BINARY = mspdebug.exe BINARY = mspdebug.exe
ifneq ($(UNAME_O),Cygwin)
OS_LIBS = -lws2_32 -lregex OS_LIBS = -lws2_32 -lregex
OS_CFLAGS = -D__Windows__
endif
else else
MSPDEBUG_CC = $(CC) MSPDEBUG_CC = $(CC)
BINARY = mspdebug BINARY = mspdebug
ifneq ($(filter $(UNAME),FreeBSD OpenBSD),) ifneq ($(filter $(UNAME_S),FreeBSD OpenBSD),)
OS_LIBS = OS_LIBS =
else else
OS_LIBS = -ldl OS_LIBS = -ldl
@ -72,7 +77,7 @@ CONFIG_CFLAGS = -DLIB_DIR=\"$(LIBDIR)\"
MSPDEBUG_LDFLAGS = $(LDFLAGS) $(PORTS_LDFLAGS) MSPDEBUG_LDFLAGS = $(LDFLAGS) $(PORTS_LDFLAGS)
MSPDEBUG_LIBS = -lusb $(READLINE_LIBS) $(OS_LIBS) MSPDEBUG_LIBS = -lusb $(READLINE_LIBS) $(OS_LIBS)
MSPDEBUG_CFLAGS = $(CFLAGS) $(READLINE_CFLAGS) $(PORTS_CFLAGS)\ MSPDEBUG_CFLAGS = $(CFLAGS) $(READLINE_CFLAGS) $(PORTS_CFLAGS)\
$(GCC_CFLAGS) $(INCLUDES) $(CONFIG_CFLAGS) $(GCC_CFLAGS) $(INCLUDES) $(CONFIG_CFLAGS) $(OS_CFLAGS)
all: $(BINARY) all: $(BINARY)

View File

@ -381,7 +381,7 @@ static int connect_to(const char *spec)
printc_dbg("Looking up %s...\n", hostname); printc_dbg("Looking up %s...\n", hostname);
ent = gethostbyname(hostname); ent = gethostbyname(hostname);
if (!ent) { if (!ent) {
#ifdef WIN32 #ifdef __Windows__
printc_err("No such host: %s: %s\n", hostname, printc_err("No such host: %s: %s\n", hostname,
last_error()); last_error());
#else #else

View File

@ -150,7 +150,7 @@ static int open_interface(struct olimex_transport *tr,
} }
#endif #endif
#ifdef WIN32 #ifdef __Windows__
if (usb_set_configuration(tr->handle, 1) < 0) { if (usb_set_configuration(tr->handle, 1) < 0) {
pr_error(__FILE__": can't set configuration 1"); pr_error(__FILE__": can't set configuration 1");
usb_close(tr->handle); usb_close(tr->handle);

View File

@ -132,7 +132,7 @@ static int open_device(struct iso_transport *tr, struct usb_device *dev)
} }
#endif #endif
#ifdef WIN32 #ifdef __Windows__
if (usb_set_configuration(tr->handle, USB_CONFIG) < 0) { if (usb_set_configuration(tr->handle, USB_CONFIG) < 0) {
printc_err("olimex_iso: can't set configuration: %s\n", printc_err("olimex_iso: can't set configuration: %s\n",
usb_strerror()); usb_strerror());

View File

@ -74,7 +74,7 @@ static int open_interface(struct rf2500_transport *tr,
"detach kernel driver"); "detach kernel driver");
#endif #endif
#ifdef WIN32 #ifdef __Windows__
if (usb_set_configuration(tr->handle, 1) < 0) { if (usb_set_configuration(tr->handle, 1) < 0) {
pr_error("rf2500: can't set configuration 1"); pr_error("rf2500: can't set configuration 1");
usb_close(tr->handle); usb_close(tr->handle);

View File

@ -26,7 +26,7 @@
#include "tilib_defs.h" #include "tilib_defs.h"
#include "threads.h" #include "threads.h"
#ifdef WIN32 #if defined(__Windows__) || defined(__CYGWIN__)
static const char tilib_filename[] = "MSP430.DLL"; static const char tilib_filename[] = "MSP430.DLL";
#else #else
static const char tilib_filename[] = "libmsp430.so"; static const char tilib_filename[] = "libmsp430.so";

View File

@ -315,7 +315,7 @@ int setup_driver(struct cmdline_args *args)
return 0; return 0;
} }
#ifdef WIN32 #ifdef __Windows__
static int sockets_init(void) static int sockets_init(void)
{ {
WSADATA data; WSADATA data;

View File

@ -105,7 +105,7 @@ int cmd_help(char **arg)
vector_destroy(&v); vector_destroy(&v);
printc("Type \"help <topic>\" for more information.\n"); printc("Type \"help <topic>\" for more information.\n");
#if defined(WIN32) && !defined(USE_READLINE) #if defined(__Windows__) && !defined(USE_READLINE)
printc("Press Ctrl+Z, Enter to quit.\n"); printc("Press Ctrl+Z, Enter to quit.\n");
#else #else
printc("Press Ctrl+D to quit.\n"); printc("Press Ctrl+D to quit.\n");

View File

@ -19,7 +19,7 @@
#include "dynload.h" #include "dynload.h"
#include "util.h" #include "util.h"
#ifdef WIN32 #ifdef __Windows__
dynload_handle_t dynload_open(const char *filename) dynload_handle_t dynload_open(const char *filename)
{ {
@ -41,7 +41,7 @@ const char *dynload_error(void)
return last_error(); return last_error();
} }
#else /* WIN32 */ #else /* __Windows__ */
#include <dlfcn.h> #include <dlfcn.h>

View File

@ -21,11 +21,11 @@
/* Portable dynamic loader interface. */ /* Portable dynamic loader interface. */
#ifdef WIN32 #ifdef __Windows__
#include <windows.h> #include <windows.h>
typedef HMODULE dynload_handle_t; typedef HMODULE dynload_handle_t;
#else /* WIN32 */ #else /* __Windows__ */
typedef void *dynload_handle_t; typedef void *dynload_handle_t;
#endif #endif

View File

@ -99,7 +99,7 @@ static int write_text(struct outbuf *out, const char *buf, FILE *fout)
out->in_code = 0; out->in_code = 0;
if (*buf == 'm') if (*buf == 'm')
out->ansi_cur = out->ansi_next; out->ansi_cur = out->ansi_next;
#ifdef WIN32 #ifdef __Windows__
if (want_color && *buf == 'm') { if (want_color && *buf == 'm') {
fflush(fout); fflush(fout);
SetConsoleTextAttribute(GetStdHandle SetConsoleTextAttribute(GetStdHandle
@ -108,7 +108,7 @@ static int write_text(struct outbuf *out, const char *buf, FILE *fout)
#endif #endif
} }
#ifndef WIN32 #ifndef __Windows__
if (want_color) if (want_color)
fputc(*buf, fout); fputc(*buf, fout);
#endif #endif

View File

@ -23,11 +23,11 @@
#include "sockets.h" #include "sockets.h"
#include "util.h" #include "util.h"
#ifdef WIN32 #ifdef __Windows__
#include <windows.h> #include <windows.h>
#endif #endif
#ifdef WIN32 #ifdef __Windows__
static DWORD error_save = 0; static DWORD error_save = 0;
static void sockets_begin(SOCKET s, DWORD event) static void sockets_begin(SOCKET s, DWORD event)
@ -137,7 +137,7 @@ ssize_t sockets_recv(SOCKET s, void *buf, size_t len, int flags,
sockets_end(s); sockets_end(s);
return ret; return ret;
} }
#else /* WIN32 */ #else /* __Windows__ */
SOCKET sockets_accept(SOCKET s, struct sockaddr *addr, socklen_t *addrlen) SOCKET sockets_accept(SOCKET s, struct sockaddr *addr, socklen_t *addrlen)
{ {
return accept(s, addr, addrlen); return accept(s, addr, addrlen);

View File

@ -19,7 +19,7 @@
#ifndef SOCKETS_H_ #ifndef SOCKETS_H_
#define SOCKETS_H_ #define SOCKETS_H_
#ifdef WIN32 #ifdef __Windows__
#include <winsock2.h> #include <winsock2.h>
#include <stdio.h> #include <stdio.h>

View File

@ -29,7 +29,7 @@
#include <linux/serial.h> #include <linux/serial.h>
#endif #endif
#ifndef WIN32 #ifndef __Windows__
#ifndef B460800 #ifndef B460800
#define B460800 460800 #define B460800 460800
@ -184,7 +184,7 @@ int sport_write(sport_t s, const uint8_t *data, int len)
return write(s, data, len); return write(s, data, len);
} }
#else /* WIN32 */ #else /* __Windows__ */
sport_t sport_open(const char *device, int rate, int flags) sport_t sport_open(const char *device, int rate, int flags)
{ {

View File

@ -19,7 +19,7 @@
#ifndef SPORT_H_ #ifndef SPORT_H_
#define SPORT_H_ #define SPORT_H_
#ifndef WIN32 #ifndef __Windows__
#include <stdint.h> #include <stdint.h>
#include <termios.h> #include <termios.h>
@ -32,7 +32,7 @@ typedef int sport_t;
#define SPORT_MC_DTR TIOCM_DTR #define SPORT_MC_DTR TIOCM_DTR
#define SPORT_MC_RTS TIOCM_RTS #define SPORT_MC_RTS TIOCM_RTS
#else /* WIN32 */ #else /* __Windows__ */
#include <windows.h> #include <windows.h>

View File

@ -21,7 +21,7 @@
/* Portable thread utilities interface. */ /* Portable thread utilities interface. */
#ifdef WIN32 #ifdef __Windows__
#include <windows.h> #include <windows.h>
typedef CRITICAL_SECTION threads_lock_t; typedef CRITICAL_SECTION threads_lock_t;
@ -46,7 +46,7 @@ static inline void threads_lock_release(threads_lock_t *lock)
LeaveCriticalSection(lock); LeaveCriticalSection(lock);
} }
#else /* WIN32 */ #else /* __Windows__ */
#include <pthread.h> #include <pthread.h>

View File

@ -25,14 +25,14 @@
#include <signal.h> #include <signal.h>
#include <assert.h> #include <assert.h>
#ifdef WIN32 #ifdef __Windows__
#include <windows.h> #include <windows.h>
#endif #endif
#include "util.h" #include "util.h"
#include "output.h" #include "output.h"
#ifdef WIN32 #ifdef __Windows__
static int ctrlc_flag; static int ctrlc_flag;
static HANDLE ctrlc_event; static HANDLE ctrlc_event;
static CRITICAL_SECTION ctrlc_cs; static CRITICAL_SECTION ctrlc_cs;
@ -87,7 +87,7 @@ HANDLE ctrlc_win32_event(void)
{ {
return ctrlc_event; return ctrlc_event;
} }
#else /* WIN32 */ #else /* __Windows__ */
static volatile int ctrlc_flag; static volatile int ctrlc_flag;
static void sigint_handler(int signum) static void sigint_handler(int signum)
@ -99,7 +99,7 @@ static void sigint_handler(int signum)
void ctrlc_init(void) void ctrlc_init(void)
{ {
#if defined(__CYGWIN__) #ifdef __CYGWIN__
signal(SIGINT, sigint_handler); signal(SIGINT, sigint_handler);
#else #else
static const struct sigaction siga = { static const struct sigaction siga = {
@ -262,7 +262,7 @@ int hexval(int c)
return 0; return 0;
} }
#ifdef WIN32 #ifdef __Windows__
char *strsep(char **strp, const char *delim) char *strsep(char **strp, const char *delim)
{ {
char *start = *strp; char *start = *strp;
@ -292,7 +292,7 @@ char *strsep(char **strp, const char *delim)
} }
#endif #endif
#ifdef WIN32 #ifdef __Windows__
const char *last_error(void) const char *last_error(void)
{ {
DWORD err = GetLastError(); DWORD err = GetLastError();

View File

@ -22,7 +22,7 @@
#include <stdint.h> #include <stdint.h>
#include <ctype.h> #include <ctype.h>
#ifdef WIN32 #ifdef __Windows__
#include <windows.h> #include <windows.h>
#endif #endif
@ -60,7 +60,7 @@ static inline int ishex(int c)
int hexval(int c); int hexval(int c);
#ifdef WIN32 #ifdef __Windows__
char *strsep(char **strp, const char *delim); char *strsep(char **strp, const char *delim);
HANDLE ctrlc_win32_event(void); HANDLE ctrlc_win32_event(void);