From 59f02abd10fcd192226177d8f41194eaec7d25a5 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Sun, 28 Aug 2011 21:58:30 +0000 Subject: [PATCH] Build fixes for win32 Currently unsupported features: - fork, used by gzip decompression - rpc, used by lassen radar format --- configure.ac | 10 ++++++++++ examples/killer_sweep.c | 5 ++--- src/Makefile.am | 8 +++++++- src/dorade.c | 6 +++++- src/gzip.c | 3 +-- src/lassen.c | 6 +++++- src/rainbow.c | 2 ++ src/rapic_parse.y | 6 ------ src/rapic_routines.c | 6 +++++- src/rapic_scan.l | 1 + src/rsl.h | 2 +- src/win32compat.h | 39 +++++++++++++++++++++++++++++++++++++++ src/wsr88d.h | 2 +- 13 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 src/win32compat.h diff --git a/configure.ac b/configure.ac index 2b59634..3405552 100644 --- a/configure.ac +++ b/configure.ac @@ -59,6 +59,16 @@ if test "$YYWRAP" = ""; then LIBS="$LIBS $LEXLIB" fi +# Test for Windows vs. Unix +case "${host}" in + *mingw32*) WIN32="yes" ;; + *) WIN32="no" ;; +esac +if test "$WIN32" = yes; then + ac_default_prefix="/" +fi +AM_CONDITIONAL([WIN32], test "$WIN32" = "yes") + AC_MSG_RESULT(LIBS = $LIBS) AC_CONFIG_FILES([Makefile doc/Makefile data/Makefile examples/Makefile src/Makefile]) AC_OUTPUT diff --git a/examples/killer_sweep.c b/examples/killer_sweep.c index d70766c..4ad518b 100644 --- a/examples/killer_sweep.c +++ b/examples/killer_sweep.c @@ -6,6 +6,7 @@ #include "rsl.h" #include +#include void print_link_list(Azimuth_hash *list) { if (list == NULL) { @@ -84,9 +85,7 @@ void poke_about_sweep(Sweep *s) float random_azim(void) { - double drand; - drand = drand48()*1; - return (float)drand; + return (float)rand() / INT_MAX; } Sweep *permute_sweep(Sweep *sweep) diff --git a/src/Makefile.am b/src/Makefile.am index dbc3fd3..7bcf381 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,7 +12,7 @@ headers = africa.h dorade.h lassen.h \ $(include_HEADERS) librsl_la_LDFLAGS = -version-info 1:42 -librsl_la_CPPFLAGS = -DDATADIR="\"$(datadir)/rsl\"" +librsl_la_CPPFLAGS = -DDATADIRRSL="\"$(dots)$(datadir)/rsl\"" librsl_la_SOURCES = \ rapic_parse.y rapic_scan.l rapic_to_radar.c rapic_routines.c \ radtec.c radtec_to_radar.c \ @@ -29,6 +29,12 @@ librsl_la_SOURCES = \ radar_to_hdf_2.c hdf_to_radar.c toolkit_memory_mgt.c \ radar_to_hdf_1.c rainbow.c rainbow_to_radar.c $(headers) +if WIN32 +librsl_la_LDFLAGS += -mwindows -no-undefined +librsl_la_LIBADD = -lws2_32 +dots = .. +endif + # This should be speciifc to rapic, # but I'm not sure how to do that with autofoo AM_LFLAGS = -P rapic diff --git a/src/dorade.c b/src/dorade.c index 7cd137f..6dac831 100644 --- a/src/dorade.c +++ b/src/dorade.c @@ -23,9 +23,13 @@ #include #include -#include #include #include "dorade.h" +#ifndef WIN32 +#include +#else +#include "win32compat.h" +#endif int dorade_verbose = 0; diff --git a/src/gzip.c b/src/gzip.c index b2c7637..9c2ef31 100644 --- a/src/gzip.c +++ b/src/gzip.c @@ -26,9 +26,8 @@ #include #define _USE_BSD #include -#include -#include #include +#include "win32compat.h" /* Prototype definitions within this file. */ int no_command (char *cmd); diff --git a/src/lassen.c b/src/lassen.c index dc8cd16..b850b5d 100644 --- a/src/lassen.c +++ b/src/lassen.c @@ -39,9 +39,13 @@ #include #include #include +#include "lassen.h" +#ifndef WIN32 #include #include -#include "lassen.h" +#else +#include "win32compat.h" +#endif /* xdr_destroy is broken on HPUX, SGI, and SUN; Linux, the only working one? */ /* This broken behavior could be from old xdr versions, too. */ diff --git a/src/rainbow.c b/src/rainbow.c index 7d5862c..72892f5 100644 --- a/src/rainbow.c +++ b/src/rainbow.c @@ -27,6 +27,8 @@ #include "rsl.h" #include "rainbow.h" +#include "win32compat.h" + static int get_param_int(char *buf) { /* Returns an integer parameter from a header line. */ diff --git a/src/rapic_parse.y b/src/rapic_parse.y index b104757..eede522 100644 --- a/src/rapic_parse.y +++ b/src/rapic_parse.y @@ -616,9 +616,3 @@ int rapicerror(char *s) fprintf(stderr, ">\n"); return 1; } - -int rapicwrap(char *s) -{ - yywrap(s); - return 1; -} diff --git a/src/rapic_routines.c b/src/rapic_routines.c index 2ae3faf..ff92f09 100644 --- a/src/rapic_routines.c +++ b/src/rapic_routines.c @@ -1,8 +1,12 @@ #include #include "rapic_routines.h" #include - +#ifndef WIN32 #include +#else +#include "win32compat.h" +#endif + void rapic_decode(unsigned char *inbuf, int inbytes, unsigned char *outbuf, int *outbytes, float *azim, float *elev, int *delta_time) { diff --git a/src/rapic_scan.l b/src/rapic_scan.l index 002aacd..6291c63 100644 --- a/src/rapic_scan.l +++ b/src/rapic_scan.l @@ -44,6 +44,7 @@ %option nounput %option noinput +%option noyywrap %x ATMODE %% diff --git a/src/rsl.h b/src/rsl.h index 597069c..b3ea1f4 100644 --- a/src/rsl.h +++ b/src/rsl.h @@ -44,7 +44,7 @@ /* so you shouldn't have to modify anything here. */ /**********************************************************************/ #ifndef COLORDIR -#define COLORDIR DATADIR "/colors" +#define COLORDIR DATADIRRSL "/colors" #endif /* These are the color table indexes. See RSL_set/get_color_table. */ diff --git a/src/win32compat.h b/src/win32compat.h new file mode 100644 index 0000000..897d8a1 --- /dev/null +++ b/src/win32compat.h @@ -0,0 +1,39 @@ +#ifdef WIN32 +#include +#include + +typedef int bool_t; +typedef unsigned char uchar_t; +typedef unsigned short ushort_t; +typedef unsigned int uint_t; + +typedef struct {} XDR; + +enum xdr_op { XDR_ENCODE = 0, XDR_DECODE = 1, XDR_FREE = 2 }; + +static inline bool_t unimp(char *what) +{ + printf("%s not supported in win32\n", what); + exit(-1); + return FALSE; +} + +static inline void xdrstdio_create(XDR *xdrs, FILE *file, enum xdr_op op) { unimp("xdr"); } +static inline void xdr_destroy(XDR *xdrs) { unimp("xdr"); } +static inline bool_t xdr_u_char (XDR *xdrs, uchar_t *ucp) { return unimp("xdr"); } +static inline bool_t xdr_bytes (XDR *xdrs, char **sp, uint_t *s, uint_t m) { return unimp("xdr"); } +static inline bool_t xdr_int (XDR *xdrs, int *ip) { return unimp("xdr"); } +static inline bool_t xdr_string (XDR *xdrs, char **sp, uint_t maxsize) { return unimp("xdr"); } +static inline bool_t xdr_u_short(XDR *xdrs, ushort_t *usp) { return unimp("xdr"); } +static inline bool_t xdr_short (XDR *xdrs, short *sp) { return unimp("xdr"); } +static inline bool_t xdr_u_int (XDR *xdrs, uint_t *up) { return unimp("xdr"); } + +static inline pid_t fork(void) { return unimp("fork"); } + +static inline char *index(const char *s, int c) +{ + while (*s != c && *s != '\0') + s++; + return *s == '\0' ? NULL : (char*)s; +} +#endif diff --git a/src/wsr88d.h b/src/wsr88d.h index 7d22427..ba56391 100644 --- a/src/wsr88d.h +++ b/src/wsr88d.h @@ -7,7 +7,7 @@ * The directory should be the same as the LIBDIR in the makefile. */ #ifndef WSR88D_SITE_INFO_FILE -#define WSR88D_SITE_INFO_FILE DATADIR "/wsr88d_locations.dat" +#define WSR88D_SITE_INFO_FILE DATADIRRSL "/wsr88d_locations.dat" #endif /*===============================================================*/ typedef struct { -- 2.43.2