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
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)

View File

@ -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

View File

@ -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);

View File

@ -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());

View File

@ -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);

View File

@ -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";

View File

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

View File

@ -105,7 +105,7 @@ int cmd_help(char **arg)
vector_destroy(&v);
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");
#else
printc("Press Ctrl+D to quit.\n");

View File

@ -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 <dlfcn.h>

View File

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

View File

@ -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

View File

@ -23,11 +23,11 @@
#include "sockets.h"
#include "util.h"
#ifdef WIN32
#ifdef __Windows__
#include <windows.h>
#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);

View File

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

View File

@ -29,7 +29,7 @@
#include <linux/serial.h>
#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)
{

View File

@ -19,7 +19,7 @@
#ifndef SPORT_H_
#define SPORT_H_
#ifndef WIN32
#ifndef __Windows__
#include <stdint.h>
#include <termios.h>
@ -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 <windows.h>

View File

@ -21,7 +21,7 @@
/* Portable thread utilities interface. */
#ifdef WIN32
#ifdef __Windows__
#include <windows.h>
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 <pthread.h>

View File

@ -25,14 +25,14 @@
#include <signal.h>
#include <assert.h>
#ifdef WIN32
#ifdef __Windows__
#include <windows.h>
#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();

View File

@ -22,7 +22,7 @@
#include <stdint.h>
#include <ctype.h>
#ifdef WIN32
#ifdef __Windows__
#include <windows.h>
#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);