diff --git a/cmake/Toolchain-cross-MinGW-w64-i686.cmake b/cmake/Toolchain-cross-MinGW-w64-i686.cmake index 021b84f3..ed78c832 100644 --- a/cmake/Toolchain-cross-MinGW-w64-i686.cmake +++ b/cmake/Toolchain-cross-MinGW-w64-i686.cmake @@ -1,6 +1,7 @@ SET(CMAKE_SYSTEM_NAME Windows) -set(COMPILER_PREFIX "i686-w64-mingw32") +set(CROSS_ARCH i686) +set(COMPILER_PREFIX "${CROSS_ARCH}-w64-mingw32") unset(CMAKE_RC_COMPILER CACHE) unset(CMAKE_C_COMPILER CACHE) @@ -12,7 +13,7 @@ find_program(CMAKE_RC_COMPILER NAMES ${COMPILER_PREFIX}-windres) find_program(CMAKE_C_COMPILER NAMES ${COMPILER_PREFIX}-gcc) find_program(CMAKE_CXX_COMPILER NAMES ${COMPILER_PREFIX}-g++) -SET(CMAKE_FIND_ROOT_PATH /usr/${COMPILER_PREFIX} /usr/${COMPILER_PREFIX}/sys-root/mingw) +SET(CMAKE_FIND_ROOT_PATH /usr/${COMPILER_PREFIX} /usr/${COMPILER_PREFIX}/sys-root/mingw /usr/local/opt/mingw-w64/toolchain-${CROSS_ARCH}/${COMPILER_PREFIX}) if(CMAKE_PREFIX_PATH) set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CMAKE_PREFIX_PATH}) diff --git a/cmake/Toolchain-cross-MinGW-w64-x86_64.cmake b/cmake/Toolchain-cross-MinGW-w64-x86_64.cmake index 91ea14b0..ff983371 100644 --- a/cmake/Toolchain-cross-MinGW-w64-x86_64.cmake +++ b/cmake/Toolchain-cross-MinGW-w64-x86_64.cmake @@ -1,6 +1,7 @@ SET(CMAKE_SYSTEM_NAME Windows) -set(COMPILER_PREFIX "x86_64-w64-mingw32") +set(CROSS_ARCH x86_64) +set(COMPILER_PREFIX "${CROSS_ARCH}-w64-mingw32") unset(CMAKE_RC_COMPILER CACHE) unset(CMAKE_C_COMPILER CACHE) @@ -12,7 +13,7 @@ find_program(CMAKE_RC_COMPILER NAMES ${COMPILER_PREFIX}-windres) find_program(CMAKE_C_COMPILER NAMES ${COMPILER_PREFIX}-gcc) find_program(CMAKE_CXX_COMPILER NAMES ${COMPILER_PREFIX}-g++) -SET(CMAKE_FIND_ROOT_PATH /usr/${COMPILER_PREFIX} /usr/${COMPILER_PREFIX}/sys-root/mingw) +SET(CMAKE_FIND_ROOT_PATH /usr/${COMPILER_PREFIX} /usr/${COMPILER_PREFIX}/sys-root/mingw /usr/local/opt/mingw-w64/toolchain-${CROSS_ARCH}/${COMPILER_PREFIX}) if(CMAKE_PREFIX_PATH) set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CMAKE_PREFIX_PATH}) diff --git a/src/common/ConfigManager.cpp b/src/common/ConfigManager.cpp index 3cc21c95..bc43853a 100644 --- a/src/common/ConfigManager.cpp +++ b/src/common/ConfigManager.cpp @@ -763,11 +763,7 @@ void SaveConfigFile() FILE *f = fopen(configFile, "w"); if (f == NULL) { char err_msg[4096] = "unknown error"; -#ifdef _WIN32 - strerror_s(err_msg, errno, 4096); -#else - strerror_r(errno, err_msg, 4096); -#endif + strncpy(err_msg, strerror(errno), 4096); fprintf(stderr, "Configuration file '%s' could not be written to: %s\n", configFile, err_msg); return; } diff --git a/tools/builder/core.sh b/tools/builder/core.sh index 42697828..22b2d0de 100644 --- a/tools/builder/core.sh +++ b/tools/builder/core.sh @@ -48,6 +48,7 @@ export CFLAGS="$CFLAGS -fPIC -I$BUILD_ROOT/root/include -L$BUILD_ROOT/root/lib - export CXXFLAGS="$CXXFLAGS -fPIC -I$BUILD_ROOT/root/include -L$BUILD_ROOT/root/lib -std=gnu++11 -Wno-error=all -fpermissive" export OBJCXXFLAGS="$OBJCXXFLAGS -fPIC -I$BUILD_ROOT/root/include -L$BUILD_ROOT/root/lib -std=gnu++11 -Wno-error=all -fpermissive" export LDFLAGS="$LDFLAGS -fPIC -L$BUILD_ROOT/root/lib -Wno-error=all" +export STRIP="${STRIP:-strip}" if [ -z "\$OPENMP" ] && echo "\$CC" | grep -Eq gcc; then export CFLAGS="\$CFLAGS -fopenmp" @@ -110,7 +111,7 @@ eval "$BUILD_ENV" PRE_BUILD_DISTS="$PRE_BUILD_DISTS bzip2 xz unzip" DISTS=$DISTS' - bzip2 http://bzip.org/1.0.6/bzip2-1.0.6.tar.gz lib/libbz2.a + bzip2 https://github.com/nemequ/bzip2/releases/download/v1.0.6/bzip2-1.0.6.tar.gz lib/libbz2.a xz https://tukaani.org/xz/xz-5.2.3.tar.gz lib/liblzma.a unzip https://downloads.sourceforge.net/project/infozip/UnZip%206.x%20%28latest%29/UnZip%206.0/unzip60.tar.gz bin/unzip zip https://downloads.sourceforge.net/project/infozip/Zip%203.x%20%28latest%29/3.0/zip30.tar.gz bin/zip @@ -151,6 +152,7 @@ DISTS=$DISTS' libjpeg-turbo https://github.com/libjpeg-turbo/libjpeg-turbo/archive/1.5.2.tar.gz lib/libjpeg.a libtiff http://download.osgeo.org/libtiff/tiff-4.0.9.tar.gz lib/libtiff.a # libcroco http://ftp.gnome.org/pub/gnome/sources/libcroco/0.6/libcroco-0.6.12.tar.xz lib/libcroco-0.6.a + libuuid https://downloads.sourceforge.net/project/libuuid/libuuid-1.0.3.tar.gz lib/libuuid.a freetype http://download.savannah.gnu.org/releases/freetype/freetype-2.9.1.tar.bz2 lib/libfreetype.a fontconfig https://freedesktop.org/software/fontconfig/release/fontconfig-2.13.0.tar.bz2 lib/libfontconfig.a libgd https://github.com/libgd/libgd/releases/download/gd-2.2.4/libgd-2.2.4.tar.xz lib/libgd.a @@ -176,7 +178,7 @@ DISTS=$DISTS' intltool https://launchpad.net/intltool/trunk/0.51.0/+download/intltool-0.51.0.tar.gz bin/intltoolize ninja https://github.com/ninja-build/ninja/archive/v1.8.2.tar.gz bin/ninja meson https://github.com/mesonbuild/meson/releases/download/0.44.0/meson-0.44.0.tar.gz bin/meson - glib https://github.com/GNOME/glib/archive/8213793f341e6052d04aa24bba7bcf1be3e25ed5.tar.gz lib/libglib-2.0.a + glib https://github.com/GNOME/glib/archive/2.57.2.tar.gz lib/libglib-2.0.a libgpg-error https://www.gnupg.org/ftp/gcrypt/libgpg-error/libgpg-error-1.27.tar.bz2 lib/libgpg-error.a libgcrypt https://www.gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-1.8.2.tar.bz2 lib/libgcrypt.a libsecret http://ftp.gnome.org/pub/gnome/sources/libsecret/0.18/libsecret-0.18.5.tar.xz lib/libsecret-1.a @@ -187,7 +189,7 @@ DISTS=$DISTS' harfbuzz https://www.freedesktop.org/software/harfbuzz/release/harfbuzz-1.7.5.tar.bz2 lib/libharfbuzz.a sfml https://github.com/SFML/SFML/archive/013d053277c980946bc7761a2a088f1cbb788f8c.tar.gz lib/libsfml-system-s.a shared-mime-info http://freedesktop.org/~hadess/shared-mime-info-1.9.tar.xz bin/update-mime-database - wxwidgets https://github.com/wxWidgets/wxWidgets/archive/148079c61858ad04a8faa7fa9c2e2949753f35b6.tar.gz lib/libwx_baseu-3.1*.a + wxwidgets https://github.com/wxWidgets/wxWidgets/archive/e09d11c7acf768a40adb156c5a32fffb53231432.tar.gz lib/libwx_baseu-3.1*.a graphite2 https://github.com/silnrsi/graphite/releases/download/1.3.10/graphite2-1.3.10.tgz lib/libgraphite2.a xvidcore http://downloads.xvid.org/downloads/xvidcore-1.3.4.tar.bz2 lib/libxvidcore.a fribidi https://github.com/fribidi/fribidi/releases/download/v1.0.1/fribidi-1.0.1.tar.bz2 lib/libfribidi.a @@ -1307,6 +1309,11 @@ build_dist() { shift extra_dist_args=$@ + if ! [ -n "$(table_line DISTS $current_dist)" ]; then + warn "no such dist: $current_dist" + return + fi + cd "$DISTS_DIR/$current_dist" puts "${NL}Building $current_dist${NL}${NL}" @@ -1719,11 +1726,17 @@ EOF EOF # if the relocation mode for the dist is 'aggressive', rewrite all '/usr' - # prefixes everywhere except for the shebang on the first line. + # prefixes everywhere except for the shebang on the first line and /usr/local if [ "$(dist_relocation_type "$current_dist")" = aggressive ]; then cat >>"${sed_scr}.work" < "$dest_f" rm -f "${dest_f}.work" @@ -2435,6 +2454,10 @@ die() { build_project() { puts "${NL}Building project: $CHECKOUT${NL}${NL}" + target_os=${CROSS_OS:-$os} + + dist_pre_build project + mkdir -p "$BUILD_ROOT/project" cd "$BUILD_ROOT/project" @@ -2442,15 +2465,21 @@ build_project() { echo_eval_run cmake "'$CHECKOUT'" $REQUIRED_CMAKE_ARGS -DVBAM_STATIC=ON -DENABLE_LTO=OFF $PROJECT_ARGS $CMAKE_BASE_ARGS $@ echo_run make -j$NUM_CPUS - if [ "$os" = mac ]; then + if [ "$target_os" = mac ]; then + $STRIP visualboyadvance-m.app/Contents/MacOS/visualboyadvance-m + codesign -s "Developer ID Application" --deep ./visualboyadvance-m.app || : rm -f ./visualboyadvance-m-Mac.zip zip -9r ./visualboyadvance-m-Mac.zip ./visualboyadvance-m.app - elif [ "$os" != windows ] && path_exists visualboyadvance-m; then - strip visualboyadvance-m + elif [ "$target_os" != windows ] && path_exists visualboyadvance-m; then + $STRIP visualboyadvance-m + elif [ "$target_os" = windows ] && path_exists visualboyadvance-m.exe; then + $STRIP visualboyadvance-m.exe fi + dist_post_build project + puts "${NL}Build Successful!!!${NL}${NL}Build results can be found in: $BUILD_ROOT/project${NL}${NL}" } diff --git a/tools/builder/mingw-cross.sh b/tools/builder/mingw-cross.sh index 9e064ff4..d8b251a3 100644 --- a/tools/builder/mingw-cross.sh +++ b/tools/builder/mingw-cross.sh @@ -23,12 +23,12 @@ export BUILD_ROOT="$HOME/vbam-build-mingw${target_bits}" do_not_remove_dists= host_dists=' - unzip zip cmake autoconf autoconf-archive automake m4 gsed bison flex-2.6.3 - flex c2man docbook2x libtool help2man texinfo xmlto pkgconfig nasm yasm - xorg-macros dejavu liberation urw graphviz docbook4.2 docbook4.1.2 - docbook4.3 docbook4.4 docbook4.5 docbook5.0 docbook-xsl docbook-xsl-ns - python2 python3 swig doxygen bakefile setuptools pip intltool ninja meson - shared-mime-info gperf + unzip zip cmake autoconf autoconf-archive automake getopt m4 gsed bison + flex-2.6.3 flex c2man docbook2x libtool help2man texinfo xmlto pkgconfig + nasm yasm xorg-macros dejavu liberation urw graphviz docbook4.2 + docbook4.1.2 docbook4.3 docbook4.4 docbook4.5 docbook5.0 docbook-xsl + docbook-xsl-ns python2 python3 swig doxygen bakefile setuptools pip + intltool ninja meson shared-mime-info gperf ' both_dists=' @@ -42,13 +42,14 @@ BUILD_ENV=$BUILD_ENV$(cat </dev/null || : } unset_host_env() { @@ -81,12 +102,15 @@ unset_host_env() { export CXX="$OCXX" export CC_ORIG="$OCC_ORIG" export CXX_ORIG="$OCXX_ORIG" - OCC= OCXX= OCC_ORIG= OCXX_ORIG= + export STRIP="$OSTRIP" + OCC= OCXX= OCC_ORIG= OCXX_ORIG= OSTRIP= export CFLAGS="$OCFLAGS" + export CPPFLAGS="$OCPPFLAGS" export CXXFLAGS="$OCXXFLAGS" + export OBJCXXFLAGS="$OOBJCXXFLAGS" export LDFLAGS="$OLDFLAGS" - OCFLAGS= OCXXFLAGS= OLDFLAGS= + OCFLAGS= OCPPFLAGS= OCXXFLAGS= OOBJCXXFLAGS= OLDFLAGS= REQUIRED_CONFIGURE_ARGS=$OREQUIRED_CONFIGURE_ARGS REQUIRED_CMAKE_ARGS=$OREQUIRED_CMAKE_ARGS @@ -104,6 +128,8 @@ unset_host_env() { fi done IFS=$OIFS + + unset_host_env_hook 2>/dev/null || : } # replace install artifact paths with absolute paths into host and target trees @@ -164,6 +190,17 @@ table_line_append DIST_PATCHES bzip2-target 'https://raw.githubusercontent.com/A table_line_remove DIST_MAKE_ARGS bzip2-target # done with bzip2-target +# use mingw version of libuuid + +if [ "$os" != windows ]; then + table_line_remove DISTS libuuid-target + table_insert_after DISTS libuuid "libuuid-target https://github.com/h0tw1r3/libuuid-mingw/archive/1.0.1.tar.gz lib/libuuid_mingw.a" +else + table_line_replace DISTS libuuid "https://github.com/h0tw1r3/libuuid-mingw/archive/1.0.1.tar.gz lib/libuuid_mingw.a" +fi + +# done with libuuid + table_insert_after DISTS libiconv-target ' catgets https://downloads.sourceforge.net/project/mingw/MinGW/Extension/catgets/mingw-catgets-1.0.1/mingw-catgets-1.0.1-src.tar.gz include/langinfo.h ' @@ -223,13 +260,13 @@ table_line_append DIST_ARGS ffmpeg "--extra-ldflags='-Wl,-allow-multiple-definit table_line_append DIST_ARGS gettext "--enable-threads=windows" -table_line_replace DISTS glib 'https://download.gnome.org/sources/glib/2.54/glib-2.54.1.tar.xz lib/libglib-2.0.a' - table_line_append DIST_PATCHES glib "\ - http://src.fedoraproject.org/cgit/rpms/mingw-glib2.git/plain/0001-Use-CreateFile-on-Win32-to-make-sure-g_unlink-always.patch?id=f68d4a3ff32fb12f5d4467f4abfec6d2fb95b9fe \ - http://src.fedoraproject.org/cgit/rpms/mingw-glib2.git/plain/0002-GNetworkMonitorBase-don-t-fail-when-IPv6-support-is-.patch?id=f68d4a3ff32fb12f5d4467f4abfec6d2fb95b9fe \ - http://src.fedoraproject.org/cgit/rpms/mingw-glib2.git/plain/glib-include-time-h-for-localtime_r.patch?id=f68d4a3ff32fb12f5d4467f4abfec6d2fb95b9fe \ - http://src.fedoraproject.org/cgit/rpms/mingw-glib2.git/plain/glib-prefer-constructors-over-DllMain.patch?id=f68d4a3ff32fb12f5d4467f4abfec6d2fb95b9fe \ + https://src.fedoraproject.org/rpms/mingw-glib2/raw/master/f/0001-Use-CreateFile-on-Win32-to-make-sure-g_unlink-always.patch \ + https://src.fedoraproject.org/rpms/mingw-glib2/raw/master/f/glib-formaterror.patch \ + https://src.fedoraproject.org/rpms/mingw-glib2/raw/master/f/glib-include-time-h-for-localtime_r.patch \ + https://src.fedoraproject.org/rpms/mingw-glib2/raw/master/f/glib-ipmreqsource.patch \ + https://src.fedoraproject.org/rpms/mingw-glib2/raw/master/f/glib-prefer-constructors-over-DllMain.patch \ + https://gist.githubusercontent.com/rkitover/2edaf9583fb3068bb14016571e6f7d01/raw/ece80116d5618f372464f02392a9bcab670ce6c1/glib-mingw-no-strerror_s.patch \ " table_line_append DIST_PATCHES graphite2 "\ diff --git a/tools/win/mac-cross-builder b/tools/win/mac-cross-builder new file mode 100755 index 00000000..af049d85 --- /dev/null +++ b/tools/win/mac-cross-builder @@ -0,0 +1,40 @@ +#!/usr/local/bin/bash + +set -e + +TAR=tar + +. "${0%/*}/../builder/mingw-cross.sh" + +set_host_env_hook() { + export COMMAND_MODE=unix2003 + export CC='ccache clang' + export CXX='ccache clang++' + export CC_ORIG=clang + export CXX_ORIG=clang++ + export CPPFLAGS="-I$BUILD_ROOT/root/include -DICONV_CONST=" + export CFLAGS="-fPIC -I$BUILD_ROOT/root/include -L$BUILD_ROOT/root/lib -Wno-error=all -framework Carbon -framework Foundation -framework CoreServices -Wno-unused-command-line-argument -DICONV_CONST= -Wl,-no_compact_unwind" + export CXXFLAGS="-fPIC -I$BUILD_ROOT/root/include -L$BUILD_ROOT/root/lib -std=gnu++11 -Wno-error=all -fpermissive -stdlib=libc++ -framework Carbon -framework Foundation -framework CoreServices -Wno-unused-command-line-argument -DICONV_CONST= -Wl,-no_compact_unwind" + export OBJCXXFLAGS="-fPIC -I$BUILD_ROOT/root/include -L$BUILD_ROOT/root/lib -std=gnu++11 -Wno-error=all -fpermissive -stdlib=libc++ -framework Carbon -framework Foundation -framework CoreServices -Wno-unused-command-line-argument -DICONV_CONST= -Wl,-no_compact_unwind" + export LDFLAGS="-fPIC -L$BUILD_ROOT/root/lib -Wno-error=all -framework Carbon -framework Foundation -framework CoreServices -Wno-unused-command-line-argument -Wl,-no_compact_unwind" +} + +unset_host_env_hook() { + unset COMMAND_MODE +} + +table_line_remove DISTS flex +table_line_remove DISTS libsecret + +# issues with perl modules linked to our libs and brew perl +table_line_remove DISTS shared-mime-info + +# -Wl,-no_compact_unwind must be passed in LDFLAGS to openssl +table_line_append DIST_MAKE_ARGS openssl "LDFLAGS=\"\$LDFLAGS\"" + +table_line_replace DIST_CONFIGURE_OVERRIDES openssl './Configure darwin64-x86_64-cc no-shared --prefix=/usr --openssldir=/etc/ssl' + +# m4 crashes on 10.13 +table_line_append DIST_PATCHES m4 '-p0 https://raw.githubusercontent.com/macports/macports-ports/edf0ee1e2cf/devel/m4/files/secure_snprintf.patch' + +builder "$@"