Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Windows support #146

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*.o
dump1090
testfiles/*.bin
misc
frames.js
Expand All @@ -8,8 +7,10 @@ frames.js
*.rej
*.orig
untrackedDeveloperSettings.js
dump1090
view1090
faup1090
*.exe
package-wheezy
oneoff/convert_benchmark
oneoff/uc8_capture_stats
Expand Down
22 changes: 20 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ else
SOAPYSDR ?= no
endif


BUILD_UNAME := $(shell uname)
BUILD_ARCH := $(shell uname -m)

# There is no standard for the uname's output on a Windows environment
ifeq ($(OS), Windows_NT)
BUILD_UNAME := Windows
endif

UNAME ?= $(BUILD_UNAME)
ARCH ?= $(BUILD_ARCH)

Expand Down Expand Up @@ -81,6 +87,7 @@ ifeq ($(UNAME), OpenBSD)
COMPAT += compat/clock_nanosleep/clock_nanosleep.o
LIBS_USB += -lusb-1.0
LIBS_CURSES := -lncurses
CPUFEATURES ?= yes
endif

ifeq ($(UNAME), FreeBSD)
Expand All @@ -97,8 +104,17 @@ ifeq ($(UNAME), NetBSD)
LIBS_CURSES := -lcurses
endif

CPUFEATURES ?= no
ifeq ($(UNAME), Windows)
# TODO: Perhaps copy the DLL files to the output folder?
CPPFLAGS += -DMISSING_TIME_R_FUNCS -DMISSING_CURSES_H_NCURSES -D_USE_MATH_DEFINES -DNCURSES_STATIC
LIBS += -lws2_32 -lsystre
LIBS_USB += -lusb-1.0
LIBS_CURSES := -lncurses
CPUFEATURES ?= yes
endif


CPUFEATURES ?= no
ifeq ($(CPUFEATURES),yes)
include Makefile.cpufeatures
DUMP1090_CPPFLAGS += -DENABLE_CPUFEATURES -Icpu_features/include
Expand Down Expand Up @@ -235,7 +251,9 @@ starch-benchmark: cpu.o dsp/helpers/tables.o $(CPUFEATURES_OBJS) $(STARCH_OBJS)
$(CC) -g -o $@ $^ $(LDFLAGS) $(LIBS)

clean:
rm -f *.o oneoff/*.o compat/clock_gettime/*.o compat/clock_nanosleep/*.o cpu_features/src/*.o dsp/generated/*.o dsp/helpers/*.o $(CPUFEATURES_OBJS) dump1090 view1090 faup1090 cprtests crctests oneoff/convert_benchmark oneoff/decode_comm_b oneoff/dsp_error_measurement oneoff/uc8_capture_stats starch-benchmark
rm -f dump1090 view1090 faup1090 cprtests crctests oneoff/convert_benchmark oneoff/decode_comm_b oneoff/dsp_error_measurement oneoff/uc8_capture_stats starch-benchmark
find . -type f -name '*.o' -exec rm {} +
find . -type f -name '*.exe' -exec rm {} +

test: cprtests
./cprtests
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ Minimal testing on 12.1-RELEASE, YMMV.
$ gmake
```

## Building on MSYS2

1. Install PothosSDR to `C:\PothosSDR\` and install MSYS2.
> The PothosSDR path can't have spaces in it because the MinGW gcc
doesn't recognize Windows style paths with escaped spaces in them
which is what the pkg-config returns.
2. Remove the following headers `pthread.h, semaphore.h, sched.h` from `<PothosSDR root>/include`.
> MSYS2 already has these POSIX headers and we need the compiler to use the default headers.

#### Building with MinGW-w64
```
$ pacman -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-ncurses mingw-w64-x86_64-libsystre mingw-w64-x86_64-libusb
$ alias make=mingw32-make
$ PKG_CONFIG_PATH="/c/PothosSDR/lib/pkgconfig:$PKG_CONFIG_PATH" make -j$(nproc)
```
#### Building with Clang
```
$ pacman -S mingw-w64-clang-x86_64-toolchain mingw-w64-clang-x86_64-ncurses mingw-w64-clang-x86_64-libsystre mingw-w64-clang-x86_64-libusb
$ alias make=mingw32-make
$ PKG_CONFIG_PATH="/c/PothosSDR/lib/pkgconfig:$PKG_CONFIG_PATH" make -j$(nproc)
```

## Generating wisdom files

dump1090-fa uses [starch](https://github.com/flightaware/starch) to build
Expand Down
46 changes: 33 additions & 13 deletions anet.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,29 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifdef _WIN32
# include <winsock2.h>
# include <ws2def.h>
# include <ws2tcpip.h>
# include <Windows.h>
# define socklen_t int
# define sockaddr_storage sockaddr
# define p_setsockopt_optval_t const char*
#else
# include <sys/socket.h>
# include <sys/un.h>
# include <netinet/in.h>
# include <netinet/tcp.h>
# include <arpa/inet.h>
# include <unistd.h>
# include <netdb.h>
# define p_setsockopt_optval_t void*
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <netdb.h>

#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
Expand All @@ -80,6 +92,7 @@ static void anetSetError(char *err, const char *fmt, ...)

int anetNonBlock(char *err, int fd)
{
#if !defined(_WIN32)
int flags;

/* Set the socket nonblocking.
Expand All @@ -93,14 +106,21 @@ int anetNonBlock(char *err, int fd)
anetSetError(err, "fcntl(F_SETFL,O_NONBLOCK): %s", strerror(errno));
return ANET_ERR;
}

#else
u_long mode = 1; // 1 to enable non-blocking socket
int errorCode = ioctlsocket(fd, FIONBIO, &mode);
if (errorCode != 0) {
anetSetError(err, "ioctlsocket(FIONBIO): %d", errorCode);
return ANET_ERR;
}
#endif
return ANET_OK;
}

int anetTcpNoDelay(char *err, int fd)
{
int yes = 1;
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void*)&yes, sizeof(yes)) == -1)
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (p_setsockopt_optval_t)&yes, sizeof(yes)) == -1)
{
anetSetError(err, "setsockopt TCP_NODELAY: %s", strerror(errno));
return ANET_ERR;
Expand All @@ -110,7 +130,7 @@ int anetTcpNoDelay(char *err, int fd)

int anetSetSendBuffer(char *err, int fd, int buffsize)
{
if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void*)&buffsize, sizeof(buffsize)) == -1)
if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (p_setsockopt_optval_t)&buffsize, sizeof(buffsize)) == -1)
{
anetSetError(err, "setsockopt SO_SNDBUF: %s", strerror(errno));
return ANET_ERR;
Expand All @@ -121,7 +141,7 @@ int anetSetSendBuffer(char *err, int fd, int buffsize)
int anetTcpKeepAlive(char *err, int fd)
{
int yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&yes, sizeof(yes)) == -1) {
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (p_setsockopt_optval_t)&yes, sizeof(yes)) == -1) {
anetSetError(err, "setsockopt SO_KEEPALIVE: %s", strerror(errno));
return ANET_ERR;
}
Expand All @@ -138,7 +158,7 @@ static int anetCreateSocket(char *err, int domain)

/* Make sure connection-intensive things like the redis benckmark
* will be able to close/open sockets a zillion of times */
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*)&on, sizeof(on)) == -1) {
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (p_setsockopt_optval_t)&on, sizeof(on)) == -1) {
anetSetError(err, "setsockopt SO_REUSEADDR: %s", strerror(errno));
return ANET_ERR;
}
Expand Down Expand Up @@ -239,7 +259,7 @@ int anetWrite(int fd, char *buf, int count)
static int anetListen(char *err, int s, struct sockaddr *sa, socklen_t len) {
if (sa->sa_family == AF_INET6) {
int on = 1;
setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on));
setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (p_setsockopt_optval_t)&on, sizeof(on));
}

