diff --git a/Makefile b/Makefile index c13621b..d6e8721 100644 --- a/Makefile +++ b/Makefile @@ -34,12 +34,14 @@ else READLINE_LIBS = -lreadline endif -UNAME := $(shell sh -c 'uname -s') -ifeq ($(UNAME),Darwin) # Mac OS X/MacPorts stuff +UNAME_S := $(shell sh -c 'uname -s') +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_LDFLAGS = -L/opt/local/lib else - ifeq ($(UNAME),OpenBSD) # OpenBSD Ports stuff + ifeq ($(UNAME_S),OpenBSD) # OpenBSD Ports stuff PORTS_CFLAGS = `pkg-config --cflags libusb` PORTS_LDFLAGS = `pkg-config --libs libusb` -ltermcap -pthread else @@ -52,12 +54,15 @@ ifeq ($(OS),Windows_NT) MSPDEBUG_CC = gcc BINARY = mspdebug.exe - OS_LIBS = -lws2_32 -lregex + ifneq ($(UNAME_O),Cygwin) + OS_LIBS = -lws2_32 -lregex + OS_CFLAGS = -D__Windows__ + endif else MSPDEBUG_CC = $(CC) BINARY = mspdebug - ifneq ($(filter $(UNAME),FreeBSD OpenBSD),) + ifneq ($(filter $(UNAME_S),FreeBSD OpenBSD),) OS_LIBS = else OS_LIBS = -ldl @@ -72,7 +77,7 @@ CONFIG_CFLAGS = -DLIB_DIR=\"$(LIBDIR)\" MSPDEBUG_LDFLAGS = $(LDFLAGS) $(PORTS_LDFLAGS) MSPDEBUG_LIBS = -lusb $(READLINE_LIBS) $(OS_LIBS) MSPDEBUG_CFLAGS = $(CFLAGS) $(READLINE_CFLAGS) $(PORTS_CFLAGS)\ - $(GCC_CFLAGS) $(INCLUDES) $(CONFIG_CFLAGS) + $(GCC_CFLAGS) $(INCLUDES) $(CONFIG_CFLAGS) $(OS_CFLAGS) all: $(BINARY) diff --git a/drivers/gdbc.c b/drivers/gdbc.c index c7788b0..efc9f57 100644 --- a/drivers/gdbc.c +++ b/drivers/gdbc.c @@ -381,7 +381,7 @@ static int connect_to(const char *spec) printc_dbg("Looking up %s...\n", hostname); ent = gethostbyname(hostname); if (!ent) { -#ifdef WIN32 +#ifdef __Windows__ printc_err("No such host: %s: %s\n", hostname, last_error()); #else diff --git a/drivers/olimex.c b/drivers/olimex.c index 2c0c6a6..aade6c8 100644 --- a/drivers/olimex.c +++ b/drivers/olimex.c @@ -150,7 +150,7 @@ static int open_interface(struct olimex_transport *tr, } #endif -#ifdef WIN32 +#ifdef __Windows__ if (usb_set_configuration(tr->handle, 1) < 0) { pr_error(__FILE__": can't set configuration 1"); usb_close(tr->handle); diff --git a/drivers/olimex_iso.c b/drivers/olimex_iso.c index bcbb92c..566ea63 100644 --- a/drivers/olimex_iso.c +++ b/drivers/olimex_iso.c @@ -132,7 +132,7 @@ static int open_device(struct iso_transport *tr, struct usb_device *dev) } #endif -#ifdef WIN32 +#ifdef __Windows__ if (usb_set_configuration(tr->handle, USB_CONFIG) < 0) { printc_err("olimex_iso: can't set configuration: %s\n", usb_strerror()); diff --git a/drivers/rf2500.c b/drivers/rf2500.c index 05007e4..c96a6c6 100644 --- a/drivers/rf2500.c +++ b/drivers/rf2500.c @@ -32,7 +32,7 @@ struct rf2500_transport { int int_number; struct usb_dev_handle *handle; - uint8_t buf[64]; + uint8_t buf[64]; int len; int offset; }; @@ -74,7 +74,7 @@ static int open_interface(struct rf2500_transport *tr, "detach kernel driver"); #endif -#ifdef WIN32 +#ifdef __Windows__ if (usb_set_configuration(tr->handle, 1) < 0) { pr_error("rf2500: can't set configuration 1"); usb_close(tr->handle); diff --git a/drivers/tilib.c b/drivers/tilib.c index 1607cd9..ff57e5d 100644 --- a/drivers/tilib.c +++ b/drivers/tilib.c @@ -26,7 +26,7 @@ #include "tilib_defs.h" #include "threads.h" -#ifdef WIN32 +#if defined(__Windows__) || defined(__CYGWIN__) static const char tilib_filename[] = "MSP430.DLL"; #else static const char tilib_filename[] = "libmsp430.so"; diff --git a/ui/main.c b/ui/main.c index 26cc96b..b0f7c28 100644 --- a/ui/main.c +++ b/ui/main.c @@ -315,7 +315,7 @@ int setup_driver(struct cmdline_args *args) return 0; } -#ifdef WIN32 +#ifdef __Windows__ static int sockets_init(void) { WSADATA data; diff --git a/ui/stdcmd.c b/ui/stdcmd.c index ea5f4cf..50cea1e 100644 --- a/ui/stdcmd.c +++ b/ui/stdcmd.c @@ -105,7 +105,7 @@ int cmd_help(char **arg) vector_destroy(&v); printc("Type \"help \" for more information.\n"); -#if defined(WIN32) && !defined(USE_READLINE) +#if defined(__Windows__) && !defined(USE_READLINE) printc("Press Ctrl+Z, Enter to quit.\n"); #else printc("Press Ctrl+D to quit.\n"); diff --git a/util/dynload.c b/util/dynload.c index a830c4b..d64ec26 100644 --- a/util/dynload.c +++ b/util/dynload.c @@ -19,7 +19,7 @@ #include "dynload.h" #include "util.h" -#ifdef WIN32 +#ifdef __Windows__ dynload_handle_t dynload_open(const char *filename) { @@ -41,7 +41,7 @@ const char *dynload_error(void) return last_error(); } -#else /* WIN32 */ +#else /* __Windows__ */ #include diff --git a/util/dynload.h b/util/dynload.h index c358f57..fb9e14e 100644 --- a/util/dynload.h +++ b/util/dynload.h @@ -21,11 +21,11 @@ /* Portable dynamic loader interface. */ -#ifdef WIN32 +#ifdef __Windows__ #include typedef HMODULE dynload_handle_t; -#else /* WIN32 */ +#else /* __Windows__ */ typedef void *dynload_handle_t; #endif diff --git a/util/output.c b/util/output.c index c8a746f..d11d7b5 100644 --- a/util/output.c +++ b/util/output.c @@ -99,7 +99,7 @@ static int write_text(struct outbuf *out, const char *buf, FILE *fout) out->in_code = 0; if (*buf == 'm') out->ansi_cur = out->ansi_next; -#ifdef WIN32 +#ifdef __Windows__ if (want_color && *buf == 'm') { fflush(fout); SetConsoleTextAttribute(GetStdHandle @@ -108,7 +108,7 @@ static int write_text(struct outbuf *out, const char *buf, FILE *fout) #endif } -#ifndef WIN32 +#ifndef __Windows__ if (want_color) fputc(*buf, fout); #endif diff --git a/util/sockets.c b/util/sockets.c index 1fbffc8..560829e 100644 --- a/util/sockets.c +++ b/util/sockets.c @@ -23,11 +23,11 @@ #include "sockets.h" #include "util.h" -#ifdef WIN32 +#ifdef __Windows__ #include #endif -#ifdef WIN32 +#ifdef __Windows__ static DWORD error_save = 0; 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); return ret; } -#else /* WIN32 */ +#else /* __Windows__ */ SOCKET sockets_accept(SOCKET s, struct sockaddr *addr, socklen_t *addrlen) { return accept(s, addr, addrlen); diff --git a/util/sockets.h b/util/sockets.h index 208ec23..550290c 100644 --- a/util/sockets.h +++ b/util/sockets.h @@ -19,7 +19,7 @@ #ifndef SOCKETS_H_ #define SOCKETS_H_ -#ifdef WIN32 +#ifdef __Windows__ #include #include diff --git a/util/sport.c b/util/sport.c index c5f2518..9977c22 100644 --- a/util/sport.c +++ b/util/sport.c @@ -29,7 +29,7 @@ #include #endif -#ifndef WIN32 +#ifndef __Windows__ #ifndef B460800 #define B460800 460800 @@ -184,7 +184,7 @@ int sport_write(sport_t s, const uint8_t *data, int len) return write(s, data, len); } -#else /* WIN32 */ +#else /* __Windows__ */ sport_t sport_open(const char *device, int rate, int flags) { diff --git a/util/sport.h b/util/sport.h index 31edf5b..5ee050c 100644 --- a/util/sport.h +++ b/util/sport.h @@ -19,7 +19,7 @@ #ifndef SPORT_H_ #define SPORT_H_ -#ifndef WIN32 +#ifndef __Windows__ #include #include @@ -32,7 +32,7 @@ typedef int sport_t; #define SPORT_MC_DTR TIOCM_DTR #define SPORT_MC_RTS TIOCM_RTS -#else /* WIN32 */ +#else /* __Windows__ */ #include diff --git a/util/threads.h b/util/threads.h index 0e9af40..e9dbfc4 100644 --- a/util/threads.h +++ b/util/threads.h @@ -21,7 +21,7 @@ /* Portable thread utilities interface. */ -#ifdef WIN32 +#ifdef __Windows__ #include typedef CRITICAL_SECTION threads_lock_t; @@ -46,7 +46,7 @@ static inline void threads_lock_release(threads_lock_t *lock) LeaveCriticalSection(lock); } -#else /* WIN32 */ +#else /* __Windows__ */ #include diff --git a/util/util.c b/util/util.c index 24a6916..a30f644 100644 --- a/util/util.c +++ b/util/util.c @@ -25,14 +25,14 @@ #include #include -#ifdef WIN32 +#ifdef __Windows__ #include #endif #include "util.h" #include "output.h" -#ifdef WIN32 +#ifdef __Windows__ static int ctrlc_flag; static HANDLE ctrlc_event; static CRITICAL_SECTION ctrlc_cs; @@ -87,7 +87,7 @@ HANDLE ctrlc_win32_event(void) { return ctrlc_event; } -#else /* WIN32 */ +#else /* __Windows__ */ static volatile int ctrlc_flag; static void sigint_handler(int signum) @@ -99,7 +99,7 @@ static void sigint_handler(int signum) void ctrlc_init(void) { -#if defined(__CYGWIN__) +#ifdef __CYGWIN__ signal(SIGINT, sigint_handler); #else static const struct sigaction siga = { @@ -262,7 +262,7 @@ int hexval(int c) return 0; } -#ifdef WIN32 +#ifdef __Windows__ char *strsep(char **strp, const char *delim) { char *start = *strp; @@ -292,7 +292,7 @@ char *strsep(char **strp, const char *delim) } #endif -#ifdef WIN32 +#ifdef __Windows__ const char *last_error(void) { DWORD err = GetLastError(); diff --git a/util/util.h b/util/util.h index ef3066c..c0fde8a 100644 --- a/util/util.h +++ b/util/util.h @@ -22,7 +22,7 @@ #include #include -#ifdef WIN32 +#ifdef __Windows__ #include #endif @@ -60,7 +60,7 @@ static inline int ishex(int c) int hexval(int c); -#ifdef WIN32 +#ifdef __Windows__ char *strsep(char **strp, const char *delim); HANDLE ctrlc_win32_event(void);