From bd46edb0349ef2e8d17b35e3f4597fbea82c9ee4 Mon Sep 17 00:00:00 2001 From: dkimitsa Date: Wed, 13 Dec 2017 16:20:37 +0200 Subject: [PATCH] scripts to build toolchain added --- README.md | 16 ++ build.sh | 121 ++++++++++++++++ file/CMakeLists.txt | 73 ++++++++++ file/build.sh | 110 ++++++++++++++ file/patches/01-gnurx-to-pcre2.patch | 48 ++++++ file/patches/apply-patches | 6 + ld64/CMakeLists.txt | 137 ++++++++++++++++++ ld64/build.sh | 105 ++++++++++++++ .../patches-cctool/01-dylib-in-exe-path.patch | 24 +++ ld64/patches-cctool/apply-patches | 6 + ld64/patches-tapi/01-crossbuild.patch | 63 ++++++++ ld64/patches-tapi/apply-patches | 6 + libmd/CMakeLists.txt | 30 ++++ libmd/build.sh | 114 +++++++++++++++ llvm-dsym/CMakeLists.txt | 85 +++++++++++ llvm-dsym/build.sh | 108 ++++++++++++++ llvm-dsym/host_linux.cmake | 3 + llvm-dsym/patches/01-lto-to-static.patch | 12 ++ llvm-dsym/patches/apply-patches | 6 + llvm/CMakeLists.txt | 30 ++++ llvm/build.sh | 114 +++++++++++++++ seal.sh | 92 ++++++++++++ version | 1 + xcbuild/CMakeLists.txt | 135 +++++++++++++++++ xcbuild/build.sh | 99 +++++++++++++ xcbuild/patches/01-static-and-linux.patch | 40 +++++ xcbuild/patches/02-win32-mmap-fix.patch | 33 +++++ .../patches/03-win32-windows7-crash-fix.patch | 25 ++++ xcbuild/patches/apply-patches | 6 + xib2nib/CMakeLists.txt | 90 ++++++++++++ xib2nib/build.sh | 99 +++++++++++++ 31 files changed, 1837 insertions(+) create mode 100644 README.md create mode 100755 build.sh create mode 100644 file/CMakeLists.txt create mode 100755 file/build.sh create mode 100644 file/patches/01-gnurx-to-pcre2.patch create mode 100755 file/patches/apply-patches create mode 100644 ld64/CMakeLists.txt create mode 100755 ld64/build.sh create mode 100644 ld64/patches-cctool/01-dylib-in-exe-path.patch create mode 100755 ld64/patches-cctool/apply-patches create mode 100644 ld64/patches-tapi/01-crossbuild.patch create mode 100755 ld64/patches-tapi/apply-patches create mode 100644 libmd/CMakeLists.txt create mode 100755 libmd/build.sh create mode 100644 llvm-dsym/CMakeLists.txt create mode 100755 llvm-dsym/build.sh create mode 100644 llvm-dsym/host_linux.cmake create mode 100644 llvm-dsym/patches/01-lto-to-static.patch create mode 100755 llvm-dsym/patches/apply-patches create mode 100644 llvm/CMakeLists.txt create mode 100755 llvm/build.sh create mode 100755 seal.sh create mode 100644 version create mode 100644 xcbuild/CMakeLists.txt create mode 100755 xcbuild/build.sh create mode 100644 xcbuild/patches/01-static-and-linux.patch create mode 100644 xcbuild/patches/02-win32-mmap-fix.patch create mode 100644 xcbuild/patches/03-win32-windows7-crash-fix.patch create mode 100755 xcbuild/patches/apply-patches create mode 100644 xib2nib/CMakeLists.txt create mode 100755 xib2nib/build.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..a0a7c75 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# RoboVM ToolChain + +This repo contains builds scripts used to compile/crosscompile toolchain utilities used to enable RoboVM compilation on Windows/Linux +RoboVM branch for Windows/Linux is [here](https://github.com/dkimitsa/robovm/tree/linuxwindows) + +## Build +To build there is build.sh script that will build all tools for all platrforms available. +See options (run ./build --helps) to limit/customize build +After binaries are built they can be packed into archives with ./seal.sh + +## Host system +Toolchain was successfuly compiled in ArchLinux 2017.11.01 +Tools were used: GCC 7.2.0, mingw 7.2.0 + +## License +Scripts itself are GPL2 but binaries that are produced are covered by corresponding Project's license diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..ca4602c --- /dev/null +++ b/build.sh @@ -0,0 +1,121 @@ +#!/bin/bash +set -e + +SELF=$(basename $0) +BASE=$(cd $(dirname $0); pwd -P) +SUPORTED_TARGETS=("macosx-x86_64" "linux-x86_64" "linux-x86" "windows-x86_64" "windows-x86") +DEFAULT_TARGETS=("linux-x86_64" "linux-x86" "windows-x86_64" "windows-x86") +SUPORTED_TOOLS=("llvm" "libmd" "ld64" "llvm-dsym" "xcbuild" "file" "xib2nib" "deps") + + +function usage { + cat </ Sets custom intstall path, and will be replaced with proper values + [target] target to build +EOF + exit $1 +} + +function arrayContainsElement () { + local e match="$1" + shift + for e; do [[ "$e" == "$match" ]] && return 0; done + return 1 +} + +TARGETS=() +SKIPPED_TARGETS=() + +for arg in "$@" +do + case $arg in + '--clean') CLEAN=1 ;; + '--postclean') POSTCLEAN=1 ;; + '--install='* ) + CMAKE_INSTALL_DIR="-DINSTALL_DIR=${arg#*=}" + ;; + '--help') + usage 0 + ;; + *) + if arrayContainsElement "$arg" "${SUPORTED_TARGETS[@]}"; then + if arrayContainsElement "$arg" "${OMIT_TARGETS[@]}"; then + echo "Skipping $arg" + SKIPPED_TARGETS+=("$arg") + else + TARGETS+=("$arg") + fi + else + echo "Unrecognized option or syntax error in option '$arg'" + usage 1 + fi + ;; + esac +done + +if [ ${#TARGETS[@]} -eq 0 ]; then + if [ ${#SKIPPED_TARGETS[@]} -ne 0 ]; then + exit 0 + fi + echo "No target specified !" + usage 1 +fi + +mkdir -p "$BASE/target.${SUFFIX}/build" + +for T in ${TARGETS[@]}; do + OS=${T%%-*} + ARCH=${T#*-} + BUILD_TYPE=Release + MAKE=make + case "$T" in + "windows-x86_64") + CMAKE_PARAMS="-DMINGW_VARIANT=x86_64-w64-mingw32" + ;; + "windows-x86") + CMAKE_PARAMS="-DMINGW_VARIANT=i686-w64-mingw32" + ;; + esac + + echo "Building target $T with params: $CMAKE_PARAMS $CMAKE_INSTALL_DIR" + # clean before build + if [ "$CLEAN" = '1' ]; then + rm -rf "$BASE/target.${SUFFIX}/build/$T" + fi + mkdir -p "$BASE/target.${SUFFIX}/build/$T" + if [ -z "$CMAKE_INSTALL_DIR" ]; then + # there is no override in install location, so just + rm -rf "$BASE/binaries/$OS/$ARCH" + fi + bash -c "cd '$BASE/target.${SUFFIX}/build/$T'; cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DOS=$OS -DARCH=$ARCH $CMAKE_PARAMS $CMAKE_INSTALL_DIR '$BASE'; $MAKE robovm-unix-file" + R=$? + if [[ $R != 0 ]]; then + echo "$T build failed" + exit $R + fi + # clean after build + if [ "$POSTCLEAN" = '1' ]; then + rm -rf "$BASE/target.${SUFFIX}/build/$T" + fi +done + diff --git a/file/patches/01-gnurx-to-pcre2.patch b/file/patches/01-gnurx-to-pcre2.patch new file mode 100644 index 0000000..84c8948 --- /dev/null +++ b/file/patches/01-gnurx-to-pcre2.patch @@ -0,0 +1,48 @@ +diff -ur a/configure.ac b/configure.ac +--- a/configure.ac 2017-09-02 11:54:09.000000000 +0300 ++++ b/configure.ac 2017-11-21 14:21:29.760641012 +0200 +@@ -159,7 +159,7 @@ + AC_CHECK_LIB(z, gzopen) + fi + if test "$MINGW" = 1; then +- AC_CHECK_LIB(gnurx,regexec,,AC_MSG_ERROR([libgnurx is required to build file(1) with MinGW])) ++ AC_CHECK_LIB([pcre2-8], [pcre2_config_8]) + fi + + dnl See if we are cross-compiling +diff -ur a/src/file.h b/src/file.h +--- a/src/file.h 2017-09-02 11:54:09.000000000 +0300 ++++ b/src/file.h 2017-11-21 14:21:51.523974346 +0200 +@@ -63,7 +63,7 @@ + #ifdef HAVE_INTTYPES_H + #include + #endif +-#include ++#include + #include + #include + #ifndef WIN32 +diff -ur a/src/Makefile.am b/src/Makefile.am +--- a/src/Makefile.am 2017-09-02 11:54:09.000000000 +0300 ++++ b/src/Makefile.am 2017-11-21 14:22:12.487307679 +0200 +@@ -13,7 +13,7 @@ + file_opts.h elfclass.h mygetopt.h cdf.c cdf_time.c readcdf.c cdf.h + libmagic_la_LDFLAGS = -no-undefined -version-info 1:0:0 + if MINGW +-MINGWLIBS = -lgnurx -lshlwapi ++MINGWLIBS = -lpcre2-8 -lpcre2-posix -lshlwapi + else + MINGWLIBS = + endif +diff -ur a/magic/Makefile.am b/magic/Makefile.am +--- a/magic/Makefile.am 2017-09-02 11:54:09.000000000 +0300 ++++ b/magic/Makefile.am 2017-11-21 14:42:31.667594346 +0200 +@@ -301,7 +301,7 @@ + # FIXME: Build file natively as well so that it can be used to compile + # the target's magic file; for now we bail if the local version does not match + if IS_CROSS_COMPILE +-FILE_COMPILE = file${EXEEXT} ++FILE_COMPILE = file + FILE_COMPILE_DEP = + else + FILE_COMPILE = $(top_builddir)/src/file${EXEEXT} diff --git a/file/patches/apply-patches b/file/patches/apply-patches new file mode 100755 index 0000000..6257f3f --- /dev/null +++ b/file/patches/apply-patches @@ -0,0 +1,6 @@ +#!/bin/bash + +BASE=$(cd $(dirname $0); pwd -P) +ls "$BASE"/*.patch | sort | while read p; do + patch -p1 -t -N < $p +done diff --git a/ld64/CMakeLists.txt b/ld64/CMakeLists.txt new file mode 100644 index 0000000..a1f1745 --- /dev/null +++ b/ld64/CMakeLists.txt @@ -0,0 +1,137 @@ +cmake_minimum_required(VERSION 2.8) +include(ExternalProject) + +# Parameters to be specified from command line +# OS name +# INSTALL_DIR if required to override + +if(NOT DEFINED OS) + message(FATAL_ERROR "Please specify an os (macosx, linux, windows), e.g. -DOS=linux") +elseif(OS STREQUAL "linux") + set(LINUX YES) + set(DLIB_SUFFIX ".so") +elseif(OS STREQUAL "macosx") + set(MACOSX YES) + set(DLIB_SUFFIX ".dylib") +elseif(OS STREQUAL "windows") + set(WINDOWS YES) + set(DLIB_SUFFIX ".dll") + set(EXE_SUFFIX ".exe") +else() + message(FATAL_ERROR "Not supported OS ${OS}" ) +endif() + +if(NOT DEFINED ARCH) + set(ARCH "x86_64") + set(X86_64 YES) +elseif (ARCH STREQUAL "x86") + set(X86 YES) +elseif (ARCH STREQUAL "x86_64") + set(X86_64 YES) +else() + message(FATAL_ERROR "Not supported ARCH ${ARCH}") +endif() + +if (WINDOWS) + if(NOT DEFINED MINGW_VARIANT) + message(FATAL_ERROR "Please setup MINGW_VARIANT, e.g. -DMINGW_VARIANT=x86_64-w64-mingw32 variable") + endif() + + # for libtapi target + if (ARCH STREQUAL "x86") + set(TENTATIVE_LIBTAPI_TARGET "TARGET=MINGW32") + else() + set(TENTATIVE_LIBTAPI_TARGET "TARGET=MINGW64") + endif() + + # for ld + set(TENTATIVE_CROSS_COMPILE_HOST "--host=${MINGW_VARIANT}") +elseif(LINUX) + if (ARCH STREQUAL "x86") + set(TENTATIVE_LIBTAPI_TARGET "TARGET=Linux32") + set(TENTATIVE_CROSS_COMPILE_HOST "--build=i686-linux-gnu \"CFLAGS=-m32\" \"CXXFLAGS=-m32\" \"OBJCFLAGS=-m32\" \"LDFLAGS=-m32\"") + endif() +endif() + +project(robovm-ld64) + +message (STATUS "OS=${OS}") +message (STATUS "ARCH=${ARCH}") + +set(EXTPREFIX "${CMAKE_BINARY_DIR}/ext") + +# allow to override repository for quiker checkouts on local builds +if(DEFINED ENV{ROBOVM_TAPI_GIT_PATH}) + set(TAPI_GIT_PATH "$ENV{ROBOVM_TAPI_GIT_PATH}") + message (STATUS "Using custom tapi.git @ ${TAPI_GIT_PATH}") +else() + set(TAPI_GIT_PATH https://github.com/tpoechtrager/apple-libtapi.git) +endif() +ExternalProject_Add(exttapi + GIT_REPOSITORY ${TAPI_GIT_PATH} + GIT_TAG 1.30.0 + UPDATE_COMMAND "" + CONFIGURE_COMMAND "" + PATCH_COMMAND bash -c "${CMAKE_SOURCE_DIR}/patches-tapi/apply-patches" + BUILD_COMMAND bash -c "INSTALLPREFIX=${EXTPREFIX} ${TENTATIVE_LIBTAPI_TARGET} ./build.sh" + INSTALL_COMMAND bash -c "./install.sh" + BUILD_IN_SOURCE 1 +) + + +# allow to override repository for quiker checkouts on local builds +if(DEFINED ENV{ROBOVM_CCTOOLS_GIT_PATH}) + set(CCTOOLS_GIT_PATH "$ENV{ROBOVM_CCTOOLS_GIT_PATH}") + message (STATUS "Using custom cctools.git @ ${CCTOOLS_GIT_PATH}") +else() + set(CCTOOLS_GIT_PATH https://github.com/dkimitsa/cctools-port.git) +endif() +ExternalProject_Add(extcctools + DEPENDS exttapi + GIT_REPOSITORY ${CCTOOLS_GIT_PATH} + GIT_TAG mingw + UPDATE_COMMAND "" + PATCH_COMMAND bash -c "${CMAKE_SOURCE_DIR}/patches-cctool/apply-patches" + CONFIGURE_COMMAND bash -c "cd cctools && ./configure --prefix=${EXTPREFIX} --with-libtapi=${EXTPREFIX} ${TENTATIVE_CROSS_COMPILE_HOST} --target=i386-apple-darwin11 --target=x86_64-apple-darwin11 --target=arm-apple-darwin11 " + BUILD_COMMAND bash -c "cd cctools && make" + INSTALL_COMMAND bash -c "cd cctools && make install" + BUILD_IN_SOURCE 1 +) + +add_custom_target(robovm-ld64) +add_dependencies(robovm-ld64 extcctools) + +if (DEFINED INSTALL_DIR) + # replace template with values + string(REPLACE "_OS_" "${OS}" INSTALL_DIR ${INSTALL_DIR}) + string(REPLACE "_ARCH_" "${ARCH}" INSTALL_DIR ${INSTALL_DIR}) + message (STATUS "Custom install dir=${INSTALL_DIR}") + +if (WINDOWS) + add_custom_command(TARGET robovm-ld64 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy + ${EXTPREFIX}/bin/tapi${DLIB_SUFFIX} + ${INSTALL_DIR}) +else(WINDOWS) + add_custom_command(TARGET robovm-ld64 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy + ${EXTPREFIX}/lib/libtapi${DLIB_SUFFIX} + ${INSTALL_DIR}) +endif() + add_custom_command(TARGET robovm-ld64 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy + ${EXTPREFIX}/bin/arm-apple-darwin11-ld${EXE_SUFFIX} + ${INSTALL_DIR}) + add_custom_command(TARGET robovm-ld64 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy + ${EXTPREFIX}/bin/arm-apple-darwin11-nm${EXE_SUFFIX} + ${INSTALL_DIR}) + add_custom_command(TARGET robovm-ld64 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy + ${EXTPREFIX}/bin/arm-apple-darwin11-lipo${EXE_SUFFIX} + ${INSTALL_DIR}) + add_custom_command(TARGET robovm-ld64 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy + ${EXTPREFIX}/bin/arm-apple-darwin11-strip${EXE_SUFFIX} + ${INSTALL_DIR}) + add_custom_command(TARGET robovm-ld64 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy + ${EXTPREFIX}/bin/arm-apple-darwin11-otool${EXE_SUFFIX} + ${INSTALL_DIR}) + add_custom_command(TARGET robovm-ld64 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy + ${EXTPREFIX}/bin/arm-apple-darwin11-codesign_allocate${EXE_SUFFIX} + ${INSTALL_DIR}) +endif(DEFINED INSTALL_DIR) diff --git a/ld64/build.sh b/ld64/build.sh new file mode 100755 index 0000000..807b861 --- /dev/null +++ b/ld64/build.sh @@ -0,0 +1,105 @@ +#!/bin/bash + +SELF=$(basename $0) +BASE=$(cd $(dirname $0); pwd -P) +SUPORTED_TARGETS=("macosx-x86_64" "linux-x86_64" "linux-x86" "windows-x86_64" "windows-x86") +CLEAN=0 +POSTCLEAN=0 +WORKERS=1 +SUFFIX=cctool-ld64 +CMAKE_INSTALL_DIR= + +function usage { + cat </ Sets custom intstall path, and will be replaced with proper values + [target] target to build +EOF + exit $1 +} + +function arrayContainsElement () { + local e match="$1" + shift + for e; do [[ "$e" == "$match" ]] && return 0; done + return 1 +} + +TARGETS=() + +for arg in "$@" +do + case $arg in + '--clean') CLEAN=1 ;; + '--postclean') POSTCLEAN=1 ;; + '--install='* ) + CMAKE_INSTALL_DIR="-DINSTALL_DIR=${arg#*=}" + ;; + '--help') + usage 0 + ;; + *) + if arrayContainsElement "$arg" "${SUPORTED_TARGETS[@]}"; then + TARGETS+=("$arg") + else + echo "Unrecognized option or syntax error in option '$arg'" + usage 1 + fi + ;; + esac +done + +if [ ${#TARGETS[@]} -eq 0 ]; then + echo "No target specified !" + usage 1 +fi + +# check for java +if [[ -z "${JAVA_HOME}" ]]; then + echo "Error! JAVA_HOME is not set!" + exit 1 +fi + +mkdir -p "$BASE/target.${SUFFIX}/build" + +for T in ${TARGETS[@]}; do + OS=${T%%-*} + ARCH=${T#*-} + BUILD_TYPE=Release + MAKE=make + case "$T" in + "macosx-x86_64") + # building with xcode only ! + MAKE=`xcrun -f make` + CMAKE_PARAMS="-DCMAKE_C_COMPILER=`xcrun -f clang` -DCMAKE_CXX_COMPILER=`xcrun -f clang++` DCMAKE_MAKE_PROGRAM=$MAKE -DCMAKE_AR=`xcrun -f ar`" + ;; + "linux-x86_64" | "linux-x86") + # nothing to be specified, assuming GCC and friends shall be accessible from box + CMAKE_PARAMS= + ;; + "windows-x86_64") + CMAKE_PARAMS="-DMINGW_VARIANT=x86_64-w64-mingw32" + ;; + "windows-x86") + CMAKE_PARAMS="-DMINGW_VARIANT=i686-w64-mingw32" + ;; + esac + + echo "Building target $T with params: $CMAKE_PARAMS $CMAKE_INSTALL_DIR" + # clean before build + if [ "$CLEAN" = '1' ]; then + rm -rf "$BASE/target.${SUFFIX}/build/$T" + fi + mkdir -p "$BASE/target.${SUFFIX}/build/$T" + if [ -z "$CMAKE_INSTALL_DIR" ]; then + # there is no override in install location, so just + rm -rf "$BASE/binaries/$OS/$ARCH" + fi + bash -c "cd '$BASE/target.${SUFFIX}/build/$T'; cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DOS=$OS -DARCH=$ARCH $CMAKE_PARAMS $CMAKE_INSTALL_DIR '$BASE'; $MAKE robovm-libmd" + R=$? + if [[ $R != 0 ]]; then + echo "$T build failed" + exit $R + fi + # clean after build + if [ "$POSTCLEAN" = '1' ]; then + rm -rf "$BASE/target.${SUFFIX}/build/$T" + fi +done + diff --git a/llvm-dsym/CMakeLists.txt b/llvm-dsym/CMakeLists.txt new file mode 100644 index 0000000..dd94034 --- /dev/null +++ b/llvm-dsym/CMakeLists.txt @@ -0,0 +1,85 @@ +cmake_minimum_required(VERSION 2.8) +include(ExternalProject) + +# Parameters to be specified from command line +# OS name +# INSTALL_DIR if required to override + +if(NOT DEFINED OS) + message(FATAL_ERROR "Please specify an os (macosx, linux, windows), e.g. -DOS=linux") +elseif(OS STREQUAL "linux") + set(LINUX YES) + set(DLIB_SUFFIX ".so") +elseif(OS STREQUAL "macosx") + set(MACOSX YES) + set(DLIB_SUFFIX ".dylib") +elseif(OS STREQUAL "windows") + set(WINDOWS YES) + set(DLIB_SUFFIX ".dll") + set(EXE_SUFFIX ".exe") +else() + message(FATAL_ERROR "Not supported OS ${OS}" ) +endif() + +if(NOT DEFINED ARCH) + set(ARCH "x86_64") + set(X86_64 YES) +elseif (ARCH STREQUAL "x86") + set(X86 YES) +elseif (ARCH STREQUAL "x86_64") + set(X86_64 YES) +else() + message(FATAL_ERROR "Not supported ARCH ${ARCH}") +endif() + +if (WINDOWS) + if(NOT DEFINED MINGW_VARIANT) + message(FATAL_ERROR "Please setup MINGW_VARIANT, e.g. -DMINGW_VARIANT=x86_64-w64-mingw32 variable") + endif() + + # the name of the target operating system + SET(CMAKE_SYSTEM_NAME Windows) + + # which compilers to use for C and C++ + SET(CMAKE_C_COMPILER ${MINGW_VARIANT}-gcc) + SET(CMAKE_CXX_COMPILER ${MINGW_VARIANT}-g++) + SET(CMAKE_RC_COMPILER ${MINGW_VARIANT}-windres) + + SET(TENTATIVE_WIN32_FLAGS "-DWIN32=true" "-DCROSS_TOOLCHAIN_FLAGS_NATIVE=-DCMAKE_TOOLCHAIN_FILE=${CMAKE_SOURCE_DIR}/host_linux.cmake") +endif() + +project(robovm-llvm-dsym) + +message (STATUS "OS=${OS}") +message (STATUS "ARCH=${ARCH}") + +set(EXTPREFIX "${CMAKE_BINARY_DIR}/ext") + +ExternalProject_Add(extllvm + URL http://releases.llvm.org/5.0.0/llvm-5.0.0.src.tar.xz + PATCH_COMMAND bash -c "${CMAKE_SOURCE_DIR}/patches/apply-patches" + CONFIGURE_COMMAND cmake -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} ${TENTATIVE_WIN32_FLAGS} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_RC_COMPILER=${CMAKE_RC_COMPILER} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} "-DCMAKE_INSTALL_PREFIX=${EXTPREFIX}" + "-DLLVM_TARGETS_TO_BUILD=ARM$X86$AArch64" + -DLLVM_ENABLE_LIBCXX=YES + -DLLVM_ENABLE_TERMINFO=OFF + ../extllvm/ + INSTALL_COMMAND "" + BUILD_COMMAND bash -c "make install/strip" +) + +add_custom_target(robovm-llvm-dsym) +add_dependencies(robovm-llvm-dsym extllvm) + +if (DEFINED INSTALL_DIR) + # replace template with values + string(REPLACE "_OS_" "${OS}" INSTALL_DIR ${INSTALL_DIR}) + string(REPLACE "_ARCH_" "${ARCH}" INSTALL_DIR ${INSTALL_DIR}) + message (STATUS "Custom install dir=${INSTALL_DIR}") + + add_custom_command(TARGET robovm-llvm-dsym POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy + ${EXTPREFIX}/bin/llvm-dsymutil${EXE_SUFFIX} + ${INSTALL_DIR}) +endif(DEFINED INSTALL_DIR) + diff --git a/llvm-dsym/build.sh b/llvm-dsym/build.sh new file mode 100755 index 0000000..4f8201b --- /dev/null +++ b/llvm-dsym/build.sh @@ -0,0 +1,108 @@ +#!/bin/bash + +SELF=$(basename $0) +BASE=$(cd $(dirname $0); pwd -P) +SUPORTED_TARGETS=("macosx-x86_64" "linux-x86_64" "linux-x86" "windows-x86_64" "windows-x86") +CLEAN=0 +POSTCLEAN=0 +WORKERS=1 +SUFFIX=llvm-dsym +CMAKE_INSTALL_DIR= + +function usage { + cat </ Sets custom intstall path, and will be replaced with proper values + [target] target to build +EOF + exit $1 +} + +function arrayContainsElement () { + local e match="$1" + shift + for e; do [[ "$e" == "$match" ]] && return 0; done + return 1 +} + +TARGETS=() + +for arg in "$@" +do + case $arg in + '--clean') CLEAN=1 ;; + '--postclean') POSTCLEAN=1 ;; + '--install='* ) + CMAKE_INSTALL_DIR="-DINSTALL_DIR=${arg#*=}" + ;; + '--help') + usage 0 + ;; + *) + if arrayContainsElement "$arg" "${SUPORTED_TARGETS[@]}"; then + TARGETS+=("$arg") + else + echo "Unrecognized option or syntax error in option '$arg'" + usage 1 + fi + ;; + esac +done + +if [ ${#TARGETS[@]} -eq 0 ]; then + echo "No target specified !" + usage 1 +fi + +mkdir -p "$BASE/target.${SUFFIX}/build" + +for T in ${TARGETS[@]}; do + OS=${T%%-*} + ARCH=${T#*-} + BUILD_TYPE=Release + MAKE=make + case "$T" in + "macosx-x86_64") + # building with xcode only ! + MAKE=`xcrun -f make` + CMAKE_PARAMS="-DCMAKE_C_COMPILER=`xcrun -f clang` -DCMAKE_CXX_COMPILER=`xcrun -f clang++` DCMAKE_MAKE_PROGRAM=$MAKE -DCMAKE_AR=`xcrun -f ar`" + ;; + "linux-x86_64" | "linux-x86") + # nothing to be specified, assuming GCC and friends shall be accessible from box + CMAKE_PARAMS= + ;; + "windows-x86_64") + CMAKE_PARAMS="-DMINGW_VARIANT=x86_64-w64-mingw32" + ;; + "windows-x86") + CMAKE_PARAMS="-DMINGW_VARIANT=i686-w64-mingw32" + ;; + esac + + echo "Building target $T with params: $CMAKE_PARAMS $CMAKE_INSTALL_DIR" + # clean before build + if [ "$CLEAN" = '1' ]; then + rm -rf "$BASE/target.${SUFFIX}/build/$T" + fi + mkdir -p "$BASE/target.${SUFFIX}/build/$T" + if [ -z "$CMAKE_INSTALL_DIR" ]; then + # there is no override in install location, so just + rm -rf "$BASE/binaries/$OS/$ARCH" + fi + bash -c "cd '$BASE/target.${SUFFIX}/build/$T'; cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DOS=$OS -DARCH=$ARCH $CMAKE_PARAMS $CMAKE_INSTALL_DIR '$BASE'; $MAKE robovm-llvm-dsym" + R=$? + if [[ $R != 0 ]]; then + echo "$T build failed" + exit $R + fi + # clean after build + if [ "$POSTCLEAN" = '1' ]; then + rm -rf "$BASE/target.${SUFFIX}/build/$T" + fi +done + diff --git a/llvm-dsym/host_linux.cmake b/llvm-dsym/host_linux.cmake new file mode 100644 index 0000000..1780ade --- /dev/null +++ b/llvm-dsym/host_linux.cmake @@ -0,0 +1,3 @@ +# when cross compiling to Windows this specifies host tools to build native part of LLVM such as tblgen +set(CMAKE_C_COMPILER gcc) +set(CMAKE_CXX_COMPILER g++) diff --git a/llvm-dsym/patches/01-lto-to-static.patch b/llvm-dsym/patches/01-lto-to-static.patch new file mode 100644 index 0000000..839104f --- /dev/null +++ b/llvm-dsym/patches/01-lto-to-static.patch @@ -0,0 +1,12 @@ +diff -ruN a/tools/lto/CMakeLists.txt b/tools/lto/CMakeLists.txt +--- a/tools/lto/CMakeLists.txt 2016-11-19 01:03:51.000000000 +0200 ++++ b/tools/lto/CMakeLists.txt 2017-11-23 12:23:03.000000000 +0200 +@@ -16,7 +16,7 @@ + + set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/lto.exports) + +-add_llvm_library(LTO SHARED ${SOURCES} DEPENDS intrinsics_gen) ++add_llvm_library(LTO ${SOURCES} DEPENDS intrinsics_gen) + + install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/lto.h + DESTINATION include/llvm-c diff --git a/llvm-dsym/patches/apply-patches b/llvm-dsym/patches/apply-patches new file mode 100755 index 0000000..6257f3f --- /dev/null +++ b/llvm-dsym/patches/apply-patches @@ -0,0 +1,6 @@ +#!/bin/bash + +BASE=$(cd $(dirname $0); pwd -P) +ls "$BASE"/*.patch | sort | while read p; do + patch -p1 -t -N < $p +done diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt new file mode 100644 index 0000000..4131e11 --- /dev/null +++ b/llvm/CMakeLists.txt @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 2.9) +include(ExternalProject) + +project(robovm-llvm) + +if(DEFINED OS) + set(OS_PARAM "-DOS=${OS}") +endif() + +if(DEFINED ARCH) + set(ARCH_PARAM "-DARCH=${ARCH}") +endif() + +if(DEFINED MINGW_VARIANT) + set(MINGW_PARAM "-DMINGW_VARIANT=${MINGW_VARIANT}") +endif() + +if(DEFINED INSTALL_DIR) + set(INSTDIR_PARAM "-DINSTALL_DIR=${INSTALL_DIR}") +endif() + +ExternalProject_Add(extllvm + SVN_REPOSITORY https://github.com/dkimitsa/robovm/branches/linuxwindows/compiler/llvm + UPDATE_COMMAND "" + CONFIGURE_COMMAND cmake ${OS_PARAM} ${ARCH_PARAM} ${MINGW_PARAM} ${INSTDIR_PARAM} + BUILD_IN_SOURCE 1 +) + +add_custom_target(robovm-llvm) +add_dependencies(robovm-llvm extllvm) diff --git a/llvm/build.sh b/llvm/build.sh new file mode 100755 index 0000000..70b168b --- /dev/null +++ b/llvm/build.sh @@ -0,0 +1,114 @@ +#!/bin/bash + +SELF=$(basename $0) +BASE=$(cd $(dirname $0); pwd -P) +SUPORTED_TARGETS=("macosx-x86_64" "linux-x86_64" "linux-x86" "windows-x86_64" "windows-x86") +CLEAN=0 +POSTCLEAN=0 +WORKERS=1 +SUFFIX=llvm +CMAKE_INSTALL_DIR= + +function usage { + cat </ Sets custom intstall path, and will be replaced with proper values + [target] target to build +EOF + exit $1 +} + +function arrayContainsElement () { + local e match="$1" + shift + for e; do [[ "$e" == "$match" ]] && return 0; done + return 1 +} + +TARGETS=() + +for arg in "$@" +do + case $arg in + '--clean') CLEAN=1 ;; + '--postclean') POSTCLEAN=1 ;; + '--install='* ) + CMAKE_INSTALL_DIR="-DINSTALL_DIR=${arg#*=}" + ;; + '--help') + usage 0 + ;; + *) + if arrayContainsElement "$arg" "${SUPORTED_TARGETS[@]}"; then + TARGETS+=("$arg") + else + echo "Unrecognized option or syntax error in option '$arg'" + usage 1 + fi + ;; + esac +done + +if [ ${#TARGETS[@]} -eq 0 ]; then + echo "No target specified !" + usage 1 +fi + +# check for java +if [[ -z "${JAVA_HOME}" ]]; then + echo "Error! JAVA_HOME is not set!" + exit 1 +fi + +mkdir -p "$BASE/target.${SUFFIX}/build" + +for T in ${TARGETS[@]}; do + OS=${T%%-*} + ARCH=${T#*-} + BUILD_TYPE=Release + MAKE=make + case "$T" in + "macosx-x86_64") + # building with xcode only ! + MAKE=`xcrun -f make` + CMAKE_PARAMS="-DCMAKE_C_COMPILER=`xcrun -f clang` -DCMAKE_CXX_COMPILER=`xcrun -f clang++` DCMAKE_MAKE_PROGRAM=$MAKE -DCMAKE_AR=`xcrun -f ar`" + ;; + "linux-x86_64" | "linux-x86") + # nothing to be specified, assuming GCC and friends shall be accessible from box + CMAKE_PARAMS= + ;; + "windows-x86_64") + CMAKE_PARAMS="-DMINGW_VARIANT=x86_64-w64-mingw32" + ;; + "windows-x86") + CMAKE_PARAMS="-DMINGW_VARIANT=i686-w64-mingw32" + ;; + esac + + echo "Building target $T with params: $CMAKE_PARAMS $CMAKE_INSTALL_DIR" + # clean before build + if [ "$CLEAN" = '1' ]; then + rm -rf "$BASE/target.${SUFFIX}/build/$T" + fi + mkdir -p "$BASE/target.${SUFFIX}/build/$T" + if [ -z "$CMAKE_INSTALL_DIR" ]; then + # there is no override in install location, so just + rm -rf "$BASE/binaries/$OS/$ARCH" + fi + bash -c "cd '$BASE/target.${SUFFIX}/build/$T'; cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DOS=$OS -DARCH=$ARCH $CMAKE_PARAMS $CMAKE_INSTALL_DIR '$BASE'; $MAKE robovm-llvm" + R=$? + if [[ $R != 0 ]]; then + echo "$T build failed" + exit $R + fi + # clean after build + if [ "$POSTCLEAN" = '1' ]; then + rm -rf "$BASE/target.${SUFFIX}/build/$T" + fi +done + diff --git a/seal.sh b/seal.sh new file mode 100755 index 0000000..35ccd2b --- /dev/null +++ b/seal.sh @@ -0,0 +1,92 @@ +#!/bin/bash +set -e + +SELF=$(basename $0) +BASE=$(cd $(dirname $0); pwd -P) +SUPORTED_TARGETS=("macosxlinux-x86_64" "linux-x86_64" "linux-x86" "windows-x86_64" "windows-x86") +DEFAULT_TARGETS=("linux-x86_64" "linux-x86" "windows-x86_64" "windows-x86") +ZIP_TARGETS=("windows-x86_64" "windows-x86") + +function usage { + cat < "${BASE}/bin/${T}/manifest" + + # seal all files + for f in ${BASE}/bin/${T}/*; do + name=`basename $f` + if [[ "$name" == "manifest" ]]; then + continue + fi + if [ -x "$(command -v md5sum)" ]; then + md5sum=($(md5sum $f)) + else + md5sum=`md5 -q $f` + fi + echo "$name=$md5sum" >> "${BASE}/bin/${T}/manifest" + done + + #pack + if arrayContainsElement "$T" "${ZIP_TARGETS[@]}"; then + cd "${BASE}/bin/" + zip -r "${BASE}/$T-${version}.zip" "${T}/" + cd - + else + tar -czf "${BASE}/$T-${version}.tar.gz" -C "${BASE}/bin/" "${T}" + fi + +done diff --git a/version b/version new file mode 100644 index 0000000..6da28dd --- /dev/null +++ b/version @@ -0,0 +1 @@ +0.1.1 \ No newline at end of file diff --git a/xcbuild/CMakeLists.txt b/xcbuild/CMakeLists.txt new file mode 100644 index 0000000..f72d948 --- /dev/null +++ b/xcbuild/CMakeLists.txt @@ -0,0 +1,135 @@ +cmake_minimum_required(VERSION 2.9) +include(ExternalProject) + +# Parameters to be specified from command line +# OS name +# INSTALL_DIR if required to override + +if(NOT DEFINED OS) + message(FATAL_ERROR "Please specify an os (macosx, linux, windows), e.g. -DOS=linux") +elseif(OS STREQUAL "linux") + set(LINUX YES) + set(DLIB_SUFFIX ".so") +elseif(OS STREQUAL "macosx") + set(MACOSX YES) + set(DLIB_SUFFIX ".dylib") +elseif(OS STREQUAL "windows") + set(WINDOWS YES) + set(DLIB_SUFFIX ".dll") + set(EXE_SUFFIX ".exe") +else() + message(FATAL_ERROR "Not supported OS ${OS}" ) +endif() + +if(NOT DEFINED ARCH) + set(ARCH "x86_64") + set(X86_64 YES) +elseif (ARCH STREQUAL "x86") + set(X86 YES) +elseif (ARCH STREQUAL "x86_64") + set(X86_64 YES) +else() + message(FATAL_ERROR "Not supported ARCH ${ARCH}") +endif() + +set(EXTPREFIX "${CMAKE_BINARY_DIR}/ext") + +if (WINDOWS) + if(NOT DEFINED MINGW_VARIANT) + message(FATAL_ERROR "Please setup MINGW_VARIANT, e.g. -DMINGW_VARIANT=x86_64-w64-mingw32 variable") + endif() + + # the name of the target operating system + SET(CMAKE_SYSTEM_NAME Windows) + + # which compilers to use for C and C++ + SET(CMAKE_C_COMPILER ${MINGW_VARIANT}-gcc) + SET(CMAKE_CXX_COMPILER ${MINGW_VARIANT}-g++) + SET(CMAKE_RC_COMPILER ${MINGW_VARIANT}-windres) + + SET(TENTATIVE_WIN32_ROOTS "-DCMAKE_FIND_ROOT_PATH=/usr/${MINGW_VARIANT};${EXTPREFIX}") + string(REPLACE ";" "$" TENTATIVE_WIN32_ROOTS "${TENTATIVE_WIN32_ROOTS}") + SET(TENTATIVE_WIN32_FIND_ROOT_PATH_MODE_PROGRAM "-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER") + SET(TENTATIVE_WIN32_FIND_ROOT_PATH_MODE_LIBRARY "-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY") + SET(TENTATIVE_WIN32_FIND_ROOT_PATH_MODE_INCLUDE "-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY") + SET(TENTATIVE_WIN32_ZLIB_DEP extzlib) +endif() + +project(robovm-xcbuild) + +message (STATUS "OS=${OS}") +message (STATUS "ARCH=${ARCH}") + +if (WINDOWS) + # for mingw have to build it + ExternalProject_Add(extzlib + URL http://zlib.net/zlib-1.2.11.tar.gz + CONFIGURE_COMMAND cmake -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} + "${TENTATIVE_WIN32_ROOTS}" + "${TENTATIVE_WIN32_FIND_ROOT_PATH_MODE_PROGRAM}" + "${TENTATIVE_WIN32_FIND_ROOT_PATH_MODE_LIBRARY}" + "${TENTATIVE_WIN32_FIND_ROOT_PATH_MODE_INCLUDE}" + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_RC_COMPILER=${CMAKE_RC_COMPILER} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + "-DCMAKE_INSTALL_PREFIX=${EXTPREFIX}" + ../extzlib/ + INSTALL_COMMAND make install/strip + COMMAND rm -r "${EXTPREFIX}/lib/libzlib.dll.a" + COMMAND rm -r "${EXTPREFIX}/bin/libzlib.dll" + COMMAND mv "${EXTPREFIX}/lib/libzlibstatic.a" "${EXTPREFIX}/lib/libzlib.a" + ) +endif() + +if (NOT MACOSX) + # it is not available on macos + set(TENTATIVE_WARNING_OPT "-Wno-error=maybe-uninitialized") +endif() + +# allow to override repository for quiker checkouts on local builds +if(DEFINED ENV{ROBOVM_XCBUILD_GIT_PATH}) + set(XCBUILD_GIT_PATH "$ENV{ROBOVM_XCBUILD_GIT_PATH}") + message (STATUS "Using custom libimobiledevice.git @ ${XCBUILD_GIT_PATH}") +else() + set(XCBUILD_GIT_PATH https://github.com/facebook/xcbuild.git) +endif() +ExternalProject_Add(extxcbuild + GIT_REPOSITORY ${XCBUILD_GIT_PATH} + GIT_TAG 34e535ea7dc38fd77f4927c4b9cb387643c7988e + UPDATE_COMMAND "" + PATCH_COMMAND bash -c "${CMAKE_SOURCE_DIR}/patches/apply-patches" + CONFIGURE_COMMAND cmake -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} + "${TENTATIVE_WIN32_ROOTS}" + "${TENTATIVE_WIN32_FIND_ROOT_PATH_MODE_PROGRAM}" + "${TENTATIVE_WIN32_FIND_ROOT_PATH_MODE_LIBRARY}" + "${TENTATIVE_WIN32_FIND_ROOT_PATH_MODE_INCLUDE}" + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_RC_COMPILER=${CMAKE_RC_COMPILER} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + "-DCMAKE_C_FLAGS=-Wno-error=unused-variable ${TENTATIVE_WARNING_OPT}" + "-DCMAKE_CXX_FLAGS=-Wno-error=unused-variable ${TENTATIVE_WARNING_OPT}" + "-DCMAKE_PREFIX_PATH=${EXTPREFIX}" + "-DCMAKE_INSTALL_PREFIX=${EXTPREFIX}" + ../extxcbuild/ + DEPENDS ${TENTATIVE_WIN32_ZLIB_DEP} +) + +add_custom_target(robovm-xcbuild) +add_dependencies(robovm-xcbuild extxcbuild) + + +if (DEFINED INSTALL_DIR) + # replace template with values + string(REPLACE "_OS_" "${OS}" INSTALL_DIR ${INSTALL_DIR}) + string(REPLACE "_ARCH_" "${ARCH}" INSTALL_DIR ${INSTALL_DIR}) + message (STATUS "Custom install dir=${INSTALL_DIR}") + + add_custom_command(TARGET robovm-xcbuild POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy + ${EXTPREFIX}/usr/bin/actool${EXE_SUFFIX} + ${INSTALL_DIR}) + add_custom_command(TARGET robovm-xcbuild POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy + ${EXTPREFIX}/usr/bin/plutil${EXE_SUFFIX} + ${INSTALL_DIR}) +endif(DEFINED INSTALL_DIR) diff --git a/xcbuild/build.sh b/xcbuild/build.sh new file mode 100755 index 0000000..4089f66 --- /dev/null +++ b/xcbuild/build.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +SELF=$(basename $0) +BASE=$(cd $(dirname $0); pwd -P) +SUPORTED_TARGETS=("macosx-x86_64" "linux-x86_64" "linux-x86" "windows-x86_64" "windows-x86") +CLEAN=0 +POSTCLEAN=0 +WORKERS=1 +SUFFIX=facebook-xcbuild +CMAKE_INSTALL_DIR= + +function usage { + cat < + #include + ++#ifdef minor ++#undef minor ++#endif ++#ifdef major ++#undef major ++#endif ++ + namespace xcassets { + namespace Slot { + diff --git a/xcbuild/patches/02-win32-mmap-fix.patch b/xcbuild/patches/02-win32-mmap-fix.patch new file mode 100644 index 0000000..06fac05 --- /dev/null +++ b/xcbuild/patches/02-win32-mmap-fix.patch @@ -0,0 +1,33 @@ +diff --git a/Libraries/libbom/Sources/bom_memory.c b/Libraries/libbom/Sources/bom_memory.c +index bd8ea154..f4a6afe3 100755 +--- a/Libraries/libbom/Sources/bom_memory.c ++++ b/Libraries/libbom/Sources/bom_memory.c +@@ -89,7 +89,7 @@ _bom_context_memory_mremap(struct bom_context_memory *memory, size_t size) + memory->size = size; + + context->mapping = CreateFileMapping(context->handle, NULL, (context->writeable ? PAGE_READWRITE : PAGE_READONLY), 0, size, NULL); +- assert(context->mapping != INVALID_HANDLE_VALUE); ++ assert(context->mapping); + + memory->data = (void *)MapViewOfFile(context->mapping, (context->writeable ? FILE_MAP_WRITE | FILE_MAP_READ : FILE_MAP_READ), 0, 0, 0); + assert(memory->data != NULL); +@@ -156,6 +156,10 @@ bom_context_memory_file(const char *fn, bool writeable, size_t minimum_size) + return invalid; + } + ++ // FIXME: this is a dirty workaround as CreateFileMapping on zero lengh ++ // file will cause 1006 error as specified in doc ++ if (!minimum_size) ++ minimum_size = 1; + if ((size_t)size < minimum_size) { + size = (DWORD)minimum_size; + +@@ -171,7 +175,7 @@ bom_context_memory_file(const char *fn, bool writeable, size_t minimum_size) + } + + HANDLE mapping = CreateFileMapping(handle, NULL, (writeable ? PAGE_READWRITE : PAGE_READONLY), 0, size, NULL); +- if (mapping == INVALID_HANDLE_VALUE) { ++ if (mapping == NULL) { + CloseHandle(handle); + return invalid; + } \ No newline at end of file diff --git a/xcbuild/patches/03-win32-windows7-crash-fix.patch b/xcbuild/patches/03-win32-windows7-crash-fix.patch new file mode 100644 index 0000000..645a84f --- /dev/null +++ b/xcbuild/patches/03-win32-windows7-crash-fix.patch @@ -0,0 +1,25 @@ +diff --git a/Libraries/libutil/Sources/DefaultFilesystem.cpp b/Libraries/libutil/Sources/DefaultFilesystem.cpp +index f57ace99..9b634c71 100644 +--- a/Libraries/libutil/Sources/DefaultFilesystem.cpp ++++ b/Libraries/libutil/Sources/DefaultFilesystem.cpp +@@ -504,8 +504,8 @@ read(std::vector *contents, std::string const &path, size_t offset, ext + } + + *contents = std::vector(size); +- +- if (!ReadFile(handle, contents->data(), size, nullptr, nullptr)) { ++ DWORD read; ++ if (!ReadFile(handle, contents->data(), size, &read, nullptr)) { + CloseHandle(handle); + return false; + } +@@ -570,7 +570,8 @@ write(std::vector const &contents, std::string const &path) + return false; + } + +- if (!WriteFile(handle, contents.data(), contents.size(), nullptr, nullptr)) { ++ DWORD written; ++ if (!WriteFile(handle, contents.data(), contents.size(), &written, nullptr)) { + CloseHandle(handle); + return false; + } \ No newline at end of file diff --git a/xcbuild/patches/apply-patches b/xcbuild/patches/apply-patches new file mode 100755 index 0000000..6257f3f --- /dev/null +++ b/xcbuild/patches/apply-patches @@ -0,0 +1,6 @@ +#!/bin/bash + +BASE=$(cd $(dirname $0); pwd -P) +ls "$BASE"/*.patch | sort | while read p; do + patch -p1 -t -N < $p +done diff --git a/xib2nib/CMakeLists.txt b/xib2nib/CMakeLists.txt new file mode 100644 index 0000000..4372d6b --- /dev/null +++ b/xib2nib/CMakeLists.txt @@ -0,0 +1,90 @@ +cmake_minimum_required(VERSION 2.9) +include(ExternalProject) + +# Parameters to be specified from command line +# OS name +# INSTALL_DIR if required to override + +if(NOT DEFINED OS) + message(FATAL_ERROR "Please specify an os (macosx, linux, windows), e.g. -DOS=linux") +elseif(OS STREQUAL "linux") + set(LINUX YES) + set(DLIB_SUFFIX ".so") +elseif(OS STREQUAL "macosx") + set(MACOSX YES) + set(DLIB_SUFFIX ".dylib") +elseif(OS STREQUAL "windows") + set(WINDOWS YES) + set(DLIB_SUFFIX ".dll") + set(EXE_SUFFIX ".exe") +else() + message(FATAL_ERROR "Not supported OS ${OS}" ) +endif() + +if(NOT DEFINED ARCH) + set(ARCH "x86_64") + set(X86_64 YES) +elseif (ARCH STREQUAL "x86") + set(X86 YES) +elseif (ARCH STREQUAL "x86_64") + set(X86_64 YES) +else() + message(FATAL_ERROR "Not supported ARCH ${ARCH}") +endif() + +set(EXTPREFIX "${CMAKE_BINARY_DIR}/ext") + +if (WINDOWS) + if(NOT DEFINED MINGW_VARIANT) + message(FATAL_ERROR "Please setup MINGW_VARIANT, e.g. -DMINGW_VARIANT=x86_64-w64-mingw32 variable") + endif() + + # the name of the target operating system + SET(CMAKE_SYSTEM_NAME Windows) + + # which compilers to use for C and C++ + SET(CMAKE_C_COMPILER ${MINGW_VARIANT}-gcc) + SET(CMAKE_CXX_COMPILER ${MINGW_VARIANT}-g++) + SET(CMAKE_RC_COMPILER ${MINGW_VARIANT}-windres) + + SET(TENTATIVE_WIN32_ROOTS "-DCMAKE_FIND_ROOT_PATH=/usr/${MINGW_VARIANT}") + SET(TENTATIVE_WIN32_FIND_ROOT_PATH_MODE_PROGRAM "-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER") + SET(TENTATIVE_WIN32_FIND_ROOT_PATH_MODE_LIBRARY "-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY") + SET(TENTATIVE_WIN32_FIND_ROOT_PATH_MODE_INCLUDE "-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY") +endif() + +project(robovm-xib2nib) + +message (STATUS "OS=${OS}") +message (STATUS "ARCH=${ARCH}") + +ExternalProject_Add(extxib2nib + SVN_REPOSITORY https://github.com/dkimitsa/WinObjC/branches/xib2nib/tools/vsimporter/xib2nib + UPDATE_COMMAND "" + CONFIGURE_COMMAND cmake -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} + "${TENTATIVE_WIN32_ROOTS}" + "${TENTATIVE_WIN32_FIND_ROOT_PATH_MODE_PROGRAM}" + "${TENTATIVE_WIN32_FIND_ROOT_PATH_MODE_LIBRARY}" + "${TENTATIVE_WIN32_FIND_ROOT_PATH_MODE_INCLUDE}" + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_RC_COMPILER=${CMAKE_RC_COMPILER} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + "-DCMAKE_INSTALL_PREFIX=${EXTPREFIX}" + ../extxib2nib/ +) + +add_custom_target(robovm-xib2nib) +add_dependencies(robovm-xib2nib extxib2nib) + + +if (DEFINED INSTALL_DIR) + # replace template with values + string(REPLACE "_OS_" "${OS}" INSTALL_DIR ${INSTALL_DIR}) + string(REPLACE "_ARCH_" "${ARCH}" INSTALL_DIR ${INSTALL_DIR}) + message (STATUS "Custom install dir=${INSTALL_DIR}") + + add_custom_command(TARGET robovm-xib2nib POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy + ${EXTPREFIX}/bin/xib2nib${EXE_SUFFIX} + ${INSTALL_DIR}) +endif(DEFINED INSTALL_DIR) diff --git a/xib2nib/build.sh b/xib2nib/build.sh new file mode 100755 index 0000000..6df110d --- /dev/null +++ b/xib2nib/build.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +SELF=$(basename $0) +BASE=$(cd $(dirname $0); pwd -P) +SUPORTED_TARGETS=("macosx-x86_64" "linux-x86_64" "linux-x86" "windows-x86_64" "windows-x86") +CLEAN=0 +POSTCLEAN=0 +WORKERS=1 +SUFFIX=ms-xib2nib +CMAKE_INSTALL_DIR= + +function usage { + cat <