From 13069158791228a15fca2a5cc648a4e775523e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Tue, 22 Oct 2013 23:35:05 +0200 Subject: [PATCH] libports: add SDL_net Fixes #936. --- libports/lib/mk/sdl_net.mk | 12 ++++++ libports/ports/sdl_net.inc | 2 + libports/ports/sdl_net.mk | 42 ++++++++++++++++++++ libports/src/lib/sdl_net/SDL_net.h.patch | 16 ++++++++ libports/src/lib/sdl_net/SDLnet.patch | 38 ++++++++++++++++++ libports/src/test/libports/sdl_net/target.mk | 5 +++ 6 files changed, 115 insertions(+) create mode 100644 libports/lib/mk/sdl_net.mk create mode 100644 libports/ports/sdl_net.inc create mode 100644 libports/ports/sdl_net.mk create mode 100644 libports/src/lib/sdl_net/SDL_net.h.patch create mode 100644 libports/src/lib/sdl_net/SDLnet.patch create mode 100644 libports/src/test/libports/sdl_net/target.mk diff --git a/libports/lib/mk/sdl_net.mk b/libports/lib/mk/sdl_net.mk new file mode 100644 index 0000000000..35bc60f8d1 --- /dev/null +++ b/libports/lib/mk/sdl_net.mk @@ -0,0 +1,12 @@ +include $(REP_DIR)/ports/sdl_net.inc +SDL_NET_DIR = $(REP_DIR)/contrib/$(SDL_NET) + +SRC_C = $(notdir $(wildcard $(SDL_NET_DIR)/SDLnet*.c)) + +vpath %.c $(SDL_NET_DIR) + +INC_DIR += $(SDL_NET_DIR) + +LIBS += libc sdl + +SHARED_LIB = yes diff --git a/libports/ports/sdl_net.inc b/libports/ports/sdl_net.inc new file mode 100644 index 0000000000..cdc7c58dd1 --- /dev/null +++ b/libports/ports/sdl_net.inc @@ -0,0 +1,2 @@ +SDL_NET_VERSION = 1.2.8 +SDL_NET = SDL_net-$(SDL_NET_VERSION) diff --git a/libports/ports/sdl_net.mk b/libports/ports/sdl_net.mk new file mode 100644 index 0000000000..86eb5fbc3c --- /dev/null +++ b/libports/ports/sdl_net.mk @@ -0,0 +1,42 @@ +include ports/sdl_net.inc + +SDL_NET_TGZ = $(SDL_NET).tar.gz +SDL_NET_URL = http://www.libsdl.org/projects/SDL_net/release/$(SDL_NET_TGZ) + +# +# Interface to top-level prepare Makefile +# +# Register SDL_net port as lower case to be consistent with the +# other libraries. +# +PORTS += sdl_net-$(SDL_NET_VERSION) + +prepare-sdl_net: $(CONTRIB_DIR)/$(SDL_NET) include/SDL/SDL_net.h + +$(CONTRIB_DIR)/$(SDL_NET): clean-sdl_net + +# +# Port-specific local rules +# +$(DOWNLOAD_DIR)/$(SDL_NET_TGZ): + $(VERBOSE)wget -c -P $(DOWNLOAD_DIR) $(SDL_NET_URL) && touch $@ + +$(CONTRIB_DIR)/$(SDL_NET): $(DOWNLOAD_DIR)/$(SDL_NET_TGZ) + $(VERBOSE)tar xfz $< \ + --exclude Xcode --exclude VisualC --exclude Xcode-iOS \ + --exclude VisualCE --exclude Watcom-OS2.zip --exclude debian \ + -C $(CONTRIB_DIR) && touch $@ + $(VERBOSE)patch -N -p0 < src/lib/sdl_net/SDLnet.patch + $(VERBOSE)patch -N -p0 < src/lib/sdl_net/SDL_net.h.patch + +# +# Install SDL_net headers +# +include/SDL/SDL_net.h: + $(VERBOSE)mkdir -p $(dir $@) + $(VERBOSE)ln -fs ../../$(CONTRIB_DIR)/$(SDL_NET)/SDL_net.h include/SDL/ + +clean-sdl_net: + $(VERBOSE)rm -rf include/SDL/SDL_net.h + $(VERBOSE)rmdir include/SDL 2>/dev/null || true + $(VERBOSE)rm -rf $(CONTRIB_DIR)/$(SDL_NET) diff --git a/libports/src/lib/sdl_net/SDL_net.h.patch b/libports/src/lib/sdl_net/SDL_net.h.patch new file mode 100644 index 0000000000..14d605497a --- /dev/null +++ b/libports/src/lib/sdl_net/SDL_net.h.patch @@ -0,0 +1,16 @@ +--- contrib/SDL_net-1.2.8/SDL_net.h.orig 2013-10-30 15:17:11.391825241 +0100 ++++ contrib/SDL_net-1.2.8/SDL_net.h 2013-10-30 15:17:55.108447538 +0100 +@@ -350,6 +350,13 @@ + extern no_parse_DECLSPEC char * SDLCALL SDLNet_GetError(void); + */ + ++#ifdef __cplusplus ++#define SDL_reinterpret_cast(type, expression) reinterpret_cast(expression) ++#define SDL_static_cast(type, expression) static_cast(expression) ++#else ++#define SDL_reinterpret_cast(type, expression) ((type)(expression)) ++#define SDL_static_cast(type, expression) ((type)(expression)) ++#endif + + /* Inline macro functions to read/write network data */ + diff --git a/libports/src/lib/sdl_net/SDLnet.patch b/libports/src/lib/sdl_net/SDLnet.patch new file mode 100644 index 0000000000..ec1efbe143 --- /dev/null +++ b/libports/src/lib/sdl_net/SDLnet.patch @@ -0,0 +1,38 @@ +--- contrib/SDL_net-1.2.8/SDLnet.c.orig 2013-10-22 23:17:40.135873087 +0200 ++++ contrib/SDL_net-1.2.8/SDLnet.c 2013-10-22 23:28:28.845485683 +0200 +@@ -122,11 +122,11 @@ + } else { + address->host = inet_addr(host); + if ( address->host == INADDR_NONE ) { +- struct hostent *hp; ++ struct addrinfo *ai; + +- hp = gethostbyname(host); +- if ( hp ) { +- memcpy(&address->host,hp->h_addr,hp->h_length); ++ retval = getaddrinfo(host, NULL, NULL, &ai); ++ if ( retval == 0 ) { ++ memcpy(&address->host,ai->ai_addr,ai->ai_addrlen); + } else { + retval = -1; + } +@@ -149,12 +149,15 @@ + */ + const char *SDLNet_ResolveIP(const IPaddress *ip) + { +- struct hostent *hp; ++ static char host[256]; + struct in_addr in; ++ int err; + +- hp = gethostbyaddr((const char *)&ip->host, sizeof(ip->host), AF_INET); +- if ( hp != NULL ) { +- return hp->h_name; ++ err = getnameinfo((const struct sockaddr*) &ip->host, ++ sizeof (struct sockaddr), host, sizeof (host), ++ NULL, 0, 0); ++ if ( err == 0 ) { ++ return host; + } + + in.s_addr = ip->host; diff --git a/libports/src/test/libports/sdl_net/target.mk b/libports/src/test/libports/sdl_net/target.mk new file mode 100644 index 0000000000..886bb02109 --- /dev/null +++ b/libports/src/test/libports/sdl_net/target.mk @@ -0,0 +1,5 @@ +TARGET = test-sdl_net +LIBS = libc sdl_net +SRC_CC = main.cc + +vpath main.cc $(PRG_DIR)/..