if (bind(s,sa,len) == -1) {
Expand Down
29 changes: 7 additions & 22 deletions compat/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,18 @@
* Platform-specific bits
*/

#if defined(__APPLE__)

/*
* Mach endian conversion
*/
# include <libkern/OSByteOrder.h>
# define bswap_16 OSSwapInt16
# define bswap_32 OSSwapInt32
# define bswap_64 OSSwapInt64
# include <machine/endian.h>
# define le16toh(x) OSSwapLittleToHostInt16(x)
# define le32toh(x) OSSwapLittleToHostInt32(x)
# define le64toh(x) OSSwapLittleToHostInt64(x)

#elif defined(__FreeBSD__)
#include <sys/endian.h>

#else // other platforms

# include <endian.h>

#endif
#include "endian.h"

/* clock_* and time-related types */

#include <time.h>

//MSVC/MinGW has no _r time functions
#ifdef MISSING_TIME_R_FUNCS
# define localtime_r(T,Tm) (localtime_s(Tm,T) ? NULL : Tm)
# define gmtime_r(T,Tm) (gmtime_s(Tm,T) ? NULL : Tm)
#endif

#if defined(CLOCK_REALTIME)
# define HAVE_CLOCKID_T
#endif
Expand Down
115 changes: 115 additions & 0 deletions compat/endian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// "License": Public Domain
// I, Mathias Panzenböck, place this file hereby into the public domain. Use it at your own risk for whatever you like.
// In case there are jurisdictions that don't support putting things in the public domain you can also consider it to
// be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it
// an example on how to get the endian conversion functions on different platforms.

#ifndef PORTABLE_ENDIAN_H__
#define PORTABLE_ENDIAN_H__

#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)

# define __WINDOWS__

#endif

#if defined(__linux__) || defined(__CYGWIN__)

# include <endian.h>

#elif defined(__APPLE__)

# include <libkern/OSByteOrder.h>

# define htobe16(x) OSSwapHostToBigInt16(x)
# define htole16(x) OSSwapHostToLittleInt16(x)
# define be16toh(x) OSSwapBigToHostInt16(x)
# define le16toh(x) OSSwapLittleToHostInt16(x)

# define htobe32(x) OSSwapHostToBigInt32(x)
# define htole32(x) OSSwapHostToLittleInt32(x)
# define be32toh(x) OSSwapBigToHostInt32(x)
# define le32toh(x) OSSwapLittleToHostInt32(x)

# define htobe64(x) OSSwapHostToBigInt64(x)
# define htole64(x) OSSwapHostToLittleInt64(x)
# define be64toh(x) OSSwapBigToHostInt64(x)
# define le64toh(x) OSSwapLittleToHostInt64(x)

# define __BYTE_ORDER BYTE_ORDER
# define __BIG_ENDIAN BIG_ENDIAN
# define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __PDP_ENDIAN PDP_ENDIAN

#elif defined(__OpenBSD__)

# include <sys/endian.h>

#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)

# include <sys/endian.h>

# define be16toh(x) betoh16(x)
# define le16toh(x) letoh16(x)

# define be32toh(x) betoh32(x)
# define le32toh(x) letoh32(x)

# define be64toh(x) betoh64(x)
# define le64toh(x) letoh64(x)

#elif defined(__WINDOWS__)

# if BYTE_ORDER == LITTLE_ENDIAN

# define htobe16(x) __builtin_bswap16(x)
# define htole16(x) (x)
# define be16toh(x) __builtin_bswap16(x)
# define le16toh(x) (x)

# define htobe32(x) __builtin_bswap32(x)
# define htole32(x) (x)
# define be32toh(x) __builtin_bswap32(x)
# define le32toh(x) (x)

# define htobe64(x) __builtin_bswap64(x)
# define htole64(x) (x)
# define be64toh(x) __builtin_bswap64(x)
# define le64toh(x) (x)

# elif BYTE_ORDER == BIG_ENDIAN

/* that would be xbox 360 */
# define htobe16(x) (x)
# define htole16(x) __builtin_bswap16(x)
# define be16toh(x) (x)
# define le16toh(x) __builtin_bswap16(x)

# define htobe32(x) (x)
# define htole32(x) __builtin_bswap32(x)
# define be32toh(x) (x)
# define le32toh(x) __builtin_bswap32(x)

# define htobe64(x) (x)
# define htole64(x) __builtin_bswap64(x)
# define be64toh(x) (x)
# define le64toh(x) __builtin_bswap64(x)

# else

# error byte order not supported

# endif

# define __BYTE_ORDER BYTE_ORDER
# define __BIG_ENDIAN BIG_ENDIAN
# define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __PDP_ENDIAN PDP_ENDIAN

#else

# error platform not supported

#endif

#endif
1 change: 1 addition & 0 deletions dump1090.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ int main(int argc, char **argv) {
}
}

modesDeInitNet();
interactiveCleanup();

// Write final stats
Expand Down
9 changes: 8 additions & 1 deletion dump1090.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@

// ============================= Include files ==========================

#ifdef _WIN32
//WinSocks2 must be included before Windows.h
# include <winsock2.h>
#else
# include <sys/ioctl.h>
#endif

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
Expand All @@ -76,7 +83,7 @@
#include <fcntl.h>
#include <ctype.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <strings.h>
Expand Down