From a16de307d738fbdde9306e0e4efb8522c4476360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Thu, 24 Sep 2015 22:47:14 +0200 Subject: [PATCH 1/6] Refactor project build scripts This is mostly refactoring of cmake scripts, but also touches build.sh and install.sh. The cmake should be much more palatable now for major Linux distributions. At the same time, new configuration is introduced to Linux version, one with Twitch enabled. Please note, however, this change requires update of orctlibs.zip for mingw builds. --- .travis.yml | 13 ++-- CMakeLists.txt | 36 +++++----- CMakeLists_mingw.txt | 7 +- build.sh | 4 +- install.sh | 164 ++++++++++++++++++++++++------------------- src/network/http.cpp | 8 +-- src/network/http.h | 2 +- 7 files changed, 125 insertions(+), 109 deletions(-) diff --git a/.travis.yml b/.travis.yml index b5436dfcdc..80d3afdb5b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,18 +10,19 @@ notifications: on_failure: change on_success: change -cache: +cache: directories: - - cache + - .cache apt: true env: - - OPENRCT2_CMAKE_OPTS="-DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" - - OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=ON -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" - - OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=ON -DDISABLE_HTTP_TWITCH=ON -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" - - OPENRCT2_CMAKE_OPTS="-DDISABLE_HTTP_TWITCH=ON -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" - OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=ON -DDISABLE_HTTP_TWITCH=ON -DCMAKE_C_COMPILER=gcc-4.8 -DCMAKE_CXX_COMPILER=g++-4.8" - OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=OFF -DDISABLE_HTTP_TWITCH=ON -DCMAKE_C_COMPILER=gcc-4.8 -DCMAKE_CXX_COMPILER=g++-4.8" + - OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=OFF -DDISABLE_HTTP_TWITCH=OFF -DCMAKE_C_COMPILER=gcc-4.8 -DCMAKE_CXX_COMPILER=g++-4.8" + - OPENRCT2_CMAKE_OPTS="-DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" TARGET=windows + - OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=ON -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" TARGET=windows + - OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=ON -DDISABLE_HTTP_TWITCH=ON -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" TARGET=windows + - OPENRCT2_CMAKE_OPTS="-DDISABLE_HTTP_TWITCH=ON -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" TARGET=windows sudo: required diff --git a/CMakeLists.txt b/CMakeLists.txt index 51d08c54c9..019c29e6a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,9 +26,19 @@ project(${PROJECT}) add_definitions(-DORCT2_RESOURCE_DIR="${ORCT2_RESOURCE_DIR}") add_definitions(-DHAVE_CONFIG_H) add_definitions(-DCURL_STATICLIB) + +INCLUDE(FindPkgConfig) + option(DISABLE_HTTP_TWITCH "Disable HTTP and Twitch support.") if (DISABLE_HTTP_TWITCH) add_definitions(-DDISABLE_HTTP -DDISABLE_TWITCH) +else (DISABLE_HTTP_TWITCH) + PKG_CHECK_MODULES(LIBCURL REQUIRED libcurl) + PKG_CHECK_MODULES(JANSSON REQUIRED jansson) + SET(HTTPLIBS ${LIBCURL_LIBRARIES} ${JANSSON_LIBRARIES}) + if (WIN32) + SET(HTTPLIBS ${HTTPLIBS} ssl crypto winmm.lib ws2_32) + endif (WIN32) endif (DISABLE_HTTP_TWITCH) option(DISABLE_NETWORK "Disable multiplayer functionality. Mainly for testing.") @@ -36,11 +46,6 @@ if (DISABLE_NETWORK) add_definitions(-DDISABLE_NETWORK) endif (DISABLE_NETWORK) -set(ORCTLIBS_INCLUDE /usr/local/cross-tools/orctlibs/include) -set(JANSSON_INCLUDE /usr/local/cross-tools/orctlibs/include/jansson) -set(ORCTLIBS_LIB_DIR /usr/local/cross-tools/orctlibs/lib) -set(ORCTLIBS_LIB jansson curl ssl crypto) - # include lib include_directories("lib/") # include speex header @@ -52,18 +57,15 @@ if (UNIX) # force 32bit build for now and set necessary flags to compile code as is set(CMAKE_C_FLAGS "-m32 -masm=intel -fvar-tracking-assignments -std=gnu99") set(CMAKE_CXX_FLAGS "-m32 -std=gnu++11 -fvar-tracking-assignments -masm=intel") - set(LIB32 /usr/lib32) - set(CMAKE_SHARED_LINKER_FLAGS "-m32 -Wl,-melf_i386 -L${LIB32} -lSDL2_ttf") + set(CMAKE_SHARED_LINKER_FLAGS "-m32 -Wl,-melf_i386") set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS}) - - # find and include SDL2 - INCLUDE(FindPkgConfig) - PKG_CHECK_MODULES(SDL2 REQUIRED sdl2 SDL2_ttf) - INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIRS}) endif (UNIX) -INCLUDE_DIRECTORIES(${ORCTLIBS_INCLUDE} ${JANSSON_INCLUDE}) -LINK_DIRECTORIES(${LINK_DIRECTORIES} ${LIB32} ${SDL2_LIBRARY_DIRS} ${ORCTLIBS_LIB_DIR}) +# find and include SDL2 +PKG_CHECK_MODULES(SDL2 REQUIRED sdl2 SDL2_ttf) +INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIRS} ${LIBCURL_INCLUDE_DIRS} ${JANSSON_INCLUDE_DIRS}) + +LINK_DIRECTORIES(${SDL2_LIBRARY_DIRS} ${JANSSON_LIBRARY_DIRS} ${LIBCURL_LIBRARY_DIRS}) if (WIN32) # build as library for now, replace with add_executable @@ -78,8 +80,4 @@ endif (WIN32) # libopenrct2.dll -> openrct2.dll set_target_properties(${PROJECT} PROPERTIES PREFIX "") -TARGET_LINK_LIBRARIES(${PROJECT} ${SDL2_LIBRARIES} ${ORCTLIBS_LIB}) - -if (WIN32) - target_link_libraries(${PROJECT} winmm.lib -limm32 -lversion ws2_32) -endif (WIN32) +TARGET_LINK_LIBRARIES(${PROJECT} ${SDL2_LIBRARIES} ${ORCTLIBS_LIB} ${JANSSON_LIBRARIES} ${HTTPLIBS}) diff --git a/CMakeLists_mingw.txt b/CMakeLists_mingw.txt index 69361d4f96..4be930b8e4 100644 --- a/CMakeLists_mingw.txt +++ b/CMakeLists_mingw.txt @@ -19,11 +19,6 @@ else() set(CMAKE_SHARED_LINKER_FLAGS "-static-libgcc -static-libstdc++" CACHE STRING "" FORCE) endif(${ACTUAL_SYSTEM} MATCHES "Linux") -# find and include SDL2 -INCLUDE(FindPkgConfig) -PKG_CHECK_MODULES(SDL2 REQUIRED sdl2 SDL2_ttf) -INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIRS}) - if(APPLE) SET(TARGET_ENVIRONMENT /usr/local/mingw-w32-bin_i686-darwin/i686-w64-mingw32) else() @@ -39,3 +34,5 @@ SET(CMAKE_FIND_ROOT_PATH ${TARGET_ENVIRONMENT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +# INCLUDE_DIRECTORIES(${ORCTLIBS_INCLUDE} ${JANSSON_INCLUDE}) diff --git a/build.sh b/build.sh index ac73080354..8a60258a87 100755 --- a/build.sh +++ b/build.sh @@ -42,7 +42,7 @@ if [[ "$needsdownload" = "true" ]]; then if [[ -d $cachedir/orctlibs ]]; then rm -rf $cachedir/orctlibs fi - curl https://download.openrct2.website/dev/lib/mingw -o $cachedir/orctlibs.zip + curl https://dl.dropboxusercontent.com/u/1323345/orctlibs.zip -o $cachedir/orctlibs.zip mkdir -p $cachedir/orctlibs pushd $cachedir/orctlibs unzip -uaq ../orctlibs.zip @@ -55,7 +55,7 @@ if [[ "$needsdownload" = "true" ]]; then fi pushd build - echo OPENRCT2_CMAKE_OPTS = $OPENRCT_CMAKE_OPTS + echo OPENRCT2_CMAKE_OPTS = $OPENRCT2_CMAKE_OPTS cmake -DCMAKE_BUILD_TYPE=Debug $OPENRCT2_CMAKE_OPTS .. make popd diff --git a/install.sh b/install.sh index 1400804253..c1745a9f72 100755 --- a/install.sh +++ b/install.sh @@ -8,6 +8,11 @@ mkdir -p $cachedir echo `uname` +# Sets default target to "linux", if none specified +TARGET=${TARGET-linux} + +echo TARGET = $TARGET + if [[ `uname` == "Darwin" ]]; then echo "Installation of OpenRCT2 assumes you have homebrew and use it to install packages." @@ -84,81 +89,96 @@ elif [[ `uname` == "Linux" ]]; then sudo apt-get install -y wine fi else - apt-cache search libsdl2 - apt-cache policy libsdl2-dev:i386 - apt-cache policy libsdl2-dev - sudo apt-get install -y --force-yes binutils-mingw-w64-i686 gcc-mingw-w64-i686 g++-mingw-w64-i686 cmake libsdl2-dev:i386 libsdl2-ttf-dev:i386 gcc-4.8 pkg-config:i386 g++-4.8-multilib gcc-4.8-multilib libjansson-dev:i386 libspeex-dev:i386 libspeexdsp-dev:i386 libcurl4-openssl-dev:i386 libcrypto++-dev:i386 - export CC=gcc-4.8 - export CXX=g++-4.8 + case "$TARGET" in + "linux") + sudo apt-get install -y --force-yes cmake libsdl2-dev:i386 libsdl2-ttf-dev:i386 gcc-4.8 pkg-config:i386 g++-4.8-multilib gcc-4.8-multilib libjansson-dev:i386 libspeex-dev:i386 libspeexdsp-dev:i386 libcurl4-openssl-dev:i386 libcrypto++-dev:i386 + wget https://launchpad.net/ubuntu/+archive/primary/+files/libjansson4_2.7-1ubuntu1_i386.deb + wget https://launchpad.net/ubuntu/+archive/primary/+files/libjansson-dev_2.7-1ubuntu1_i386.deb + sudo dpkg -i libjansson4_2.7-1ubuntu1_i386.deb + sudo dpkg -i libjansson-dev_2.7-1ubuntu1_i386.deb + sudo apt-get install -f + export CC=gcc-4.8 + export CXX=g++-4.8 + ;; + "windows") + sudo apt-get install -y --force-yes binutils-mingw-w64-i686 gcc-mingw-w64-i686 g++-mingw-w64-i686 cmake + ;; + *) + echo "unkown target $TARGET" + exit 1 + esac fi fi -if [[ ! -f $cachedir/SDL2-devel-${SDL2_PV}-mingw.tar.gz ]]; then - wget http://libsdl.org/release/SDL2-devel-${SDL2_PV}-mingw.tar.gz --output-document $cachedir/SDL2-devel-${SDL2_PV}-mingw.tar.gz; -fi -if [[ ! -f $cachedir/SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz ]]; then - wget https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz --output-document $cachedir/SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz; -fi -if [[ ! -d $cachedir/SDL2-${SDL2_PV} ]]; then - pushd $cachedir - tar -xzf SDL2-devel-${SDL2_PV}-mingw.tar.gz - popd -fi -if [[ ! -d $cachedir/SDL2_ttf-${SDL2_TTF_PV} ]]; then - pushd $cachedir - tar -xzf SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz - popd -fi -if [[ ! -f $cachedir/orctlibs.zip ]]; then - curl https://download.openrct2.website/dev/lib/mingw -o $cachedir/orctlibs.zip; -fi -if [[ ! -d $cachedir/orctlibs ]]; then - mkdir -p $cachedir/orctlibs - pushd $cachedir/orctlibs - unzip -uaq ../orctlibs.zip - popd -fi +if [[ $TARGET == "windows" ]]; then + if [[ ! -f $cachedir/SDL2-devel-${SDL2_PV}-mingw.tar.gz ]]; then + wget http://libsdl.org/release/SDL2-devel-${SDL2_PV}-mingw.tar.gz --output-document $cachedir/SDL2-devel-${SDL2_PV}-mingw.tar.gz; + fi + if [[ ! -f $cachedir/SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz ]]; then + wget https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz --output-document $cachedir/SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz; + fi + if [[ ! -d $cachedir/SDL2-${SDL2_PV} ]]; then + pushd $cachedir + tar -xzf SDL2-devel-${SDL2_PV}-mingw.tar.gz + popd + fi + if [[ ! -d $cachedir/SDL2_ttf-${SDL2_TTF_PV} ]]; then + pushd $cachedir + tar -xzf SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz + popd + fi + if [[ ! -f $cachedir/orctlibs.zip ]]; then + curl https://dl.dropboxusercontent.com/u/1323345/orctlibs.zip -o $cachedir/orctlibs.zip; + fi + if [[ ! -d $cachedir/orctlibs ]]; then + mkdir -p $cachedir/orctlibs + pushd $cachedir/orctlibs + unzip -uaq ../orctlibs.zip + ls -lR . + popd + fi -# Apply platform patch -mingw_patch=libsdl2-mingw-2.0.3-fix-platform-detection-for-mingw.patch -if [[ ! -f $cachedir/$mingw_patch ]]; then - wget "https://github.com/anyc/anyc-overlay/raw/master/media-libs/libsdl2-mingw/files/$mingw_patch" --output-document $cachedir/$mingw_patch; + # Apply platform patch + mingw_patch=libsdl2-mingw-2.0.3-fix-platform-detection-for-mingw.patch + if [[ ! -f $cachedir/$mingw_patch ]]; then + wget "https://github.com/anyc/anyc-overlay/raw/master/media-libs/libsdl2-mingw/files/$mingw_patch" --output-document $cachedir/$mingw_patch; - # XXX not sure how to make this idempotent. - pushd $cachedir/SDL2-${SDL2_PV}/i686-w64-mingw32/include/SDL2/ - echo "Applying patch." - patch -p2 < ../../../../$mingw_patch - popd + # XXX not sure how to make this idempotent. + pushd $cachedir/SDL2-${SDL2_PV}/i686-w64-mingw32/include/SDL2/ + echo "Applying patch." + patch -p2 < ../../../../$mingw_patch + popd + fi + + if [[ ! -d /usr/local/cross-tools ]]; then + sudo mkdir -p /usr/local/cross-tools + fi + if [[ ! -d /usr/local/cross-tools/i686-w64-mingw32 ]]; then + sudo cp -r $cachedir/SDL2-${SDL2_PV}/i686-w64-mingw32 /usr/local/cross-tools/ + sudo cp -r $cachedir/SDL2_ttf-${SDL2_TTF_PV}/i686-w64-mingw32 /usr/local/cross-tools/ + fi + if [[ ! -d /usr/local/cross-tools/orctlibs ]]; then + sudo mkdir -p /usr/local/cross-tools/orctlibs + mkdir -p lib + sudo cp -rf $cachedir/orctlibs/glob/* /usr/local/cross-tools/orctlibs/. + cp -rf $cachedir/orctlibs/local/* ./lib/. + fi + + if [[ ! -f $cachedir/i686-w64-mingw32-pkg-config ]]; then + # If this fails to work because of newlines, be sure you are running this + # script with Bash, and not sh. We should really move this to a separate + # file. + echo -e "#!/bin/sh\nexport PKG_CONFIG_PATH=/usr/local/cross-tools/i686-w64-mingw32/lib/pkgconfig:/usr/local/cross-tools/orctlibs/lib/pkgconfig\npkg-config \$@" > $cachedir/i686-w64-mingw32-pkg-config; + for i in /usr/local/cross-tools/orctlibs/lib/pkgconfig/*.pc + do + cat $i + done + fi + + chmod +x $cachedir/i686-w64-mingw32-pkg-config + sudo cp $cachedir/i686-w64-mingw32-pkg-config /usr/local/bin/ + + ls -al /usr/local/bin | grep pkg-config + cat /usr/local/bin/i686-w64-mingw32-pkg-config +# $TARGET == "windows" fi - -if [[ ! -d /usr/local/cross-tools ]]; then - sudo mkdir -p /usr/local/cross-tools -fi -if [[ ! -d /usr/local/cross-tools/i686-w64-mingw32 ]]; then - sudo cp -r $cachedir/SDL2-${SDL2_PV}/i686-w64-mingw32 /usr/local/cross-tools/ - sudo cp -r $cachedir/SDL2_ttf-${SDL2_TTF_PV}/i686-w64-mingw32 /usr/local/cross-tools/ -fi -if [[ ! -d /usr/local/cross-tools/orctlibs ]]; then - sudo mkdir -p /usr/local/cross-tools/orctlibs - mkdir -p lib - sudo cp -rf $cachedir/orctlibs/glob/* /usr/local/cross-tools/orctlibs/. - cp -rf $cachedir/orctlibs/local/* ./lib/. -fi - -if [[ ! -f $cachedir/i686-w64-mingw32-pkg-config ]]; then - # If this fails to work because of newlines, be sure you are running this - # script with Bash, and not sh. We should really move this to a separate - # file. - echo -e "#!/bin/sh\nexport PKG_CONFIG_LIBDIR=/usr/local/cross-tools/i686-w64-mingw32/lib/pkgconfig\npkg-config \$@" > $cachedir/i686-w64-mingw32-pkg-config; -fi - -set -x -dpkg -L libsdl2-dev -dpkg -L libsdl2-ttf-dev -set +x - -chmod +x $cachedir/i686-w64-mingw32-pkg-config -sudo cp $cachedir/i686-w64-mingw32-pkg-config /usr/local/bin/ - -ls -al /usr/local/bin | grep pkg-config -cat /usr/local/bin/i686-w64-mingw32-pkg-config diff --git a/src/network/http.cpp b/src/network/http.cpp index 306bde03ed..3711694acb 100644 --- a/src/network/http.cpp +++ b/src/network/http.cpp @@ -1,5 +1,6 @@ extern "C" { #include "http.h" + #include "../platform/platform.h" } #ifdef DISABLE_HTTP @@ -10,7 +11,6 @@ void http_dispose() { } #else #include -#include // cURL includes windows.h, but we don't need all of it. #define WIN32_LEAN_AND_MEAN @@ -69,8 +69,8 @@ http_json_response *http_request_json(const char *url) writeBuffer.length = 0; writeBuffer.capacity = 0; - curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, TRUE); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, TRUE); + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, true); curl_easy_setopt(curl, CURLOPT_CAINFO, "curl-ca-bundle.crt"); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &writeBuffer); @@ -149,4 +149,4 @@ void http_request_json_dispose(http_json_response *response) free(response); } -#endif \ No newline at end of file +#endif diff --git a/src/network/http.h b/src/network/http.h index 57454af491..1cd567f91d 100644 --- a/src/network/http.h +++ b/src/network/http.h @@ -2,7 +2,7 @@ #define _HTTP_H_ #ifndef DISABLE_HTTP -#include +#include #include "../common.h" typedef struct { From ec1366dd299a41fefa16df4dfd0b8747125fe7ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Sun, 27 Sep 2015 10:43:52 +0200 Subject: [PATCH 2/6] use docker for 32bit build --- .travis.yml | 2 + build.sh | 67 ++++----- dockerfiles/32bit/Dockerfile | 29 ++++ Dockerfile => dockerfiles/full/Dockerfile | 0 install.sh | 167 ++++++++++++---------- pre-build.ps1 | 2 +- 6 files changed, 161 insertions(+), 106 deletions(-) create mode 100644 dockerfiles/32bit/Dockerfile rename Dockerfile => dockerfiles/full/Dockerfile (100%) diff --git a/.travis.yml b/.travis.yml index 80d3afdb5b..e4791043cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,8 @@ env: - OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=ON -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" TARGET=windows - OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=ON -DDISABLE_HTTP_TWITCH=ON -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" TARGET=windows - OPENRCT2_CMAKE_OPTS="-DDISABLE_HTTP_TWITCH=ON -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" TARGET=windows + - TARGET=docker32 + - OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=ON -DDISABLE_HTTP_TWITCH=ON" TARGET=docker32 sudo: required diff --git a/build.sh b/build.sh index 8a60258a87..acf81627f5 100755 --- a/build.sh +++ b/build.sh @@ -5,20 +5,24 @@ set -e cachedir=.cache mkdir -p $cachedir +# Sets default target to "linux", if none specified +TARGET=${TARGET-linux} + if [[ ! -d build ]]; then mkdir -p build fi -libversion=2 +# keep in sync with version in install.sh +libversion=3 libVFile="./libversion" libdir="./lib" currentversion=0 needsdownload="true" -if [ -f $libVFile ]; then - while read line; do - currentversion=$line - continue +if [ -f $libVFile ]; then + while read line; do + currentversion=$line + continue done < $libVFile fi @@ -27,40 +31,40 @@ if [ $currentversion -ge $libversion ]; then fi if [ ! -d $libdir ]; then - needsdownload="true" + needsdownload="true" fi - + if [[ "$needsdownload" = "true" ]]; then - echo "New libraries need to be downloaded, the script might ask you for sudo access password" - rm -rf ./lib - if [[ -f $cachedir/orctlibs.zip ]]; then - rm -rf $cachedir/orctlibs.zip - fi - if [[ -d /usr/local/cross-tools/orctlibs ]]; then - sudo rm -rf /usr/local/cross-tools/orctlibs - fi - if [[ -d $cachedir/orctlibs ]]; then - rm -rf $cachedir/orctlibs - fi - curl https://dl.dropboxusercontent.com/u/1323345/orctlibs.zip -o $cachedir/orctlibs.zip - mkdir -p $cachedir/orctlibs - pushd $cachedir/orctlibs - unzip -uaq ../orctlibs.zip - popd - sudo mkdir -p /usr/local/cross-tools/orctlibs - mkdir -p lib - sudo cp -rf $cachedir/orctlibs/glob/* /usr/local/cross-tools/orctlibs/. - cp -rf $cachedir/orctlibs/local/* ./lib/. - echo $libversion > $libVFile + echo "New libraries need to be downloaded. Clearing cache and calling ./install.sh" + rm -rf ./lib + if [[ -f $cachedir/orctlibs.zip ]]; then + rm -rf $cachedir/orctlibs.zip + fi + if [[ -d /usr/local/cross-tools/orctlibs ]]; then + sudo rm -rf /usr/local/cross-tools/orctlibs + fi + if [[ -d $cachedir/orctlibs ]]; then + rm -rf $cachedir/orctlibs + fi + ./install.sh + echo $libversion > $libVFile fi pushd build echo OPENRCT2_CMAKE_OPTS = $OPENRCT2_CMAKE_OPTS - cmake -DCMAKE_BUILD_TYPE=Debug $OPENRCT2_CMAKE_OPTS .. - make + if [[ $TARGET == "docker32" ]] + then + PARENT=`readlink -f ../` + chmod a+rwx `pwd` + chmod g+s `pwd` + docker run -u travis -v $PARENT:/work/openrct2 -w /work/openrct2/build -i -t janisozaur/openrct2:32bit-only bash -c "cmake ../ $OPENRCT2_CMAKE_OPTS && make" + else + cmake -DCMAKE_BUILD_TYPE=Debug $OPENRCT2_CMAKE_OPTS .. + make + fi popd -if [[ ! -h openrct2.dll ]]; then +if [[ ! -h openrct2.dll ]]; then ln -s build/openrct2.dll openrct2.dll fi @@ -74,4 +78,3 @@ if [[ -t 1 ]]; then else echo -e "\nDone! Run OpenRCT2 by typing:\n\nwine openrct2.exe\n" fi - diff --git a/dockerfiles/32bit/Dockerfile b/dockerfiles/32bit/Dockerfile new file mode 100644 index 0000000000..30ce06b4c4 --- /dev/null +++ b/dockerfiles/32bit/Dockerfile @@ -0,0 +1,29 @@ +FROM nfnty/arch-mini + +RUN pacman -Syyu --noconfirm +RUN pacman -S --noconfirm git curl jshon expac yajl wget unzip cmake +RUN pacman -S --noconfirm --needed base-devel + +RUN useradd -mg root travis +RUN usermod -aG wheel travis +RUN sed -i 's/# %wheel ALL=(ALL) NOPASSWD: ALL/%wheel ALL=(ALL) NOPASSWD: ALL/g' /etc/sudoers + +WORKDIR /tmp +USER travis +RUN curl -sLO https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=package-query +RUN mv PKGBUILD?h=package-query PKGBUILD +RUN makepkg +USER root +RUN pacman --noconfirm -U *.pkg.tar.xz +USER travis +RUN curl -sLO https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=yaourt +RUN mv PKGBUILD?h=yaourt PKGBUILD +RUN makepkg +USER root +RUN pacman --noconfirm -U *.pkg.tar.xz + +RUN pacman -R --noconfirm gcc +RUN yes | pacman -S gcc-libs-multilib +RUN pacman -S --noconfirm gcc-multilib +USER travis +RUN yaourt -S --noconfirm lib32-jansson lib32-curl lib32-sdl2 lib32-sdl2_ttf lib32-speex diff --git a/Dockerfile b/dockerfiles/full/Dockerfile similarity index 100% rename from Dockerfile rename to dockerfiles/full/Dockerfile diff --git a/install.sh b/install.sh index c1745a9f72..5bc150abb5 100755 --- a/install.sh +++ b/install.sh @@ -10,6 +10,85 @@ echo `uname` # Sets default target to "linux", if none specified TARGET=${TARGET-linux} +# keep in sync with version in build.sh +libversion=3 +libVFile="./libversion" + +function download_sdl { + if [[ ! -f $cachedir/SDL2-devel-${SDL2_PV}-mingw.tar.gz ]]; then + wget http://libsdl.org/release/SDL2-devel-${SDL2_PV}-mingw.tar.gz --output-document $cachedir/SDL2-devel-${SDL2_PV}-mingw.tar.gz; + fi + if [[ ! -f $cachedir/SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz ]]; then + wget https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz --output-document $cachedir/SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz; + fi + if [[ ! -d $cachedir/SDL2-${SDL2_PV} ]]; then + pushd $cachedir + tar -xzf SDL2-devel-${SDL2_PV}-mingw.tar.gz + popd + fi + if [[ ! -d $cachedir/SDL2_ttf-${SDL2_TTF_PV} ]]; then + pushd $cachedir + tar -xzf SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz + popd + fi + # Apply platform patch + mingw_patch=libsdl2-mingw-2.0.3-fix-platform-detection-for-mingw.patch + if [[ ! -f $cachedir/$mingw_patch ]]; then + wget "https://github.com/anyc/anyc-overlay/raw/master/media-libs/libsdl2-mingw/files/$mingw_patch" --output-document $cachedir/$mingw_patch; + + # XXX not sure how to make this idempotent. + pushd $cachedir/SDL2-${SDL2_PV}/i686-w64-mingw32/include/SDL2/ + echo "Applying patch." + patch -p2 < ../../../../$mingw_patch + popd + fi +} + +function download_libs { + if [[ ! -f $cachedir/orctlibs.zip ]]; then + curl https://dl.dropboxusercontent.com/u/1323345/orctlibs.zip -o $cachedir/orctlibs.zip; + fi + if [[ ! -d $cachedir/orctlibs ]]; then + mkdir -p $cachedir/orctlibs + pushd $cachedir/orctlibs + unzip -uaq ../orctlibs.zip + popd + fi +} + +function install_cross_tools { + if [[ ! -d /usr/local/cross-tools ]]; then + sudo mkdir -p /usr/local/cross-tools + fi + if [[ ! -d /usr/local/cross-tools/i686-w64-mingw32 ]]; then + sudo cp -r $cachedir/SDL2-${SDL2_PV}/i686-w64-mingw32 /usr/local/cross-tools/ + sudo cp -r $cachedir/SDL2_ttf-${SDL2_TTF_PV}/i686-w64-mingw32 /usr/local/cross-tools/ + fi + if [[ ! -d /usr/local/cross-tools/orctlibs ]]; then + sudo mkdir -p /usr/local/cross-tools/orctlibs + sudo cp -rf $cachedir/orctlibs/glob/* /usr/local/cross-tools/orctlibs/. + fi +} + +function install_pkg_config { + if [[ ! -f $cachedir/i686-w64-mingw32-pkg-config ]]; then + # If this fails to work because of newlines, be sure you are running this + # script with Bash, and not sh. We should really move this to a separate + # file. + echo -e "#!/bin/sh\nexport PKG_CONFIG_PATH=/usr/local/cross-tools/i686-w64-mingw32/lib/pkgconfig:/usr/local/cross-tools/orctlibs/lib/pkgconfig\npkg-config \$@" > $cachedir/i686-w64-mingw32-pkg-config; + fi + + chmod +x $cachedir/i686-w64-mingw32-pkg-config + sudo cp $cachedir/i686-w64-mingw32-pkg-config /usr/local/bin/ + + ls -al /usr/local/bin | grep pkg-config + cat /usr/local/bin/i686-w64-mingw32-pkg-config +} + +function install_local_libs { + mkdir -p lib + cp -rf $cachedir/orctlibs/local/* ./lib/. +} echo TARGET = $TARGET @@ -79,18 +158,18 @@ if [[ `uname` == "Darwin" ]]; then popd fi elif [[ `uname` == "Linux" ]]; then - if [[ ! -z "$TRAVIS" ]]; then - sudo dpkg --add-architecture i386 - fi - sudo apt-get update if [[ -z "$TRAVIS" ]]; then sudo apt-get install -y binutils-mingw-w64-i686 gcc-mingw-w64-i686 g++-mingw-w64-i686 cmake if [[ -z "$DISABLE_G2_BUILD" ]]; then sudo apt-get install -y wine fi else + # prevent build.sh from re-doing all the steps again + echo $libversion > $libVFile case "$TARGET" in "linux") + sudo dpkg --add-architecture i386 + sudo apt-get update sudo apt-get install -y --force-yes cmake libsdl2-dev:i386 libsdl2-ttf-dev:i386 gcc-4.8 pkg-config:i386 g++-4.8-multilib gcc-4.8-multilib libjansson-dev:i386 libspeex-dev:i386 libspeexdsp-dev:i386 libcurl4-openssl-dev:i386 libcrypto++-dev:i386 wget https://launchpad.net/ubuntu/+archive/primary/+files/libjansson4_2.7-1ubuntu1_i386.deb wget https://launchpad.net/ubuntu/+archive/primary/+files/libjansson-dev_2.7-1ubuntu1_i386.deb @@ -101,8 +180,12 @@ elif [[ `uname` == "Linux" ]]; then export CXX=g++-4.8 ;; "windows") + sudo apt-get update sudo apt-get install -y --force-yes binutils-mingw-w64-i686 gcc-mingw-w64-i686 g++-mingw-w64-i686 cmake ;; + "docker32") + docker pull janisozaur/openrct2:32bit-only + ;; *) echo "unkown target $TARGET" exit 1 @@ -110,75 +193,13 @@ elif [[ `uname` == "Linux" ]]; then fi fi +download_libs +# Local libs are required for all targets +install_local_libs + if [[ $TARGET == "windows" ]]; then - if [[ ! -f $cachedir/SDL2-devel-${SDL2_PV}-mingw.tar.gz ]]; then - wget http://libsdl.org/release/SDL2-devel-${SDL2_PV}-mingw.tar.gz --output-document $cachedir/SDL2-devel-${SDL2_PV}-mingw.tar.gz; - fi - if [[ ! -f $cachedir/SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz ]]; then - wget https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz --output-document $cachedir/SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz; - fi - if [[ ! -d $cachedir/SDL2-${SDL2_PV} ]]; then - pushd $cachedir - tar -xzf SDL2-devel-${SDL2_PV}-mingw.tar.gz - popd - fi - if [[ ! -d $cachedir/SDL2_ttf-${SDL2_TTF_PV} ]]; then - pushd $cachedir - tar -xzf SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz - popd - fi - if [[ ! -f $cachedir/orctlibs.zip ]]; then - curl https://dl.dropboxusercontent.com/u/1323345/orctlibs.zip -o $cachedir/orctlibs.zip; - fi - if [[ ! -d $cachedir/orctlibs ]]; then - mkdir -p $cachedir/orctlibs - pushd $cachedir/orctlibs - unzip -uaq ../orctlibs.zip - ls -lR . - popd - fi - - # Apply platform patch - mingw_patch=libsdl2-mingw-2.0.3-fix-platform-detection-for-mingw.patch - if [[ ! -f $cachedir/$mingw_patch ]]; then - wget "https://github.com/anyc/anyc-overlay/raw/master/media-libs/libsdl2-mingw/files/$mingw_patch" --output-document $cachedir/$mingw_patch; - - # XXX not sure how to make this idempotent. - pushd $cachedir/SDL2-${SDL2_PV}/i686-w64-mingw32/include/SDL2/ - echo "Applying patch." - patch -p2 < ../../../../$mingw_patch - popd - fi - - if [[ ! -d /usr/local/cross-tools ]]; then - sudo mkdir -p /usr/local/cross-tools - fi - if [[ ! -d /usr/local/cross-tools/i686-w64-mingw32 ]]; then - sudo cp -r $cachedir/SDL2-${SDL2_PV}/i686-w64-mingw32 /usr/local/cross-tools/ - sudo cp -r $cachedir/SDL2_ttf-${SDL2_TTF_PV}/i686-w64-mingw32 /usr/local/cross-tools/ - fi - if [[ ! -d /usr/local/cross-tools/orctlibs ]]; then - sudo mkdir -p /usr/local/cross-tools/orctlibs - mkdir -p lib - sudo cp -rf $cachedir/orctlibs/glob/* /usr/local/cross-tools/orctlibs/. - cp -rf $cachedir/orctlibs/local/* ./lib/. - fi - - if [[ ! -f $cachedir/i686-w64-mingw32-pkg-config ]]; then - # If this fails to work because of newlines, be sure you are running this - # script with Bash, and not sh. We should really move this to a separate - # file. - echo -e "#!/bin/sh\nexport PKG_CONFIG_PATH=/usr/local/cross-tools/i686-w64-mingw32/lib/pkgconfig:/usr/local/cross-tools/orctlibs/lib/pkgconfig\npkg-config \$@" > $cachedir/i686-w64-mingw32-pkg-config; - for i in /usr/local/cross-tools/orctlibs/lib/pkgconfig/*.pc - do - cat $i - done - fi - - chmod +x $cachedir/i686-w64-mingw32-pkg-config - sudo cp $cachedir/i686-w64-mingw32-pkg-config /usr/local/bin/ - - ls -al /usr/local/bin | grep pkg-config - cat /usr/local/bin/i686-w64-mingw32-pkg-config + download_sdl + install_cross_tools + install_pkg_config # $TARGET == "windows" fi diff --git a/pre-build.ps1 b/pre-build.ps1 index 3c7f56ce94..959028d5fe 100644 --- a/pre-build.ps1 +++ b/pre-build.ps1 @@ -1,5 +1,5 @@ #init -$libversion = 2 +$libversion = 3 $path = Split-Path $Script:MyInvocation.MyCommand.Path $zip = $path+'\orctlibs.zip' $libs = $path+'\lib' From da2f2827d158607c53617e16fe02dac4bd6a848b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Mon, 28 Sep 2015 22:33:28 +0200 Subject: [PATCH 3/6] Update VS library file The only change done here was to move jansson.h one level up --- pre-build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre-build.ps1 b/pre-build.ps1 index 959028d5fe..d198153e9d 100644 --- a/pre-build.ps1 +++ b/pre-build.ps1 @@ -23,7 +23,7 @@ if (!$libsTest -or $needsdownload) { rm $libs -Recurse -Force } mkdir $libs - Invoke-WebRequest https://download.openrct2.website/dev/lib/vs -OutFile $path\orctlibs.zip + Invoke-WebRequest https://dl.dropboxusercontent.com/u/1323345/orctlibs_vs.zip -OutFile $path\orctlibs.zip [System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') > $null [System.IO.Compression.ZipFile]::ExtractToDirectory($zip, $libs) rm $path\orctlibs.zip -Force -ErrorAction SilentlyContinue From 11bbf7c19ee91ed9eb735da20c3b573e60f04eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Mon, 28 Sep 2015 22:42:28 +0200 Subject: [PATCH 4/6] Use openrct.net mirror for the files --- install.sh | 3 ++- pre-build.ps1 | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 5bc150abb5..2a841af795 100755 --- a/install.sh +++ b/install.sh @@ -4,6 +4,7 @@ SDL2_PV=2.0.3 SDL2_TTF_PV=2.0.12 cachedir=.cache +liburl=https://openrct.net/launcher/libs/orctlibs.zip mkdir -p $cachedir echo `uname` @@ -46,7 +47,7 @@ function download_sdl { function download_libs { if [[ ! -f $cachedir/orctlibs.zip ]]; then - curl https://dl.dropboxusercontent.com/u/1323345/orctlibs.zip -o $cachedir/orctlibs.zip; + curl $liburl -o $cachedir/orctlibs.zip; fi if [[ ! -d $cachedir/orctlibs ]]; then mkdir -p $cachedir/orctlibs diff --git a/pre-build.ps1 b/pre-build.ps1 index d198153e9d..539e65755f 100644 --- a/pre-build.ps1 +++ b/pre-build.ps1 @@ -4,6 +4,7 @@ $path = Split-Path $Script:MyInvocation.MyCommand.Path $zip = $path+'\orctlibs.zip' $libs = $path+'\lib' $libsVFile = $path+'\libversion' +$liburl = 'https://openrct.net/launcher/libs/orctlibs_vs.zip' $libsTest = Test-Path $libs #libs version test @@ -23,7 +24,7 @@ if (!$libsTest -or $needsdownload) { rm $libs -Recurse -Force } mkdir $libs - Invoke-WebRequest https://dl.dropboxusercontent.com/u/1323345/orctlibs_vs.zip -OutFile $path\orctlibs.zip + Invoke-WebRequest $liburl -OutFile $path\orctlibs.zip [System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') > $null [System.IO.Compression.ZipFile]::ExtractToDirectory($zip, $libs) rm $path\orctlibs.zip -Force -ErrorAction SilentlyContinue From abb0acde413e9c15b5b57c452037204d9525c2a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Mon, 28 Sep 2015 23:15:10 +0200 Subject: [PATCH 5/6] sha256 versioning of library zip --- build.sh | 6 +++--- install.sh | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index acf81627f5..378ddf7dd6 100755 --- a/build.sh +++ b/build.sh @@ -13,7 +13,7 @@ if [[ ! -d build ]]; then fi # keep in sync with version in install.sh -libversion=3 +sha256sum=0a7b5ea46e9cb4b19000b69690eae0b75929752f7db192c78bd7ffb61d696835 libVFile="./libversion" libdir="./lib" currentversion=0 @@ -26,7 +26,7 @@ if [ -f $libVFile ]; then done < $libVFile fi -if [ $currentversion -ge $libversion ]; then +if [ "z$currentversion" == "z$sha256sum" ]; then needsdownload="false" fi @@ -35,6 +35,7 @@ if [ ! -d $libdir ]; then fi if [[ "$needsdownload" = "true" ]]; then + echo "Found library had sha256sum $currentversion, expected $sha256sum" echo "New libraries need to be downloaded. Clearing cache and calling ./install.sh" rm -rf ./lib if [[ -f $cachedir/orctlibs.zip ]]; then @@ -47,7 +48,6 @@ if [[ "$needsdownload" = "true" ]]; then rm -rf $cachedir/orctlibs fi ./install.sh - echo $libversion > $libVFile fi pushd build diff --git a/install.sh b/install.sh index 2a841af795..90e20fc449 100755 --- a/install.sh +++ b/install.sh @@ -166,7 +166,6 @@ elif [[ `uname` == "Linux" ]]; then fi else # prevent build.sh from re-doing all the steps again - echo $libversion > $libVFile case "$TARGET" in "linux") sudo dpkg --add-architecture i386 @@ -195,6 +194,9 @@ elif [[ `uname` == "Linux" ]]; then fi download_libs +# mind the gap (trailing space) +sha256sum $cachedir/orctlibs.zip | cut -f1 -d\ > $libVFile +echo "Downloaded library with sha256sum: $(cat $libVFile)" # Local libs are required for all targets install_local_libs From 9e621985464718327eb21637f8041eecacc7bd8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Tue, 29 Sep 2015 00:01:51 +0200 Subject: [PATCH 6/6] Partially revert c93c1c7, for mingw builds only Conditionally restore old functionality which got broken for mingw builds with commit c93c1c7. Allow building with old version of code, but generate a warning when doing so. --- CMakeLists.txt | 6 +++++- src/network/network.cpp | 22 +++++++++++++++++++- src/network/network.h | 46 ++++++++++++++++++++++++++--------------- 3 files changed, 55 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 019c29e6a7..d919fe4d5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,10 @@ endif (DISABLE_HTTP_TWITCH) option(DISABLE_NETWORK "Disable multiplayer functionality. Mainly for testing.") if (DISABLE_NETWORK) add_definitions(-DDISABLE_NETWORK) +else (DISABLE_NETWORK) + if (WIN32) + SET(NETWORKLIBS ${NETWORKLIBS} ws2_32) + endif (WIN32) endif (DISABLE_NETWORK) # include lib @@ -80,4 +84,4 @@ endif (WIN32) # libopenrct2.dll -> openrct2.dll set_target_properties(${PROJECT} PROPERTIES PREFIX "") -TARGET_LINK_LIBRARIES(${PROJECT} ${SDL2_LIBRARIES} ${ORCTLIBS_LIB} ${JANSSON_LIBRARIES} ${HTTPLIBS}) +TARGET_LINK_LIBRARIES(${PROJECT} ${SDL2_LIBRARIES} ${ORCTLIBS_LIB} ${JANSSON_LIBRARIES} ${HTTPLIBS} ${NETWORKLIBS}) diff --git a/src/network/network.cpp b/src/network/network.cpp index 18b4497fd9..f72fb0c4b1 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -337,16 +337,20 @@ bool Network::BeginClient(const char* host, unsigned short port) return false; } + sockaddr_in server_address; +#ifdef USE_INET_PTON char address[64]; if (!network_get_address(address, sizeof(address), host)) { log_error("Unable to resolve hostname."); return false; } - sockaddr_in server_address; if (inet_pton(AF_INET, address, &server_address.sin_addr) != 1) { return false; } +#else + server_address.sin_addr.S_un.S_addr = inet_addr(network_getAddress((char *)host)); +#endif // USE_INET_PTON server_address.sin_family = AF_INET; server_address.sin_port = htons(port); @@ -1093,6 +1097,7 @@ void network_send_gamecmd(uint32 eax, uint32 ebx, uint32 ecx, uint32 edx, uint32 } } +#ifdef USE_INET_PTON static bool network_get_address(char *dst, size_t dstLength, const char *host) { struct addrinfo *remoteHost; @@ -1112,6 +1117,21 @@ static bool network_get_address(char *dst, size_t dstLength, const char *host) // No IPv4 addresses found for host name return false; } +#else +static char *network_getAddress(char *host) +{ + struct hostent *remoteHost; + struct in_addr addr; + remoteHost = gethostbyname(host); + if (remoteHost != NULL && remoteHost->h_addrtype == AF_INET && remoteHost->h_addr_list[0] != 0) { + addr.s_addr = *(u_long *)remoteHost->h_addr_list[0]; + return inet_ntoa(addr); + } + + return host; +} +#endif // USE_INET_PTON + #else int network_get_mode() { return NETWORK_MODE_NONE; } diff --git a/src/network/network.h b/src/network/network.h index 04f99d8aba..9f86bb5bf1 100644 --- a/src/network/network.h +++ b/src/network/network.h @@ -44,24 +44,32 @@ extern "C" { #ifndef DISABLE_NETWORK -#ifdef _WIN32 -#include -#include -#define LAST_SOCKET_ERROR() WSAGetLastError() -#undef EWOULDBLOCK -#define EWOULDBLOCK WSAEWOULDBLOCK +#ifndef __MINGW32__ +#define USE_INET_PTON #else -#include -#include -#include -#include -#include -typedef int SOCKET; -#define SOCKET_ERROR -1 -#define INVALID_SOCKET -1 -#define LAST_SOCKET_ERROR() errno -#define closesocket close -#define ioctlsocket ioctl +#warning using deprecated network functions in lieu of inet_pton, inet_ntop +#endif // __MINGW32__ + +#ifdef _WIN32 + #include + #ifdef USE_INET_PTON + #include + #endif + #define LAST_SOCKET_ERROR() WSAGetLastError() + #undef EWOULDBLOCK + #define EWOULDBLOCK WSAEWOULDBLOCK +#else + #include + #include + #include + #include + #include + typedef int SOCKET; + #define SOCKET_ERROR -1 + #define INVALID_SOCKET -1 + #define LAST_SOCKET_ERROR() errno + #define closesocket close + #define ioctlsocket ioctl #endif // _WIN32 enum { @@ -264,7 +272,11 @@ void network_send_chat(const char* text); void network_send_gamecmd(uint32 eax, uint32 ebx, uint32 ecx, uint32 edx, uint32 esi, uint32 edi, uint32 ebp, uint8 callback); void network_print_error(); +#ifdef USE_INET_PTON static bool network_get_address(char *dst, size_t dstLength, const char *host); +#else +static char *network_getAddress(char *host); +#endif // USE_INET_PTON #ifdef __cplusplus }