From 66980934b2a713f890a22a1f59fcbddb561c2e83 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Sat, 24 Feb 2018 14:39:29 -0500 Subject: [PATCH] add multi-platform build system under `tools/` add some scripts to invoke the build system to build all deps for vbam and vbam itself: - `tools/linux/builder` This builds a mostly static linux binary with a few dynamic deps for xorg and wayland. Using gtk3. This will run on just about any dist. - `tools/osx/builder` Builds a static mac app targetting 10.7. - `tools/win/linux-cross-builder` Builds a static windows binary using the mingw-w64 toolchain. - `tools/win/msys2-builder` Builds a static windows binary in the MSYS2 environment, this may be suffering from a few regressions. Change some cmake code to support the build system, refactor a few things in it. --- CMakeLists.txt | 741 +++--- README.md | 10 +- cmake/FindSSP.cmake | 13 +- cmake/Toolchain-cross-MinGW-w64-i686.cmake | 4 + cmake/Toolchain-cross-MinGW-w64-x86_64.cmake | 4 + installdeps | 12 + src/wx/CMakeLists.txt | 90 +- src/wx/guiinit.cpp | 4 +- src/wx/link-static.cmake | 5 + src/wx/msys-link-static.cmake | 5 + tools/builder/core.sh | 2463 ++++++++++++++++++ tools/builder/mingw.sh | 230 ++ tools/builder/unix.sh | 170 ++ tools/linux/builder | 45 + tools/osx/builder | 599 +---- tools/unix/builder | 11 + tools/win/builder | 351 --- tools/win/linux-cross-builder | 95 + tools/win/msys2-builder | 147 ++ 19 files changed, 3709 insertions(+), 1290 deletions(-) create mode 100644 src/wx/link-static.cmake create mode 100644 src/wx/msys-link-static.cmake create mode 100644 tools/builder/core.sh create mode 100644 tools/builder/mingw.sh create mode 100644 tools/builder/unix.sh create mode 100755 tools/linux/builder create mode 100755 tools/unix/builder delete mode 100644 tools/win/builder create mode 100755 tools/win/linux-cross-builder create mode 100755 tools/win/msys2-builder diff --git a/CMakeLists.txt b/CMakeLists.txt index a324fa78..843788ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,107 +1,121 @@ -# The project's name is VBA-M it uses C and C++ code -PROJECT(VBA-M C CXX) +project(VBA-M C CXX) -cmake_minimum_required( VERSION 2.8.12 ) +cmake_minimum_required(VERSION 2.8.12) -IF(CMAKE_BUILD_TYPE STREQUAL "") - SET(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build Type" FORCE) -ENDIF() +if(NOT CMAKE_PREFIX_PATH AND (NOT ("$ENV{CMAKE_PREFIX_PATH}" STREQUAL ""))) + set(CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH}") +endif() -SET(ALL_TARGETS fex visualboyadvance-m vbamcore vbam) +if(CMAKE_BUILD_TYPE STREQUAL "") + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build Type" FORCE) +endif() + +set(ALL_TARGETS fex visualboyadvance-m vbamcore vbam) if(COMMAND cmake_policy) cmake_policy(SET CMP0003 NEW) # link to full path of libs cmake_policy(SET CMP0005 NEW) # escapes in add_definitions -endif(COMMAND cmake_policy) +endif() -SET( CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ) +set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) #Output all binaries at top level -SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}) +set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}) -option( ENABLE_SDL "Build the SDL port" OFF ) -option( ENABLE_WX "Build the wxWidgets port" ON ) -option( ENABLE_DEBUGGER "Enable the debugger" ON ) -option( ENABLE_NLS "Enable translations" ON ) +option(ENABLE_SDL "Build the SDL port" OFF) +option(ENABLE_WX "Build the wxWidgets port" ON) +option(ENABLE_DEBUGGER "Enable the debugger" ON) +option(ENABLE_NLS "Enable translations" ON) -SET(ASM_DEFAULT OFF) +option(VBAM_STATIC "Try to link all libraries statically" OFF) -IF(NOT CMAKE_SYSTEM_PROCESSOR) - IF(NOT CMAKE_TOOLCHAIN_FILE AND CMAKE_HOST_SYSTEM_PROCESSOR) - SET(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) - ELSEIF(CMAKE_TOOLCHAIN_FILE MATCHES mxe) - IF(CMAKE_TOOLCHAIN_FILE MATCHES "i[3-9]86") - SET(CMAKE_SYSTEM_PROCESSOR i686) - ELSE() - SET(CMAKE_SYSTEM_PROCESSOR x86_64) - ENDIF() - ENDIF() -ENDIF() +if(VBAM_STATIC) + set(SDL2_STATIC ON) + set(SFML_STATIC_LIBRARIES ON) + set(FFMPEG_STATIC ON) + set(SSP_STATIC ON) + set(OPENAL_STATIC ON) +endif() + +set(ASM_DEFAULT OFF) + +if(NOT CMAKE_SYSTEM_PROCESSOR) + if(NOT CMAKE_TOOLCHAIN_FILE AND CMAKE_HOST_SYSTEM_PROCESSOR) + set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) + elseif(CMAKE_TOOLCHAIN_FILE MATCHES mxe) + if(CMAKE_TOOLCHAIN_FILE MATCHES "i[3-9]86") + set(CMAKE_SYSTEM_PROCESSOR i686) + else() + set(CMAKE_SYSTEM_PROCESSOR x86_64) + endif() + endif() +endif() # turn asm on by default on 32bit x86 -IF(CMAKE_SYSTEM_PROCESSOR MATCHES "[xX]86|i[3-9]86|[aA][mM][dD]64") - IF(CMAKE_C_SIZEOF_DATA_PTR EQUAL 4) # 32 bit - SET(ASM_DEFAULT ON) - SET(X86_32 ON) - ELSE() - SET(AMD64 ON) - ENDIF() -ENDIF() +if(CMAKE_SYSTEM_PROCESSOR MATCHES "[xX]86|i[3-9]86|[aA][mM][dD]64") + if(CMAKE_C_SIZEOF_DATA_PTR EQUAL 4) # 32 bit + set(ASM_DEFAULT ON) + set(X86_32 ON) + else() + set(AMD64 ON) + endif() +endif() -OPTION(ENABLE_ASM "Enable x86 ASM related options" ${ASM_DEFAULT}) +option(ENABLE_ASM "Enable x86 ASM related options" ${ASM_DEFAULT}) # The ARM ASM core seems to be very buggy, see #98 and #54. Default to it being # OFF for the time being, until it is either fixed or replaced. -option( ENABLE_ASM_CORE "Enable x86 ASM CPU cores" OFF) +option(ENABLE_ASM_CORE "Enable x86 ASM CPU cores" OFF) -IF(ENABLE_ASM_CORE) - MESSAGE(WARNING "!!!!!! The x86 ASM cores are considered buggy and dangerous, use at your own risk. !!!!!!") -ENDIF() +if(ENABLE_ASM_CORE) + message(WARNING "!!!!!! The x86 ASM cores are considered buggy and dangerous, use at your own risk. !!!!!!") +endif() -SET(ASM_SCALERS_DEFAULT ${ENABLE_ASM}) -SET(MMX_DEFAULT ${ENABLE_ASM}) +set(ASM_SCALERS_DEFAULT ${ENABLE_ASM}) +set(MMX_DEFAULT ${ENABLE_ASM}) -option( ENABLE_ASM_SCALERS "Enable x86 ASM graphic filters" ${ASM_SCALERS_DEFAULT}) +option(ENABLE_ASM_SCALERS "Enable x86 ASM graphic filters" ${ASM_SCALERS_DEFAULT}) if(ENABLE_ASM_SCALERS) - option( ENABLE_MMX "Enable MMX" ${MMX_DEFAULT}) -endif(ENABLE_ASM_SCALERS) + option(ENABLE_MMX "Enable MMX" ${MMX_DEFAULT}) +endif() -option( ENABLE_LINK "Enable GBA linking functionality" ON ) -option( ENABLE_LIRC "Enable LIRC support" OFF ) +option(ENABLE_LINK "Enable GBA linking functionality" ON) +option(ENABLE_LIRC "Enable LIRC support" OFF) -SET(FFMPEG_DEFAULT ON) +# currently completely broken +set(FFMPEG_DEFAULT OFF) -IF(WIN32 AND NOT (MINGW AND MSYS)) - SET(FFMPEG_DEFAULT OFF) -ENDIF() +if(WIN32 AND NOT (MINGW AND MSYS)) + set(FFMPEG_DEFAULT OFF) +endif() option(ENABLE_FFMPEG "Enable ffmpeg A/V recording" ${FFMPEG_DEFAULT}) -SET(LTO_DEFAULT ON) +set(LTO_DEFAULT ON) -IF(WIN32 AND CMAKE_COMPILER_IS_GNUCXX AND AMD64) +if(WIN32 AND CMAKE_COMPILER_IS_GNUCXX AND AMD64) # lto produces buggy binaries for 64 bit win32 - SET(LTO_DEFAULT OFF) -ENDIF() + set(LTO_DEFAULT OFF) +endif() -OPTION(ENABLE_LTO "Compile with Link Time Optimization (gcc and clang only)" ${LTO_DEFAULT}) +option(ENABLE_LTO "Compile with Link Time Optimization (gcc and clang only)" ${LTO_DEFAULT}) if(MSVC) - ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS) -endif(MSVC) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) +endif() -option( ENABLE_GBA_LOGGING "Enable extended GBA logging" ON ) -if( ENABLE_GBA_LOGGING ) - ADD_DEFINITIONS (-DGBA_LOGGING ) -endif( ENABLE_GBA_LOGGING ) +option(ENABLE_GBA_LOGGING "Enable extended GBA logging" ON) +if(ENABLE_GBA_LOGGING) + add_definitions(-DGBA_LOGGING ) +endif() if(ENABLE_MMX) - ADD_DEFINITIONS (-DMMX) -endif(ENABLE_MMX) + add_definitions(-DMMX) +endif() # The SDL port can't be built without debugging support -if( NOT ENABLE_DEBUGGER AND ENABLE_SDL ) - message( SEND_ERROR "The SDL port can't be built without debugging support" ) -endif( NOT ENABLE_DEBUGGER AND ENABLE_SDL ) +if(NOT ENABLE_DEBUGGER AND ENABLE_SDL) + message(SEND_ERROR "The SDL port can't be built without debugging support") +endif() find_package(Git) if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git") @@ -124,65 +138,63 @@ endif() include_directories(${CMAKE_BINARY_DIR}) configure_file("${CMAKE_SOURCE_DIR}/src/version.h.in" "${CMAKE_BINARY_DIR}/version.h" @ONLY) -IF(CMAKE_BUILD_TYPE STREQUAL "Debug") - ADD_DEFINITIONS(-DDEBUG) -ELSE() - ADD_DEFINITIONS(-DNDEBUG) -ENDIF() +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + add_definitions(-DDEBUG) +else() + add_definitions(-DNDEBUG) +endif() # hack for ninja in msys2 -IF(WIN32 AND CMAKE_GENERATOR STREQUAL Ninja AND (NOT $ENV{MSYSTEM} STREQUAL "")) - SET(MSYS ON) -ENDIF() +if(WIN32 AND CMAKE_GENERATOR STREQUAL Ninja AND (NOT $ENV{MSYSTEM} STREQUAL "")) + set(MSYS ON) +endif() # Add support for Homebrew, MacPorts and Fink on OS X -IF(APPLE) - INCLUDE(MacPackageManagers) -ENDIF(APPLE) +if(APPLE) + include(MacPackageManagers) +endif() # We do not support amd64 asm yet -IF(AMD64 AND (ENABLE_ASM_CORE OR ENABLE_ASM_SCALERS OR ENABLE_MMX)) - MESSAGE(FATAL_ERROR "The options ASM_CORE, ASM_SCALERS and MMX are not supported on AMD64 yet.") -ENDIF() +if(AMD64 AND (ENABLE_ASM_CORE OR ENABLE_ASM_SCALERS OR ENABLE_MMX)) + message(FATAL_ERROR "The options ASM_CORE, ASM_SCALERS and MMX are not supported on AMD64 yet.") +endif() -IF(ENABLE_ASM_CORE OR ENABLE_ASM_SCALERS) - ENABLE_LANGUAGE(ASM_NASM) - SET(ASM_ENABLED ON) -ENDIF() +if(ENABLE_ASM_CORE OR ENABLE_ASM_SCALERS) + enable_language(ASM_NASM) + set(ASM_ENABLED ON) +endif() # Look for some dependencies using CMake scripts -FIND_PACKAGE(ZLIB REQUIRED) -FIND_PACKAGE(OpenGL REQUIRED) +find_package(ZLIB REQUIRED) +find_package(OpenGL REQUIRED) +find_package(PNG REQUIRED) -# TODO: make static on mac and fedora cross-compiles -FIND_PACKAGE(PNG REQUIRED) +if(EXISTS /etc/redhat-release) + set(FEDORA_HOST ON) +endif() -IF(APPLE AND NOT MACPORTS) - SET(SDL2_STATIC ON) -ENDIF() +if((APPLE AND NOT MACPORTS) OR (WIN32 AND FEDORA_HOST)) + set(SDL2_STATIC ON) +endif() -IF(EXISTS /etc/redhat-release) - SET(FEDORA_HOST ON) -ENDIF() +if(WIN32 AND SDL2_STATIC) + set(SDL2_BUILDING_LIBRARY TRUE) # try not to link SDL2main +endif() -IF(WINDOWS AND FEDORA_HOST) - SET(SDL2_STATIC ON) -ENDIF() +find_package(SDL2 REQUIRED) +add_definitions(${SDL2_DEFINITIONS}) -FIND_PACKAGE(SDL2 REQUIRED) -ADD_DEFINITIONS(${SDL2_DEFINITIONS}) - -if( ENABLE_LINK ) +if(ENABLE_LINK) # msys2 does not have static sfml libs atm # while on mxe we use static libs if(WIN32 AND ((NOT (MINGW AND MSYS)) OR CMAKE_TOOLCHAIN_FILE MATCHES mxe)) set(SFML_STATIC_LIBRARIES TRUE) endif() - FIND_PACKAGE ( SFML 2 COMPONENTS network system REQUIRED ) -endif( ENABLE_LINK ) + find_package(SFML 2 COMPONENTS network system REQUIRED) +endif() # set the standard libraries all ports use -SET(VBAMCORE_LIBS +set(VBAMCORE_LIBS vbamcore fex ${SDL2_LIBRARY} @@ -193,9 +205,9 @@ SET(VBAMCORE_LIBS ) if(ENABLE_FFMPEG) - FIND_PACKAGE(PkgConfig REQUIRED) + find_package(PkgConfig REQUIRED) - PKG_CHECK_MODULES(FFMPEG REQUIRED libavcodec libavformat libswscale libavutil) + pkg_check_modules(FFMPEG REQUIRED libavcodec libavformat libswscale libavutil) if(FFMPEG_STATIC) set(FFMPEG_LIBRARIES ${FFMPEG_STATIC_LIBRARIES}) @@ -208,97 +220,97 @@ if(ENABLE_FFMPEG) set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES}) set(FFMPEG_LDFLAGS ${FFMPEG_LDFLAGS} ${FFMPEG_OTHER_LDFLAGS}) endif() -endif(ENABLE_FFMPEG) +endif() if(NOT ENABLE_FFMPEG) - ADD_DEFINITIONS(-DNO_FFMPEG) -endif(NOT ENABLE_FFMPEG) + add_definitions(-DNO_FFMPEG) +endif() -IF( ENABLE_LIRC ) - SET( WITHLIRC 1 ) -ELSE( ENABLE_LIRC ) - SET( WITHLIRC 0 ) -ENDIF( ENABLE_LIRC ) +if(ENABLE_LIRC) + set(WITHLIRC 1) +else() + set(WITHLIRC 0) +endif() -INCLUDE(GNUInstallDirs) +include(GNUInstallDirs) # C defines -ADD_DEFINITIONS (-DHAVE_NETINET_IN_H -DHAVE_ARPA_INET_H -DHAVE_ZLIB_H -DFINAL_VERSION -DSDL -DUSE_OPENGL -DSYSCONF_INSTALL_DIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}" -DWITH_LIRC=${WITHLIRC}) -ADD_DEFINITIONS (-DPKGDATADIR="${CMAKE_INSTALL_FULL_DATADIR}/vbam" -DPACKAGE=) +add_definitions(-DHAVE_NETINET_IN_H -DHAVE_ARPA_INET_H -DHAVE_ZLIB_H -DFINAL_VERSION -DSDL -DUSE_OPENGL -DSYSCONF_INSTALL_DIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}" -DWITH_LIRC=${WITHLIRC}) +add_definitions(-DPKGDATADIR="${CMAKE_INSTALL_FULL_DATADIR}/vbam" -DPACKAGE=) -if( ENABLE_LINK ) +if(ENABLE_LINK) # IPC linking code needs sem_timedwait which can be either in librt or pthreads - FIND_LIBRARY(RT_LIB rt) - IF(RT_LIB) - SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${RT_LIB}) - SET(VBAMCORE_LIBS ${VBAMCORE_LIBS} ${RT_LIB}) - ENDIF(RT_LIB) + find_library(RT_LIB rt) + if(RT_LIB) + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${RT_LIB}) + set(VBAMCORE_LIBS ${VBAMCORE_LIBS} ${RT_LIB}) + endif() - FIND_LIBRARY(PTHREAD_LIB pthread) - IF(PTHREAD_LIB) - SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${PTHREAD_LIB}) - SET(VBAMCORE_LIBS ${VBAMCORE_LIBS} ${PTHREAD_LIB}) - ENDIF(PTHREAD_LIB) + find_library(PTHREAD_LIB pthread) + if(PTHREAD_LIB) + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${PTHREAD_LIB}) + set(VBAMCORE_LIBS ${VBAMCORE_LIBS} ${PTHREAD_LIB}) + endif() - INCLUDE(CheckFunctionExists) - CHECK_FUNCTION_EXISTS(sem_timedwait SEM_TIMEDWAIT) - IF( SEM_TIMEDWAIT) - ADD_DEFINITIONS (-DHAVE_SEM_TIMEDWAIT) - ENDIF( SEM_TIMEDWAIT) -else( ENABLE_LINK ) - ADD_DEFINITIONS (-DNO_LINK) -endif( ENABLE_LINK ) + include(CheckFunctionExists) + check_function_exists(sem_timedwait SEM_TIMEDWAIT) + if(SEM_TIMEDWAIT) + add_definitions(-DHAVE_SEM_TIMEDWAIT) + endif() +else() + add_definitions(-DNO_LINK) +endif() # The debugger is enabled by default -if( NOT ENABLE_DEBUGGER ) - ADD_DEFINITIONS (-DNO_DEBUGGER) -else( NOT ENABLE_DEBUGGER ) - ADD_DEFINITIONS (-DBKPT_SUPPORT) -endif( NOT ENABLE_DEBUGGER ) +if(NOT ENABLE_DEBUGGER) + add_definitions(-DNO_DEBUGGER) +else() + add_definitions(-DBKPT_SUPPORT) +endif() # The ASM core is disabled by default because we don't know on which platform we are -IF( NOT ENABLE_ASM_CORE ) - ADD_DEFINITIONS (-DC_CORE) -ENDIF( NOT ENABLE_ASM_CORE ) +if(NOT ENABLE_ASM_CORE) + add_definitions(-DC_CORE) +endif() # Enable internationalization -if( ENABLE_NLS ) - SET( LOCALEDIR ${CMAKE_INSTALL_PREFIX}/share/locale ) - ADD_DEFINITIONS ( -DENABLE_NLS ) - ADD_DEFINITIONS ( -DLOCALEDIR="${LOCALEDIR}" ) +if(ENABLE_NLS) + set(LOCALEDIR ${CMAKE_INSTALL_PREFIX}/share/locale) + add_definitions(-DENABLE_NLS) + add_definitions(-DLOCALEDIR="${LOCALEDIR}") # for now, only GBALink.cpp uses gettext() directly - IF(APPLE) + if(APPLE) # use Homebrew gettext if available - IF(EXISTS "/usr/local/opt/gettext") - SET(CMAKE_INCLUDE_PATH "${CMAKE_INCLUDE_PATH};/usr/local/opt/gettext/include") - SET(CMAKE_LIBRARY_PATH "${CMAKE_LIBRARY_PATH};/usr/local/opt/gettext/lib") - SET(CMAKE_PROGRAM_PATH "${CMAKE_PROGRAM_PATH};/usr/local/opt/gettext/bin") - ENDIF() - ENDIF() - IF(ENABLE_LINK) - FIND_PATH(LIBINTL_INC libintl.h) - FIND_LIBRARY(LIBINTL_LIB intl) - FIND_LIBRARY(LIBICONV_LIB iconv) - IF(LIBINTL_LIB) - SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${LIBINTL_LIB}) - SET(VBAMCORE_LIBS ${VBAMCORE_LIBS} ${LIBINTL_LIB}) - ENDIF(LIBINTL_LIB) - IF(LIBICONV_LIB) - SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${LIBICONV_LIB}) - SET(VBAMCORE_LIBS ${VBAMCORE_LIBS} ${LIBICONV_LIB}) - ENDIF(LIBICONV_LIB) - INCLUDE(CheckFunctionExists) - CHECK_FUNCTION_EXISTS(gettext GETTEXT_FN) - IF(NOT (LIBINTL_INC OR GETTEXT_FN)) - MESSAGE(FATAL_ERROR "NLS requires libintl/gettext") - ENDIF() - INCLUDE_DIRECTORIES(${LIBINTL_INC}) - ENDIF(ENABLE_LINK) -endif( ENABLE_NLS ) + if(EXISTS "/usr/local/opt/gettext") + set(CMAKE_INCLUDE_PATH "${CMAKE_INCLUDE_PATH};/usr/local/opt/gettext/include") + set(CMAKE_LIBRARY_PATH "${CMAKE_LIBRARY_PATH};/usr/local/opt/gettext/lib") + set(CMAKE_PROGRAM_PATH "${CMAKE_PROGRAM_PATH};/usr/local/opt/gettext/bin") + endif() + endif() + if(ENABLE_LINK) + find_path(LIBINTL_INC libintl.h) + find_library(LIBINTL_LIB intl) + find_library(LIBICONV_LIB iconv) + if(LIBINTL_LIB) + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${LIBINTL_LIB}) + set(VBAMCORE_LIBS ${VBAMCORE_LIBS} ${LIBINTL_LIB}) + endif() + if(LIBICONV_LIB) + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${LIBICONV_LIB}) + set(VBAMCORE_LIBS ${VBAMCORE_LIBS} ${LIBICONV_LIB}) + endif() + include(CheckFunctionExists) + check_function_exists(gettext GETTEXT_FN) + if(NOT (LIBINTL_INC OR GETTEXT_FN)) + message(FATAL_ERROR "NLS requires libintl/gettext") + endif() + include_directories(${LIBINTL_INC}) + endif() +endif() # Win32 deps submodule -IF(WIN32) - IF(NOT EXISTS "${CMAKE_SOURCE_DIR}/dependencies/mingw-xaudio/include") +if(WIN32) + if(NOT EXISTS "${CMAKE_SOURCE_DIR}/dependencies/mingw-xaudio/include") set(git_checkout FALSE) find_package(Git) if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git") @@ -309,34 +321,34 @@ IF(WIN32) if(NOT (git_checkout AND git_status EQUAL 0)) message(FATAL_ERROR "Please pull in git submodules, e.g.\nrun: git submodule update --init --remote --recursive") endif() - ENDIF() + endif() - IF(MINGW) - INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/dependencies/mingw-xaudio/include") - ELSEIF(MSVC) - SET(DEPS_MSVC "${CMAKE_SOURCE_DIR}/dependencies/msvc") - INCLUDE_DIRECTORIES("${DEPS_MSVC}") # for GL/glext.h and getopt.h - ENDIF() -ENDIF() + if(MINGW) + include_directories("${CMAKE_SOURCE_DIR}/dependencies/mingw-xaudio/include") + elseif(MSVC) + set(DEPS_MSVC "${CMAKE_SOURCE_DIR}/dependencies/msvc") + include_directories("${DEPS_MSVC}") # for GL/glext.h and getopt.h + endif() +endif() include(ProcessorCount) ProcessorCount(num_cpus) # Compiler flags -IF(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang) - SET(LTO_FLAGS "") - IF(ENABLE_LTO) - IF(CMAKE_COMPILER_IS_GNUCXX) +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang) + set(LTO_FLAGS "") + if(ENABLE_LTO) + if(CMAKE_COMPILER_IS_GNUCXX) if(num_cpus GREATER 1) - SET(LTO_FLAGS -flto=${num_cpus} -ffat-lto-objects) + set(LTO_FLAGS -flto=${num_cpus} -ffat-lto-objects) else() - SET(LTO_FLAGS -flto -ffat-lto-objects) + set(LTO_FLAGS -flto -ffat-lto-objects) endif() - ELSE() - SET(LTO_FLAGS -flto) - ENDIF() - ENDIF(ENABLE_LTO) + else() + set(LTO_FLAGS -flto) + endif() + endif() unset(MY_C_OPT_FLAGS) @@ -345,132 +357,139 @@ IF(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang) endif() # common optimization flags - IF(NOT (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL Clang AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.3)) - SET(MY_C_OPT_FLAGS ${MY_C_OPT_FLAGS} -O2 -fomit-frame-pointer ${LTO_FLAGS}) - ELSE() + if(NOT (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL Clang AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.3)) + set(MY_C_OPT_FLAGS ${MY_C_OPT_FLAGS} -O2 -fomit-frame-pointer ${LTO_FLAGS}) + else() # LTO and -fomit-frame-pointer generate broken binaries on Lion with XCode 4.2 tools - SET(MY_C_OPT_FLAGS ${MY_C_OPT_FLAGS} -O2) - ENDIF() + set(MY_C_OPT_FLAGS ${MY_C_OPT_FLAGS} -O2) + endif() # only use -mtune=generic on PC architectures - IF(X86_32 OR AMD64) - SET(MY_C_OPT_FLAGS ${MY_C_OPT_FLAGS} -mtune=generic) - ENDIF() + if(X86_32 OR AMD64) + set(MY_C_OPT_FLAGS ${MY_C_OPT_FLAGS} -mtune=generic) + endif() # common debug flags - IF(CMAKE_COMPILER_IS_GNUCXX) - SET(MY_C_DBG_FLAGS -ggdb3 -Og) - ELSE() - SET(MY_C_DBG_FLAGS -g) - ENDIF() + if(CMAKE_COMPILER_IS_GNUCXX) + set(MY_C_DBG_FLAGS -ggdb3 -Og) + else() + set(MY_C_DBG_FLAGS -g) + endif() # common flags - SET(MY_C_FLAGS -pipe -Wformat -Wformat-security -D_FORTIFY_SOURCE=2 -feliminate-unused-debug-types) + set(MY_C_FLAGS -pipe -Wformat -Wformat-security -D_FORTIFY_SOURCE=2 -feliminate-unused-debug-types) - IF(NOT WIN32) - SET(MY_C_FLAGS ${MY_C_FLAGS} -fPIC) - ENDIF() + if(NOT WIN32) + set(MY_C_FLAGS ${MY_C_FLAGS} -fPIC) + endif() - INCLUDE(CheckCXXCompilerFlag) + include(CheckCXXCompilerFlag) # check if ssp flags are supported for this version of gcc - IF(CMAKE_COMPILER_IS_GNUCXX) - CHECK_CXX_COMPILER_FLAG(-fstack-protector-strong F_STACK_PROTECTOR_STRONG_FLAG) + if(CMAKE_COMPILER_IS_GNUCXX) + check_cxx_compiler_flag(-fstack-protector-strong F_STACK_PROTECTOR_STRONG_FLAG) - IF(F_STACK_PROTECTOR_STRONG_FLAG) - SET(MY_C_FLAGS ${MY_C_FLAGS} -fstack-protector-strong) + if(F_STACK_PROTECTOR_STRONG_FLAG) + set(MY_C_FLAGS ${MY_C_FLAGS} -fstack-protector-strong) - CHECK_CXX_COMPILER_FLAG("--param ssp-buffer-size=4" SSP_BUFFER_SIZE_FLAG) + check_cxx_compiler_flag("--param ssp-buffer-size=4" SSP_BUFFER_SIZE_FLAG) - IF(SSP_BUFFER_SIZE_FLAG) + if(SSP_BUFFER_SIZE_FLAG) # we do not add it to MY_C_FLAGS because this breaks things like CMAKE_REQUIRED_LIBRARIES # which misinterpret compiler flags without leading dashes - ADD_COMPILE_OPTIONS(--param ssp-buffer-size=4) - ENDIF() - ENDIF() - ENDIF() + add_compile_options(--param ssp-buffer-size=4) + endif() + endif() - IF(MINGW) - SET(MY_C_FLAGS ${MY_C_FLAGS} -static-libgcc -static-libstdc++) - ENDIF(MINGW) + set(MYU_C_FLAGS ${MY_C_FLAGS} -fopenmp) + endif() - IF(CMAKE_BUILD_TYPE STREQUAL Debug) - SET(MY_C_FLAGS ${MY_C_FLAGS} ${MY_C_DBG_FLAGS} -Wall -Wextra) - ELSE() - SET(MY_C_FLAGS ${MY_C_FLAGS} ${MY_C_OPT_FLAGS} -Wno-error) - ENDIF() + if(MINGW) + set(MY_C_FLAGS ${MY_C_FLAGS} -static-libgcc -static-libstdc++) + endif() - FOREACH(C_COMPILE_FLAG ${MY_C_FLAGS}) - ADD_COMPILE_OPTIONS(${C_COMPILE_FLAG}) - ENDFOREACH() + if(CMAKE_BUILD_TYPE STREQUAL Debug) + set(MY_C_FLAGS ${MY_C_FLAGS} ${MY_C_DBG_FLAGS} -Wall -Wextra) + else() + set(MY_C_FLAGS ${MY_C_FLAGS} ${MY_C_OPT_FLAGS} -Wno-error) + endif() - SET(MY_CXX_FLAGS -std=gnu++11 -fpermissive -fexceptions) + foreach(C_COMPILE_FLAG ${MY_C_FLAGS}) + add_compile_options(${C_COMPILE_FLAG}) + endforeach() - FOREACH(ARG ${MY_CXX_FLAGS}) - SET(MY_CXX_FLAGS_STR "${MY_CXX_FLAGS_STR} ${ARG}") - ENDFOREACH() + set(MY_CXX_FLAGS -std=gnu++11 -fpermissive -fexceptions) + + foreach(ARG ${MY_CXX_FLAGS}) + set(MY_CXX_FLAGS_STR "${MY_CXX_FLAGS_STR} ${ARG}") + endforeach() # These must be set for C++ only, and we can't use generator expressions in # ADD_COMPILE_OPTIONS because that's a cmake 3.3 feature and we need 2.8.12 # compat for Ubuntu 14. - STRING(REGEX REPLACE "" " ${MY_CXX_FLAGS_STR} " CMAKE_CXX_COMPILE_OBJECT ${CMAKE_CXX_COMPILE_OBJECT}) + string(REGEX REPLACE "" " ${MY_CXX_FLAGS_STR} " CMAKE_CXX_COMPILE_OBJECT ${CMAKE_CXX_COMPILE_OBJECT}) - FOREACH(ARG ${MY_C_FLAGS}) - SET(MY_C_FLAGS_STR "${MY_C_FLAGS_STR} ${ARG}") - ENDFOREACH() + foreach(ARG ${MY_C_FLAGS}) + set(MY_C_FLAGS_STR "${MY_C_FLAGS_STR} ${ARG}") + endforeach() # need all flags for linking, because of -flto etc. - SET(CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} ${MY_C_FLAGS_STR}") - SET(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${MY_C_FLAGS_STR}") + set(CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} ${MY_C_FLAGS_STR}") + set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${MY_C_FLAGS_STR}") # for the gcc -fstack-protector* flags we need libssp # we also have to use the gcc- binutils for LTO to work - IF(CMAKE_COMPILER_IS_GNUCXX) - IF(ENABLE_LTO) - INCLUDE(UseGCCBinUtilsWrappers) - ENDIF(ENABLE_LTO) + if(CMAKE_COMPILER_IS_GNUCXX) + if(ENABLE_LTO) + include(UseGCCBinUtilsWrappers) + endif() - IF(WIN32) - SET(SSP_STATIC ON) - ENDIF(WIN32) + if(WIN32) + set(SSP_STATIC ON) + endif() - FIND_PACKAGE(SSP) + find_package(SSP) - IF(SSP_LIBRARY) - SET(MY_C_LINKER_FLAGS ${MY_C_LINKER_FLAGS} ${SSP_LIBRARY}) - ENDIF(SSP_LIBRARY) + if(SSP_LIBRARY) + set(MY_C_LINKER_FLAGS ${MY_C_LINKER_FLAGS} ${SSP_LIBRARY}) + endif() - SET(MY_C_LINKER_FLAGS ${MY_C_LINKER_FLAGS} -Wl,-allow-multiple-definition) - ENDIF() + set(MY_C_LINKER_FLAGS ${MY_C_LINKER_FLAGS} -Wl,-allow-multiple-definition) + + if(CMAKE_PREFIX_PATH) + list(GET CMAKE_PREFIX_PATH 0 prefix_path_first) + set(MY_C_LINKER_FLAGS ${MY_C_LINKER_FLAGS} "-Wl,-rpath-link=${prefix_path_first}/lib") + endif() + endif() # set linker flags - FOREACH(ARG ${MY_C_LINKER_FLAGS}) - SET(MY_C_LINKER_FLAGS_STR "${MY_C_LINKER_FLAGS_STR} ${ARG}") - ENDFOREACH() + foreach(ARG ${MY_C_LINKER_FLAGS}) + set(MY_C_LINKER_FLAGS_STR "${MY_C_LINKER_FLAGS_STR} ${ARG}") + endforeach() - SET(CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} ${MY_C_LINKER_FLAGS_STR}") - SET(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${MY_C_LINKER_FLAGS_STR}") -ENDIF() + set(CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} ${MY_C_LINKER_FLAGS_STR}") + set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${MY_C_LINKER_FLAGS_STR}") +endif() # Assembler flags -IF(ASM_ENABLED) - STRING(REGEX REPLACE "" "-I${CMAKE_SOURCE_DIR}/src/filters/hq/asm/ -O1 -w-orphan-labels" CMAKE_ASM_NASM_COMPILE_OBJECT ${CMAKE_ASM_NASM_COMPILE_OBJECT}) -ENDIF(ASM_ENABLED) +if(ASM_ENABLED) + string(REGEX REPLACE "" "-I${CMAKE_SOURCE_DIR}/src/filters/hq/asm/ -O1 -w-orphan-labels" CMAKE_ASM_NASM_COMPILE_OBJECT ${CMAKE_ASM_NASM_COMPILE_OBJECT}) +endif() -IF(APPLE) - ADD_DEFINITIONS(-DMACHO) -ELSEIF("${CMAKE_SYSTEM}" MATCHES "Linux") - ADD_DEFINITIONS(-DELF) -ENDIF() +if(APPLE) + add_definitions(-DMACHO) +elseif("${CMAKE_SYSTEM}" MATCHES "Linux") + add_definitions(-DELF) +endif() -IF(AMD64) - ADD_DEFINITIONS(-D__AMD64__) -ENDIF() +if(AMD64) + add_definitions(-D__AMD64__) +endif() add_subdirectory (fex) -SET(SRC_MAIN +set(SRC_MAIN src/Util.cpp src/common/ConfigManager.cpp src/common/dictionary.c @@ -481,10 +500,10 @@ SET(SRC_MAIN ) if(MSVC) - SET(SRC_MAIN ${SRC_MAIN} "dependencies/msvc/getopt.c") -endif(MSVC) + set(SRC_MAIN ${SRC_MAIN} "dependencies/msvc/getopt.c") +endif() -SET(HDR_MAIN +set(HDR_MAIN src/System.h src/Util.h src/common/array.h @@ -498,19 +517,19 @@ SET(HDR_MAIN ) if(MSVC) - SET(HDR_MAIN ${HDR_MAIN} "dependencies/msvc/getopt.h") -endif(MSVC) + set(HDR_MAIN ${HDR_MAIN} "dependencies/msvc/getopt.h") +endif() if(ENABLE_FFMPEG) - SET(SRC_MAIN ${SRC_MAIN} src/common/ffmpeg.cpp) - SET(HDR_MAIN ${HDR_MAIN} src/common/ffmpeg.h) -endif(ENABLE_FFMPEG) + set(SRC_MAIN ${SRC_MAIN} src/common/ffmpeg.cpp) + set(HDR_MAIN ${HDR_MAIN} src/common/ffmpeg.h) +endif() if(ENABLE_NLS) - SET(HDR_MAIN ${HDR_MAIN} src/NLS.h) -endif(ENABLE_NLS) + set(HDR_MAIN ${HDR_MAIN} src/NLS.h) +endif() -SET(SRC_GBA +set(SRC_GBA src/gba/agbprint.cpp src/gba/bios.cpp src/gba/BreakpointStructures.cpp @@ -540,7 +559,7 @@ SET(SRC_GBA src/gba/Sram.cpp ) -SET(HDR_GBA +set(HDR_GBA src/gba/agbprint.h src/gba/bios.h src/gba/BreakpointStructures.h @@ -563,7 +582,7 @@ SET(HDR_GBA src/gba/Sram.h ) -SET(SRC_GB +set(SRC_GB src/gb/GB.cpp src/gb/gbCheats.cpp src/gb/gbDis.cpp @@ -575,7 +594,7 @@ SET(SRC_GB src/gb/gbSound.cpp ) -SET(HDR_GB +set(HDR_GB src/gb/gb.h src/gb/gbCheats.h src/gb/gbCodes.h @@ -587,7 +606,7 @@ SET(HDR_GB src/gb/gbSound.h ) -SET(SRC_APU +set(SRC_APU src/apu/Blip_Buffer.cpp src/apu/Effects_Buffer.cpp src/apu/Gb_Apu.cpp @@ -596,7 +615,7 @@ SET(SRC_APU src/apu/Multi_Buffer.cpp ) -SET(HDR_APU +set(HDR_APU src/apu/blargg_common.h #Unused(?) but in the VS projects src/apu/blargg_config.h #Unused(?) but in the VS projects src/apu/blargg_source.h @@ -607,7 +626,7 @@ SET(HDR_APU src/apu/Multi_Buffer.h ) -SET(SRC_SDL +set(SRC_SDL src/sdl/SDL.cpp src/sdl/filters.cpp src/sdl/text.cpp @@ -617,7 +636,7 @@ SET(SRC_SDL src/sdl/expr-lex.cpp ) -SET(HDR_SDL +set(HDR_SDL src/sdl/filters.h src/sdl/text.h src/sdl/inputSDL.h @@ -625,7 +644,7 @@ SET(HDR_SDL src/sdl/exprNode.h ) -SET(SRC_FILTERS +set(SRC_FILTERS src/filters/2xSaI.cpp src/filters/admame.cpp src/filters/bilinear.cpp @@ -638,7 +657,7 @@ SET(SRC_FILTERS src/filters/xBRZ/xbrz.cpp ) -SET(HDR_FILTERS +set(HDR_FILTERS src/filters/hq2x.h src/filters/interp.h src/filters/lq2x.h @@ -646,18 +665,18 @@ SET(HDR_FILTERS src/filters/xBRZ/xbrz.h ) -SET(SRC_HQ_C +set(SRC_HQ_C src/filters/hq/c/hq_implementation.cpp ) -SET(HDR_HQ_C +set(HDR_HQ_C src/filters/hq/c/hq3x_pattern.h src/filters/hq/c/hq4x_pattern.h src/filters/hq/c/hq_base.h src/filters/hq/c/hq_shared.h ) -SET(SRC_HQ_ASM +set(SRC_HQ_ASM src/filters/hq/asm/hq3x_16.asm src/filters/hq/asm/hq3x_32.asm src/filters/hq/asm/hq4x_16.asm @@ -665,44 +684,44 @@ SET(SRC_HQ_ASM src/filters/hq/asm/hq3x32.cpp ) -if( ENABLE_ASM_SCALERS ) - SET(SRC_FILTERS ${SRC_FILTERS} ${SRC_HQ_ASM}) - IF(ENABLE_MMX) - SET(SRC_FILTERS ${SRC_FILTERS} src/filters/2xSaImmx.asm) - ENDIF(ENABLE_MMX) -else( ENABLE_ASM_SCALERS ) - SET(SRC_FILTERS ${SRC_FILTERS} ${SRC_HQ_C}) - SET(HDR_FILTERS ${HDR_FILTERS} ${HDR_HQ_C}) - ADD_DEFINITIONS ( -DNO_ASM ) -endif( ENABLE_ASM_SCALERS ) +if(ENABLE_ASM_SCALERS) + set(SRC_FILTERS ${SRC_FILTERS} ${SRC_HQ_ASM}) + if(ENABLE_MMX) + set(SRC_FILTERS ${SRC_FILTERS} src/filters/2xSaImmx.asm) + endif() +else() + set(SRC_FILTERS ${SRC_FILTERS} ${SRC_HQ_C}) + set(HDR_FILTERS ${HDR_FILTERS} ${HDR_HQ_C}) + add_definitions(-DNO_ASM) +endif() -if( ENABLE_DEBUGGER ) - SET(SRC_DEBUGGER +if(ENABLE_DEBUGGER) + set(SRC_DEBUGGER src/gba/armdis.cpp src/gba/elf.cpp src/gba/remote.cpp ) - SET(HDR_DEBUGGER + set(HDR_DEBUGGER src/gba/armdis.h src/gba/elf.h src/gba/remote.h ) -endif( ENABLE_DEBUGGER ) +endif() -INCLUDE_DIRECTORIES( +include_directories( ${ZLIB_INCLUDE_DIR} fex ${PNG_INCLUDE_DIR} ${SDL2_INCLUDE_DIR} ) -IF( ENABLE_FFMPEG ) - INCLUDE_DIRECTORIES( +if(ENABLE_FFMPEG) + include_directories( ${FFMPEG_INCLUDE_DIRS} ) -ENDIF( ENABLE_FFMPEG ) +endif() -ADD_LIBRARY ( +add_library( vbamcore STATIC ${PROJECT_SRCS} @@ -722,8 +741,8 @@ ADD_LIBRARY ( set_property(TARGET vbamcore PROPERTY CXX_STANDARD 11) set_property(TARGET vbamcore PROPERTY CXX_STANDARD_REQUIRED ON) -IF( ENABLE_SDL ) - ADD_EXECUTABLE ( +if(ENABLE_SDL) + add_executable( vbam WIN32 ${SRC_SDL} @@ -732,69 +751,69 @@ IF( ENABLE_SDL ) set_property(TARGET vbam PROPERTY CXX_STANDARD 11) set_property(TARGET vbam PROPERTY CXX_STANDARD_REQUIRED ON) - IF( WIN32 ) - SET( WIN32_LIBRARIES wsock32 ws2_32 ) - ENDIF( WIN32 ) + if(WIN32) + set(WIN32_LIBRARIES wsock32 ws2_32) + endif() - IF( ENABLE_LIRC ) - SET( LIRC_CLIENT_LIBRARY lirc_client ) - ENDIF( ENABLE_LIRC ) + if(ENABLE_LIRC) + set(LIRC_CLIENT_LIBRARY lirc_client) + endif() - TARGET_LINK_LIBRARIES ( + target_link_libraries( vbam ${VBAMCORE_LIBS} ${WIN32_LIBRARIES} ${LIRC_CLIENT_LIBRARY} ) - INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/vbam${CMAKE_EXECUTABLE_SUFFIX} DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}) + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/vbam${CMAKE_EXECUTABLE_SUFFIX} DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}) - IF( WIN32 ) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/sdl/vbam.cfg-example + if(WIN32) + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/sdl/vbam.cfg-example DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR} RENAME vbam.cfg) - ELSE( WIN32 ) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/sdl/vbam.cfg-example + else() + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/sdl/vbam.cfg-example DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR} RENAME vbam.cfg) - ENDIF( WIN32 ) -ENDIF( ENABLE_SDL ) + endif() +endif() -IF( ENABLE_WX ) +if(ENABLE_WX) add_subdirectory(src/wx) - INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/visualboyadvance-m${CMAKE_EXECUTABLE_SUFFIX} DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}) -ENDIF( ENABLE_WX ) + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/visualboyadvance-m${CMAKE_EXECUTABLE_SUFFIX} DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}) +endif() -if( ENABLE_WX ) +if(ENABLE_WX) # Native Language Support - if( ENABLE_NLS ) + if(ENABLE_NLS) add_subdirectory(po) - endif( ENABLE_NLS ) -endif( ENABLE_WX ) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/vba-over.ini DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/vbam) + endif() +endif() +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/vba-over.ini DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/vbam) # manual pages -IF( UNIX ) - IF( ENABLE_SDL ) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/debian/vbam.6 DESTINATION ${CMAKE_INSTALL_FULL_MANDIR}/man6) - ENDIF( ENABLE_SDL ) - IF( ENABLE_WX ) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/debian/visualboyadvance-m.6 DESTINATION ${CMAKE_INSTALL_FULL_MANDIR}/man6) - ENDIF( ENABLE_WX ) -ENDIF( UNIX ) +if(UNIX) + if(ENABLE_SDL) + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/debian/vbam.6 DESTINATION ${CMAKE_INSTALL_FULL_MANDIR}/man6) + endif() + if(ENABLE_WX) + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/debian/visualboyadvance-m.6 DESTINATION ${CMAKE_INSTALL_FULL_MANDIR}/man6) + endif() +endif() # linux data and icon files -IF( NOT WIN32 AND NOT APPLE ) - IF( ENABLE_WX ) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/wx/wxvbam.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/wx/wxvbam.appdata.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/appdata) - INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/wx/icons/sizes/ DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor) - ENDIF( ENABLE_WX ) -ENDIF( NOT WIN32 AND NOT APPLE ) +if(NOT WIN32 AND NOT APPLE) + if(ENABLE_WX) + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/wx/wxvbam.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications) + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/wx/wxvbam.appdata.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/appdata) + install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/wx/icons/sizes/ DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor) + endif() +endif() -SET(CPACK_GENERATOR "ZIP") +set(CPACK_GENERATOR "ZIP") set(CPACK_SOURCE_GENERATOR "TGZ") -SET(CPACK_PACKAGE_VERSION_MAJOR "2") -SET(CPACK_PACKAGE_VERSION_MINOR "0") -SET(CPACK_PACKAGE_VERSION_PATCH "0-Git-" ${COMMITHASH}) +set(CPACK_PACKAGE_VERSION_MAJOR "2") +set(CPACK_PACKAGE_VERSION_MINOR "0") +set(CPACK_PACKAGE_VERSION_PATCH "0-Git-" ${COMMITHASH}) list(APPEND CPACK_SOURCE_IGNORE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/dependencies") -INCLUDE(CPack) +include(CPack) diff --git a/README.md b/README.md index fe76aeb3..4ab1d4a6 100644 --- a/README.md +++ b/README.md @@ -130,14 +130,18 @@ Here is the complete list: | ENABLE_MMX | Enable MMX | ON for 32 bit builds | | ENABLE_LINK | Enable GBA linking functionality (requires SFML) | ON | | ENABLE_LIRC | Enable LIRC support | OFF | -| ENABLE_FFMPEG | Enable ffmpeg A/V recording | ON on Linux and MSys2 | +| ENABLE_FFMPEG | Enable ffmpeg A/V recording | OFF | | ENABLE_LTO | Compile with Link Time Optimization (gcc and clang only) | ON for release build | | ENABLE_GBA_LOGGING | Enable extended GBA logging | ON | | ENABLE_DIRECT3D | Direct3D rendering for wxWidgets (Windows, **NOT IMPLEMENTED!!!**) | ON | | ENABLE_XAUDIO2 | Enable xaudio2 sound output for wxWidgets (Windows only) | ON | | ENABLE_OPENAL | Enable OpenAL for the wxWidgets port | ON | -| SFML_STATIC_LIBRARIES | Set this to ON if linking static SFML libraries | OFF | -| FFMPEG_STATIC | Set this to ON if linking static ffmpeg librariesl | OFF | +| VBAM_STATIC | Try link all libs statically (the following are set to ON if ON) | OFF | +| SDL2_STATIC | Try to link static SDL2 libraries | OFF | +| SFML_STATIC_LIBRARIES | Try to link static SFML libraries | OFF | +| FFMPEG_STATIC | Try to link static ffmpeg libraries | OFF | +| SSP_STATIC | Try to link static gcc stack protector library (gcc only) | OFF except Win32 | +| OPENAL_STATIC | Try to link static OpenAL libraries | OFF | Note for distro packagers, we use the CMake module [GNUInstallDirs](https://cmake.org/cmake/help/v2.8.12/cmake.html#module:GNUInstallDirs) diff --git a/cmake/FindSSP.cmake b/cmake/FindSSP.cmake index 3008f3a8..4b3057a2 100644 --- a/cmake/FindSSP.cmake +++ b/cmake/FindSSP.cmake @@ -52,9 +52,18 @@ IF(NOT (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUC)) RETURN() ENDIF() -GET_FILENAME_COMPONENT(GCC_DIRNAME ${CMAKE_C_COMPILER} DIRECTORY) +foreach(arg ${CMAKE_C_COMPILER_ARG1} ${CMAKE_C_COMPILER_ARG2} ${CMAKE_C_COMPILER_ARG3} ${CMAKE_C_COMPILER_ARG4} ${CMAKE_C_COMPILER_ARG5} ${CMAKE_C_COMPILER_ARG6} ${CMAKE_C_COMPILER_ARG7} ${CMAKE_C_COMPILER_ARG8} ${CMAKE_C_COMPILER_ARG9}) + string(STRIP ${arg} arg) + set(gcc_args "${gcc_args};${arg}") +endforeach() -EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} --print-libgcc-file-name OUTPUT_VARIABLE LIBGCC_FILE OUTPUT_STRIP_TRAILING_WHITESPACE) +EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} ${gcc_args} --print-prog-name=gcc OUTPUT_VARIABLE GCC_EXECUTABLE OUTPUT_STRIP_TRAILING_WHITESPACE) + +execute_process(COMMAND sh -c "command -v ${GCC_EXECUTABLE}" OUTPUT_VARIABLE GCC_EXECUTABLE OUTPUT_STRIP_TRAILING_WHITESPACE) + +GET_FILENAME_COMPONENT(GCC_DIRNAME ${GCC_EXECUTABLE} DIRECTORY) + +EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} ${gcc_args} --print-libgcc-file-name OUTPUT_VARIABLE LIBGCC_FILE OUTPUT_STRIP_TRAILING_WHITESPACE) GET_FILENAME_COMPONENT(LIBGCC_DIRNAME ${LIBGCC_FILE} DIRECTORY) diff --git a/cmake/Toolchain-cross-MinGW-w64-i686.cmake b/cmake/Toolchain-cross-MinGW-w64-i686.cmake index 22e6f64a..3c645935 100644 --- a/cmake/Toolchain-cross-MinGW-w64-i686.cmake +++ b/cmake/Toolchain-cross-MinGW-w64-i686.cmake @@ -9,6 +9,10 @@ find_program(CMAKE_CXX_COMPILER NAMES ${COMPILER_PREFIX}-g++) SET(CMAKE_FIND_ROOT_PATH /usr/${COMPILER_PREFIX} /usr/${COMPILER_PREFIX}/sys-root/mingw) +if(CMAKE_PREFIX_PATH) + set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CMAKE_PREFIX_PATH}) +endif() + # adjust the default behaviour of the FIND_XXX() commands: # search headers and libraries in the target environment, search # programs in the host environment too diff --git a/cmake/Toolchain-cross-MinGW-w64-x86_64.cmake b/cmake/Toolchain-cross-MinGW-w64-x86_64.cmake index 12302a12..45606314 100644 --- a/cmake/Toolchain-cross-MinGW-w64-x86_64.cmake +++ b/cmake/Toolchain-cross-MinGW-w64-x86_64.cmake @@ -9,6 +9,10 @@ find_program(CMAKE_CXX_COMPILER NAMES ${COMPILER_PREFIX}-g++) SET(CMAKE_FIND_ROOT_PATH /usr/${COMPILER_PREFIX} /usr/${COMPILER_PREFIX}/sys-root/mingw) +if(CMAKE_PREFIX_PATH) + set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CMAKE_PREFIX_PATH}) +endif() + # adjust the default behaviour of the FIND_XXX() commands: # search headers and libraries in the target environment, search # programs in the host environment too diff --git a/installdeps b/installdeps index 6f14ff5f..367e8080 100755 --- a/installdeps +++ b/installdeps @@ -159,6 +159,8 @@ linux_installdeps() { archlinux_installdeps elif [ -f /etc/solus-release ]; then solus_installdeps + elif path_exists /etc/os-release && [ "$(. /etc/os-release; puts "$ID_LIKE")" = suse ]; then + suse_installdeps else error "Don't know how to install deps on your version of Linux" fi @@ -488,6 +490,16 @@ fedora_installdeps() { build_instructions } +suse_installdeps() { + check_cross + installing + + check sudo zypper in -y gcc gcc-c++ binutils make cmake nasm ffmpeg2-devel gettext-tools libpng16-devel \ + pkg-config libSDL2-devel sfml2-devel wxWidgets-3_0-devel + + build_instructions +} + archlinux_require_yaourt() { if ! command -v yaourt >/dev/null; then ( diff --git a/src/wx/CMakeLists.txt b/src/wx/CMakeLists.txt index 4d61e2e1..69e664f3 100644 --- a/src/wx/CMakeLists.txt +++ b/src/wx/CMakeLists.txt @@ -31,7 +31,7 @@ if(ENABLE_OPENAL) FIND_PACKAGE(OpenAL REQUIRED) INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR}) - IF(WIN32 AND ((NOT (MINGW AND MSYS)) OR CMAKE_TOOLCHAIN_FILE MATCHES mxe)) + IF(OPENAL_STATIC OR (WIN32 AND ((NOT (MINGW AND MSYS)) OR CMAKE_TOOLCHAIN_FILE MATCHES mxe))) ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC) ENDIF() else(ENABLE_OPENAL) @@ -42,6 +42,33 @@ IF(CMAKE_BUILD_TYPE STREQUAL "Debug") SET(wxWidgets_USE_DEBUG ON) # noop if wx is compiled with --disable-debug, like in Mac Homebrew atm ENDIF() +# on e.g. msys2 add a couple of libraries wx needs +#if(WIN32 AND (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang)) +# set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -luuid -lwinspool") +#endif() + +# convert msys paths like /c/foo to windows paths like c:/foo +# for variables set by FindWxWidgets +function(normalize_wx_paths) + if(MSYS) + unset(new_paths) + foreach(p ${wxWidgets_LIBRARY_DIRS}) + execute_process(COMMAND cygpath -m "${p}" OUTPUT_VARIABLE p_win OUTPUT_STRIP_TRAILING_WHITESPACE) + list(APPEND new_paths "${p_win}") + endforeach() + + set(wxWidgets_LIBRARY_DIRS ${new_paths} PARENT_SCOPE) + + string(REGEX REPLACE "((^| )[^/]*)/([a-zA-Z])/" "\\1\\3:/" new_libs "${wxWidgets_LIBRARIES}") + + set(wxWidgets_LIBRARIES ${new_libs} PARENT_SCOPE) + endif() +endfunction() + +if(CMAKE_PREFIX_PATH) + set(wxWidgets_CONFIG_OPTIONS "--prefix=${CMAKE_PREFIX_PATH}") +endif() + SET(wxWidgets_USE_UNICODE ON) # adv is for wxAboutBox # xml, html is for xrc @@ -51,6 +78,7 @@ SET(wxWidgets_USE_LIBS xrc xml html adv gl net core base gl) # the gl lib may not be available, and if it looks like it is we still have to # do a compile test later FIND_PACKAGE(wxWidgets QUIET) +normalize_wx_paths() SET(CHECK_WX_OPENGL FALSE) @@ -116,6 +144,7 @@ IF(NOT WX_HAS_OPENGL) ADD_DEFINITIONS(-DNO_OGL) LIST(REMOVE_ITEM wxWidgets_USE_LIBS gl) FIND_PACKAGE(wxWidgets REQUIRED) + normalize_wx_paths() ENDIF() IF(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_CROSSCOMPILING) @@ -268,8 +297,19 @@ IF(NOT WIN32 AND NOT APPLE) SET(WX_CONFIG_H "${WX_CONFIG_H}/wx/config.h") INCLUDE(CheckCXXSymbolExists) + CHECK_CXX_SYMBOL_EXISTS(__WXGTK4__ ${WX_CONFIG_H} WX_USING_GTK4) CHECK_CXX_SYMBOL_EXISTS(__WXGTK3__ ${WX_CONFIG_H} WX_USING_GTK3) - IF(WX_USING_GTK3) + IF(WX_USING_GTK4) + FIND_PACKAGE(PkgConfig REQUIRED) + PKG_CHECK_MODULES(GTK4 REQUIRED gtk+-4.0) + IF(NOT GTK4_INCLUDE_DIRS) + MESSAGE(FATAL_ERROR "Could not find gtk4") + ENDIF() + INCLUDE_DIRECTORIES(${GTK4_INCLUDE_DIRS}) + LINK_DIRECTORIES(${GTK4_LIBRARY_DIRS}) + ADD_COMPILE_OPTIONS(${GTK4_CFLAGS_OTHER}) + SET(GTK_LIBRARIES ${GTK4_LIBRARIES}) + ELSEIF(WX_USING_GTK3) FIND_PACKAGE(PkgConfig REQUIRED) PKG_CHECK_MODULES(GTK3 REQUIRED gtk+-3.0) IF(NOT GTK3_INCLUDE_DIRS) @@ -367,10 +407,17 @@ INCLUDE(HostCompile) HOST_COMPILE(${CMAKE_CURRENT_SOURCE_DIR}/bin2c.c ${BIN2C}) +if(WXRC) + separate_arguments(WXRC UNIX_COMMAND "${WXRC}") +else() + set(WXRC wxrc) +endif() + ADD_CUSTOM_COMMAND(OUTPUT wxvbam.xrs WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND wxrc ${XRC_SOURCES} -o wxvbam.xrs + COMMAND ${WXRC} ${XRC_SOURCES} "--output=wxvbam.xrs" DEPENDS ${XRC_SOURCES}) + ADD_CUSTOM_COMMAND(OUTPUT builtin-xrc.h COMMAND ${BIN2C} wxvbam.xrs builtin-xrc.h builtin_xrs DEPENDS wxvbam.xrs) @@ -520,12 +567,39 @@ if(ENABLE_FFMPEG) visualboyadvance-m PROPERTIES LINK_FLAGS ${FFMPEG_LDFLAGS_STR} ) -endif(ENABLE_FFMPEG) +endif() -# Build a console app in debug mode on Windows -IF(WIN32 AND CMAKE_BUILD_TYPE STREQUAL Debug) - SET(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -Wl,--subsystem,console") -ENDIF() +# link libgcc/libstdc++ statically on mingw +# and adjust link command when making a static binary +if(CMAKE_COMPILER_IS_GNUCXX) + if(WIN32) + # Build a console app in debug mode on Windows + if(CMAKE_BUILD_TYPE STREQUAL Debug) + set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -Wl,--subsystem,console") + else() + set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -Wl,--subsystem,windows") + endif() + endif() + + if(VBAM_STATIC) + # some dists don't have a static libpthread + set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread ") + + if(WIN32) + add_custom_command( + TARGET visualboyadvance-m PRE_LINK + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/msys-link-static.cmake + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + else() + add_custom_command( + TARGET visualboyadvance-m PRE_LINK + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/link-static.cmake + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + endif() + endif() +endif() IF(WIN32) INSTALL(PROGRAMS ${PROJECT_BINARY_DIR}/visualboyadvance-m${CMAKE_EXECUTABLE_SUFFIX} DESTINATION ${CMAKE_BINARY_DIR}) diff --git a/src/wx/guiinit.cpp b/src/wx/guiinit.cpp index 4e916949..bc423b6b 100644 --- a/src/wx/guiinit.cpp +++ b/src/wx/guiinit.cpp @@ -2536,8 +2536,8 @@ void MainFrame::MenuOptionIntRadioValue(const char* menuName, int& field, int va // app-specific volume controls. #ifdef __WXMSW__ - #include - #include + #include + #include #include typedef int (WINAPI *func_LoadIconWithScaleDown)(HINSTANCE, LPCWSTR, int, int, HICON*); #endif diff --git a/src/wx/link-static.cmake b/src/wx/link-static.cmake new file mode 100644 index 00000000..01656053 --- /dev/null +++ b/src/wx/link-static.cmake @@ -0,0 +1,5 @@ +file(READ CMakeFiles/visualboyadvance-m.dir/link.txt link_cmd) + +string(REGEX REPLACE "-l(z|expat|X[^ ]+|xcb[^ ]*) " "-Wl,--whole-archive -l\\1 -Wl,--no-whole-archive " link_cmd ${link_cmd}) + +file(WRITE CMakeFiles/visualboyadvance-m.dir/link.txt ${link_cmd}) diff --git a/src/wx/msys-link-static.cmake b/src/wx/msys-link-static.cmake new file mode 100644 index 00000000..a5881a1f --- /dev/null +++ b/src/wx/msys-link-static.cmake @@ -0,0 +1,5 @@ +file(READ CMakeFiles/visualboyadvance-m.dir/linklibs.rsp link_libs) + +string(REPLACE "-Wl,-Bdynamic" "" link_libs ${link_libs}) + +file(WRITE CMakeFiles/visualboyadvance-m.dir/linklibs.rsp ${link_libs}) diff --git a/tools/builder/core.sh b/tools/builder/core.sh new file mode 100644 index 00000000..e9c99778 --- /dev/null +++ b/tools/builder/core.sh @@ -0,0 +1,2463 @@ +#!/bin/sh + +set -e + +[ -n "$BASH_VERSION" ] && set -o posix + +BUILD_ROOT=${BUILD_ROOT:-$HOME/vbam-build} +TAR=${TAR:-tar --force-local} +CURL=${CURL:-curl --insecure} +PERL_MAKE=${PERL_MAKE:-make} + +[ -n "$BUILD_ENV" ] && eval "$BUILD_ENV" + +BUILD_ENV=$BUILD_ENV$(cat </dev/null; then + export CC="ccache \$CC" + export CXX="ccache \$CXX" + fi + ;; +esac + +export CPPFLAGS="$CPPFLAGS -I$BUILD_ROOT/root/include" +export CFLAGS="$CFLAGS -fPIC -I$BUILD_ROOT/root/include -L$BUILD_ROOT/root/lib -Wno-error=all" +export CXXFLAGS="$CXXFLAGS -fPIC -I$BUILD_ROOT/root/include -L$BUILD_ROOT/root/lib -std=gnu++11 -Wno-error=all" +export OBJCXXFLAGS="$OBJCXXFLAGS -fPIC -I$BUILD_ROOT/root/include -L$BUILD_ROOT/root/lib -std=gnu++11 -Wno-error=all" +export LDFLAGS="$LDFLAGS -fPIC -L$BUILD_ROOT/root/lib -Wno-error=all" + +if [ -z "\$OPENMP" ] && echo "\$CC" | grep -Eq gcc; then + export CFLAGS="\$CFLAGS -fopenmp" + export CXXFLAGS="\$CXXFLAGS -fopenmp" + export OBJCXXFLAGS="\$OBJCXXFLAGS -fopenmp" + export LDFLAGS="\$LDFLAGS -fopenmp" + export OPENMP=1 +fi + +export CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH:-$BUILD_ROOT/root}" +export PKG_CONFIG_PATH="$BUILD_ROOT/root/lib/pkgconfig:$BUILD_ROOT/root/share/pkgconfig" + +export LD_LIBRARY_PATH="$BUILD_ROOT/root/lib" + +export PERL_MM_USE_DEFAULT=1 +export PERL_EXTUTILS_AUTOINSTALL="--defaultdeps" + +export OPENSSL_ROOT="$BUILD_ROOT/root" + +export PERL_MB_OPT='--install_base $BUILD_ROOT/root/perl5' +export PERL_MM_OPT='INSTALL_BASE=$BUILD_ROOT/root/perl5' +export PERL5LIB="$BUILD_ROOT/root/perl5/lib/perl5" +export PERL_LOCAL_LIB_ROOT="$BUILD_ROOT/root/perl5" + +case "\$PATH" in + *"$BUILD_ROOT"*) + ;; + *) + export PATH="$BUILD_ROOT/host/bin:$BUILD_ROOT/root/bin:$BUILD_ROOT/root/perl5/bin:\$PATH" + ;; +esac + +export PERL_MM_OPT="\$PERL_MM_OPT CCFLAGS='\$CFLAGS' LDDFLAGS='\$LDFLAGS'" + +export MANPATH="$BUILD_ROOT/root/man:$BUILD_ROOT/root/share/man:/usr/share/man:/usr/local/share/man" + +export XML_CATALOG_FILES="$BUILD_ROOT/root/etc/xml/catalog.xml" + +export FORMAT_DIR="$BUILD_ROOT/root/share/xmlto/format" + +export XDG_DATA_DIRS="$BUILD_ROOT/root/share" + +export FONTCONFIG_PATH="$BUILD_ROOT/root/etc/fonts" + +export BISON_PKGDATADIR="$BUILD_ROOT/root/share/bison" + +export SWIG_LIB="\$(echo \$BUILD_ROOT/root/share/swig/*)" + +if command -v cygpath >/dev/null; then + export XML_CATALOG_FILES=\$(cygpath -m "\$XML_CATALOG_FILES") +fi + +EOF +) + +ORIG_PATH=$PATH + +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 + 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 + openssl https://www.openssl.org/source/openssl-1.0.2l.tar.gz lib/libssl.a + cmake https://cmake.org/files/v3.10/cmake-3.10.0-rc3.tar.gz bin/cmake + zlib https://zlib.net/zlib-1.2.11.tar.gz lib/libz.a + m4 http://ftp.gnu.org/gnu/m4/m4-1.4.18.tar.xz bin/m4 + autoconf https://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.xz bin/autoconf + autoconf-archive http://mirror.team-cymru.org/gnu/autoconf-archive/autoconf-archive-2017.09.28.tar.xz share/aclocal/ax_check_gl.m4 + automake https://ftp.gnu.org/gnu/automake/automake-1.15.1.tar.xz bin/automake + libtool https://ftp.gnu.org/gnu/libtool/libtool-2.4.6.tar.xz bin/libtool + xorg-macros https://www.x.org/archive//individual/util/util-macros-1.19.1.tar.bz2 share/pkgconfig/xorg-macros.pc + help2man https://ftp.gnu.org/gnu/help2man/help2man-1.47.5.tar.xz bin/help2man + libiconv https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz lib/libiconv.a + gettext http://ftp.gnu.org/pub/gnu/gettext/gettext-0.19.8.1.tar.xz lib/libintl.a + getopt http://frodo.looijaard.name/system/files/software/getopt/getopt-1.1.6.tar.gz bin/getopt + gsed http://ftp.gnu.org/gnu/sed/sed-4.4.tar.xz bin/sed + bison https://ftp.gnu.org/gnu/bison/bison-3.0.4.tar.xz bin/bison + texinfo http://ftp.gnu.org/gnu/texinfo/texinfo-6.5.tar.xz bin/makeinfo + flex-2.6.3 https://github.com/westes/flex/releases/download/v2.6.3/flex-2.6.3.tar.gz bin/flex + flex https://github.com/westes/flex/archive/e7d45afc6aeb49745f17d21ddba4848e0c0118fc.tar.gz bin/flex + xmlto https://releases.pagure.org/xmlto/xmlto-0.0.28.tar.bz2 bin/xmlto + gperf http://ftp.gnu.org/pub/gnu/gperf/gperf-3.1.tar.gz bin/gperf + pkgconfig https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz bin/pkg-config + nasm http://repo.or.cz/nasm.git/snapshot/53371ddd17b685f8880c22b8b698e494e0f1059b.tar.gz bin/nasm + yasm http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz bin/yasm + pcre https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.bz2 lib/libpcre.a + libffi ftp://sourceware.org/pub/libffi/libffi-3.2.1.tar.gz lib/libffi.a + c2man http://www.ciselant.de/c2man/c2man-2.0@42.tar.gz bin/c2man + libxml2 ftp://xmlsoft.org/libxml2/libxml2-2.9.7.tar.gz lib/libxml2.a + libxslt https://git.gnome.org/browse/libxslt/snapshot/libxslt-1.1.32-rc1.tar.xz lib/libxslt.a + XML-NamespaceSupport https://cpan.metacpan.org/authors/id/P/PE/PERIGRIN/XML-NamespaceSupport-1.12.tar.gz perl5/lib/perl5/XML/NamespaceSupport.pm + XML-SAX-Base https://cpan.metacpan.org/authors/id/G/GR/GRANTM/XML-SAX-Base-1.09.tar.gz perl5/lib/perl5/XML/SAX/Base.pm + XML-SAX https://cpan.metacpan.org/authors/id/G/GR/GRANTM/XML-SAX-0.99.tar.gz perl5/lib/perl5/XML/SAX.pm + docbook2x https://downloads.sourceforge.net/project/docbook2x/docbook2x/0.8.8/docbook2X-0.8.8.tar.gz bin/docbook2man + expat https://github.com/libexpat/libexpat/archive/R_2_2_4.tar.gz lib/libexpat.a + libpng https://download.sourceforge.net/libpng/libpng-1.6.32.tar.xz lib/libpng.a + 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 + freetype http://download.savannah.gnu.org/releases/freetype/freetype-2.8.tar.bz2 lib/libfreetype.a + fontconfig https://www.freedesktop.org/software/fontconfig/release/fontconfig-2.12.6.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 + dejavu https://downloads.sourceforge.net/project/dejavu/dejavu/2.37/dejavu-fonts-ttf-2.37.tar.bz2 share/fonts/dejavu/DejaVuSansMono.ttf + liberation https://releases.pagure.org/liberation-fonts/liberation-fonts-ttf-2.00.1.tar.gz share/fonts/liberation/LiberationMono-Regular.ttf + urw http://downloads.ghostscript.com/public/fonts/urw-base35-v1.10.zip share/fonts/urw/a010013l.pfm + graphviz https://gitlab.com/graphviz/graphviz/repository/archive.tar.bz2?ref=bd97cff688f7a7b85b6f1262e14eb1cac0862fcd bin/dot_static + docbook4.2 http://www.docbook.org/xml/4.2/docbook-xml-4.2.zip share/xml/docbook/schema/dtd/4.2/catalog.xml + docbook4.1.2 http://www.docbook.org/xml/4.1.2/docbkx412.zip share/xml/docbook/schema/dtd/4.1.2/catalog.xml + docbook4.3 http://www.docbook.org/xml/4.3/docbook-xml-4.3.zip share/xml/docbook/schema/dtd/4.3/catalog.xml + docbook4.4 http://www.docbook.org/xml/4.4/docbook-xml-4.4.zip share/xml/docbook/schema/dtd/4.4/catalog.xml + docbook4.5 http://www.docbook.org/xml/4.5/docbook-xml-4.5.zip share/xml/docbook/schema/dtd/4.5/catalog.xml + docbook5.0 http://www.docbook.org/xml/5.0/docbook-5.0.zip share/xml/docbook/schema/dtd/5.0/catalog.xml + docbook-xsl https://downloads.sourceforge.net/project/docbook/docbook-xsl/1.79.1/docbook-xsl-1.79.1.tar.bz2 share/xml/docbook/stylesheet/docbook-xsl/catalog.xml + docbook-xsl-ns https://downloads.sourceforge.net/project/docbook/docbook-xsl-ns/1.79.1/docbook-xsl-ns-1.79.1.tar.bz2 share/xml/docbook/stylesheet/docbook-xsl-ns/catalog.xml + python2 https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tar.xz bin/python + python3 https://github.com/python/cpython/archive/d135f20ae8887acc7716561bc8f4c7eb6d58d24c.tar.gz bin/python3 + swig https://downloads.sourceforge.net/project/swig/swig/swig-3.0.12/swig-3.0.12.tar.gz bin/swig + libxml2-python ftp://xmlsoft.org/libxml2/libxml2-sources-2.9.7.tar.gz lib/python2.7/site-packages/libxml2.py + doxygen https://downloads.sourceforge.net/project/doxygen/rel-1.8.14/doxygen-1.8.14.src.tar.gz bin/doxygen + bakefile https://github.com/vslavik/bakefile/archive/33c270a565ba0954cca9611b2443593b2e9e698a.tar.gz bin/bakefile_gen + XML-Parser https://cpan.metacpan.org/authors/id/T/TO/TODDR/XML-Parser-2.44.tar.gz perl5/man/man3/XML*Parser.3* + 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 + 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 + sdl2 https://www.libsdl.org/release/SDL2-2.0.7.tar.gz lib/libSDL2.a + flac https://github.com/xiph/flac/archive/f7cd466c24fb5d1966943f3ea36a1f4a37858597.tar.gz lib/libFLAC.a + libogg http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.xz lib/libogg.a + libvorbis https://github.com/xiph/vorbis/archive/v1.3.5.tar.gz lib/libvorbis.a + 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/47c0aed3222360f22cd35e8cad307457e51299c2.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 + libgsm http://www.quut.com/gsm/gsm-1.0.17.tar.gz lib/libgsm.a + libmodplug https://github.com/Konstanty/libmodplug/archive/5a39f5913d07ba3e61d8d5afdba00b70165da81d.tar.gz lib/libmodplug.a + libopencore-amrnb https://downloads.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-0.1.5.tar.gz lib/libopencore-amrnb.a + opus https://archive.mozilla.org/pub/opus/opus-1.2.1.tar.gz lib/libopus.a + snappy https://github.com/google/snappy/archive/1.1.7.tar.gz lib/libsnappy.a + libsoxr https://downloads.sourceforge.net/project/soxr/soxr-0.1.2-Source.tar.xz lib/libsoxr.a + speex http://downloads.us.xiph.org/releases/speex/speex-1.2.0.tar.gz lib/libspeex.a + libtheora https://github.com/Distrotech/libtheora/archive/17b02c8c564475bb812e540b551219fc42b1f75f.tar.gz lib/libtheora.a + vidstab https://github.com/georgmartius/vid.stab/archive/v1.1.0.tar.gz lib/libvidstab.a + libvo-amrwbenc https://github.com/mstorsjo/vo-amrwbenc/archive/v0.1.3.tar.gz lib/libvo-amrwbenc.a + mp3lame https://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz lib/libmp3lame.a + libass https://github.com/libass/libass/releases/download/0.13.7/libass-0.13.7.tar.xz lib/libass.a + libbluray ftp://ftp.videolan.org/pub/videolan/libbluray/1.0.2/libbluray-1.0.2.tar.bz2 lib/libbluray.a + libvpx http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-1.6.1.tar.bz2 lib/libvpx.a + libwavpack http://www.wavpack.com/wavpack-5.1.0.tar.bz2 lib/libwavpack.a + libx264 ftp://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20171228-2245.tar.bz2 lib/libx264.a + libx265 https://bitbucket.org/multicoreware/x265/downloads/x265_2.5.tar.gz lib/libx265.a + libxavs https://github.com/Distrotech/xavs/archive/distrotech-xavs-git.tar.gz lib/libxavs.a + libzmq https://github.com/zeromq/libzmq/releases/download/v4.2.2/zeromq-4.2.2.tar.gz lib/libzmq.a +# libzvbi https://downloads.sourceforge.net/project/zapping/zvbi/0.2.35/zvbi-0.2.35.tar.bz2 lib/libzvbi.a + ffmpeg https://github.com/ffmpeg/ffmpeg/archive/0c78b6a416c661afed745d44495b5194f714fb96.tar.gz lib/libavformat.a +' + +# these two can be set to always be included regardless of overrides +REQUIRED_CONFIGURE_ARGS="$REQUIRED_CONFIGURE_ARGS" +REQUIRED_CMAKE_ARGS="$REQUIRED_CMAKE_ARGS" + +CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-shared --enable-static --prefix=/usr" + +CMAKE_BASE_ARGS="$CMAKE_BASE_ARGS -DBUILD_SHARED_LIBS=NO -DENABLE_SHARED=NO -DCMAKE_PREFIX_PATH=\"\$CMAKE_PREFIX_PATH\" -DCMAKE_BUILD_TYPE=Release" + +CMAKE_ARGS="$CMAKE_BASE_ARGS $CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=/usr" + +MESON_ARGS="--prefix /usr --buildtype release --default-library static -Dintrospection=false" + +PROJECT_ARGS="$PROJECT_ARGS" + +DIST_PATCHES=$DIST_PATCHES' + docbook2x https://gist.githubusercontent.com/rkitover/0b5dcc95a0703a9b0e0e7eb6d325a98e/raw/e256d2fad8d19633ac8abe02a0d1e119063d1fd9/docbook2x.patch + graphite2 https://gist.githubusercontent.com/rkitover/418600634d7cf19e2bf1c3708b50c042/raw/839b72d9cda545f2e3b640d743c1bd44b89861b9/graphite2-1.3.10-static.patch + python2 https://gist.githubusercontent.com/rkitover/2d9e5baff1f1cc4f2618dee53083bd35/raw/7f33fcf5470a9f1013ac6ae7bb168368a98fe5a0/python-2.7.14-custom-static-openssl.patch https://gist.githubusercontent.com/rkitover/afab7ed3ac7ce1860c43a258571c8ae1/raw/6f5fc90a7acf5f5c3ffda2edf402b28f469a4b3b/python-2.7.14-static-libintl.patch + python3 https://gist.githubusercontent.com/rkitover/93d89a679705875c59275fb0a8f22b45/raw/6149e7fa3920d6c674c79448c5a4c9313620e06c/python-3.6.3-custom-static-openssl.patch https://gist.githubusercontent.com/rkitover/b18f19eafda3775a9652cc9cdf3ec914/raw/ed14c34bf9f205ccc3a4684dbdb83f8620162b98/python-3.6.3-static-libintl.patch + intltool https://gist.githubusercontent.com/rkitover/d638882f52e5d5f8e392cbf6842cd6d0/raw/dcfbe358bbb8b89f88b40a9c3402494552fd33f8/intltool-0.51.0.patch +' + +DIST_TAR_ARGS="$DIST_TAR_ARGS +" + +DIST_CONFIGURE_TYPES="$DIST_CONFIGURE_TYPES + unzip make + zip make + harfbuzz autoconf + python2 autoreconf + python3 autoreconf + libxml2-python python + glib autoreconf + graphviz autoreconf + docbook2x autoreconf +" + +DIST_PRE_BUILD="$DIST_PRE_BUILD +# xz mkdir -p build-aux; touch build-aux/config.rpath; mkdir -p po; touch po/Makefile.in.in; sed -i.bak 's/ po / /g' Makefile.am; + getopt sed -i.bak 's/\\\$(LDFLAGS)\\(.*\\)\$/\\1 \$(LDFLAGS)/' Makefile; +# flex-2.6.3 sed -i.bak '/^'\"\$TAB\"'tests \\\\\$/d' Makefile.am; + flex mkdir -p build-aux; touch build-aux/config.rpath; mkdir -p po; touch po/Makefile.in.in; sed -i.bak '/po \\\\$/d' Makefile.am; + python3 sed -i.bak '/-Wl,-stack_size,/d' configure.ac; + libxml2-python cd python; \ + sed -i.bak \"s,^ROOT = .*,ROOT = os.getenv('BUILD_ROOT') + '/root',; s|^\\( *platformLibs = \\[ *[^]].*\\)\\] *\$|\\1, 'lzma', 'iconv', 'intl']|\" setup.py; + bakefile sed -i.bak '/SUBDIRS = doc/d' Makefile.am; + unzip rm -f unix/Contents; ln -sf \$(find unix -mindepth 1 -maxdepth 1) .; + zip rm -f unix/Contents; ln -sf \$(find unix -mindepth 1 -maxdepth 1) .; + expat cd expat; \ + sed -i.bak '/doc\\/Makefile/d' configure.ac; \ + sed -i.bak '/SUBDIRS/{; s/ doc//; }' Makefile.am; \ + sed -i.bak 's/cp \\\$ declspec.h; + harfbuzz touch test/CMakeLists.txt; + xvidcore cd build/generic; \ + sed -i.bak '/^all:/{ s/ *\\\$(SHARED_LIB)//; }; \ + /^install:/{ s, *\\\$(BUILD_DIR)/\\\$(SHARED_LIB),,; }; \ + s/\\\$(INSTALL).*\\\$(SHARED_LIB).*/:/; \ + s/\\\$(LN_S).*\\\$(SHARED_LIB).*/:/; \ + s/@echo.*\\\$(SHARED_LIB).*/@:/; \ + ' Makefile; + libx265 cd source; + libsoxr rm -rf tests; mkdir tests; touch tests/CMakeLists.txt; + XML-SAX sed -i.bak 's/-MXML::SAX/-Mblib -MXML::SAX/' Makefile.PL; + docbook2x sed -i.bak 's/^\\( *SUBDIRS *= *.*\\)doc\\(.*\\)\$/\1\2/' Makefile.am; \ + sed -i.bak 's/^\\( *SUBDIRS *= *.*\\)documentation\\(.*\\)\$/\1\2/' xslt/Makefile.am; +" + +DIST_POST_BUILD="$DIST_POST_BUILD + harfbuzz rebuild_dist freetype --with-harfbuzz=yes; + flex-2.6.3 build_dist flex || :; + glib rebuild_dist gettext --without-included-glib --without-included-libxml; + graphviz (cd '$BUILD_ROOT/root/bin'; path_exists dot_static && ! path_exists dot && ln -sf '$BUILD_ROOT/root/bin/dot_static' ./dot || :) + libxml2 mkdir -p '$BUILD_ROOT/root/etc/xml'; \ + xmlcatalog --noout --create '$BUILD_ROOT/root/etc/xml/catalog.xml' || :; + python2 pip2 install six; + python3 pip3 install six; + fontconfig mkdir -p '$BUILD_ROOT/root/etc/fonts'; \ + touch '$BUILD_ROOT/root/etc/fonts/fonts.conf'; \ + sed -i.bak 's|/usr/share/fonts|$BUILD_ROOT/root/share/fonts|g' '$BUILD_ROOT/root/etc/fonts/fonts.conf' +" + +DIST_POST_CONFIGURE="$DIST_POST_CONFIGURE +" + +DIST_CONFIGURE_OVERRIDES="$DIST_CONFIGURE_OVERRIDES + openssl ./config no-shared --prefix=/usr --openssldir=/etc/ssl + cmake ./configure --prefix=/usr --no-qt-gui + zlib ./configure --static --prefix=/usr + XML-SAX echo no | PERL_MM_USE_DEFAULT=0 perl Makefile.PL + wxwidgets ./configure $REQUIRED_CONFIGURE_ARGS --disable-shared --prefix=/usr --enable-stl --disable-precomp-headers --enable-cxx11 --enable-permissive --with-opengl --with-libpng +" + +DIST_BUILD_OVERRIDES="$DIST_BUILD_OVERRIDES + c2man ./Configure -de -Dprefix=/usr -Dmansrc=/usr/share/man/man1; \ + sed -i.bak 's|/[^ ][^ ]*/libfl\\.[^ ]*|-L$BUILD_ROOT/root/lib -lfl|' Makefile; \ + make -j\$NUM_CPUS; \ + make install bin='$BUILD_ROOT/root/bin' mansrc='$BUILD_ROOT/root/share/man/man1' privlib='$BUILD_ROOT/root/lib/c2man' + libxml2-python python setup.py build install && python3 setup.py build install + setuptools python bootstrap.py; python easy_install.py . + pip easy_install . + ninja python configure.py --bootstrap && cp -af ./ninja '$BUILD_ROOT/root/bin' + docbook4.2 install_docbook_dist schema + docbook4.1.2 cp '$BUILD_ROOT/dists/docbook4.2/catalog.xml' . ; \ + sed -i.bak 's/V4.2/V4.1.2/g; s/4.2/4.1.2/g;' catalog.xml; \ + install_docbook_dist schema + docbook4.3 install_docbook_dist schema + docbook4.4 install_docbook_dist schema + docbook4.5 install_docbook_dist schema + docbook5.0 install_docbook_dist schema + docbook-xsl install_docbook_dist stylesheet + docbook-xsl-ns install_docbook_dist stylesheet + dejavu install_fonts + liberation install_fonts + urw install_fonts +" + +DIST_ARGS="$DIST_ARGS + gettext --with-included-gettext --with-included-glib --with-included-libcroco --with-included-libunistring --with-included-libxml CPPFLAGS=\"\$CPPFLAGS -DLIBXML_STATIC\" + pkgconfig --with-internal-glib --with-libiconv=gnu + pcre --enable-utf8 --enable-pcre8 --enable-pcre16 --enable-pcre32 --enable-unicode-properties --enable-pcregrep-libz --enable-pcregrep-libbz2 --enable-jit + libgd --without-xpm + fontconfig --with-baseconfigdir=/etc/fonts + graphviz --disable-ltdl --without-x CFLAGS=\"-include \$PWD/declspec.h $CFLAGS\" + python2 --with-ensurepip --with-system-expat + python3 --with-ensurepip --with-system-expat + glib --with-libiconv=gnu + bakefile --enable-shared + XML-Parser EXPATINCPATH='$BUILD_ROOT/root/include' EXPATLIBPATH='$BUILD_ROOT/root/lib' + sfml -DSFML_USE_SYSTEM_DEPS=TRUE + freetype --with-harfbuzz=no + harfbuzz --with-cairo=no --with-icu=no + flac --disable-ogg + libvpx --disable-unit-tests --disable-tools --disable-docs --disable-examples + libxavs --disable-asm + libzvbi --without-x + libxml2 --without-python + libbluray --disable-bdjava-jar --disable-examples + libopencore-amrnb --disable-compile-c + vidstab -DUSE_OMP=NO + libx264 --enable-pic + libx265 -DHIGH_BIT_DEPTH=ON -DENABLE_ASSEMBLY=OFF -DENABLE_CLI=OFF + + ffmpeg --pkg-config-flags=--static --enable-nonfree --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-version3 --enable-libass --enable-libbluray --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzmq --enable-openssl --enable-lzma --extra-cflags='-DMODPLUG_STATIC -DZMQ_STATIC' --extra-cxxflags='-DMODPLUG_STATIC -DZMQ_STATIC' --extra-objcflags='-DMODPLUG_STATIC -DZMQ_STATIC' + +# +# TODO: add these if possible (from brew) --enable-indev=qtkit --enable-securetransport --enable-chromaprint --enable-ffplay --enable-frei0r --enable-libbs2b --enable-libcaca --enable-libfdk-aac --enable-libgme --enable-libgsm --enable-librtmp --enable-librubberband --enable-libssh --enable-libtesseract --enable-libtwolame --enable-webp --enable-libzimg +# +# Possibly also: --enable-libzvbi +# I could not get libzvbi to build +# +# these require > 10.7: +# --enable-opencl # requires 10.8 +# --enable-videotoolbox # requires 10.8 +" + + +DIST_BARE_MAKE_ARGS='CC="$CC"' + +DIST_MAKE_ARGS="$DIST_MAKE_ARGS + openssl CC=\"\$CC -fPIC\" + getopt LDFLAGS=\"\$LDFLAGS -lintl -liconv\" CFLAGS=\"\$CFLAGS\" + bzip2 libbz2.a bzip2 bzip2recover CFLAGS=\"\$CFLAGS\" LDFLAGS=\"\$LDFLAGS\" + unzip generic2 + zip generic + expat DOCBOOK_TO_MAN=docbook2man + shared-mime-info -j1 +" + +DIST_MAKE_INSTALL_ARGS="$DIST_MAKE_INSTALL_ARGS + openssl MANDIR=/share/man + libgsm CC=\"\$CC\" +" + +DIST_EXTRA_LDFLAGS="$DIST_EXTRA_LDFLAGS + graphviz -lpcreposix + doxygen -lintl -liconv + ffmpeg -lm -llzma -lpthread +" + +DIST_EXTRA_LIBS="$DIST_EXTRA_LIBS + gettext -liconv + shared-mime-info \$LD_START_GROUP -lxml2 -lgio-2.0 -lgmodule-2.0 -lgobject-2.0 -lglib-2.0 -lpcre -llzma -lz -lm -lffi -lpthread -liconv -lresolv -ldl \$LD_END_GROUP + python3 -lintl + harfbuzz -lz + wxwidgets -ljpeg -ltiff +" + +OIFS=$IFS +NL=' +' +TAB=' ' + + +builder() { + setup + read_command_line "$@" + install_core_deps + setup_perl + delete_outdated_dists + pre_build_all + build_prerequisites + + DOWNLOADED_DISTS= UNPACKED_DISTS= + + download_needed_dists + + unpack_needed_dists $DOWNLOADED_DISTS + build_needed_dists $UNPACKED_DISTS + + build_project +} + +read_command_line() { + case "$1" in + --env) + puts "$BUILD_ENV" + exit 0 + ;; + --clean) + rm -rf "$BUILD_ROOT/dists/*" + unpack_dists + exit 0 + ;; + esac +} + +# overridable hook for other scripts +pre_build_all() { + return 0 +} + +# NOTE: this is called on source at the end of the file + +setup() { + detect_os + + mkdir -p "$BUILD_ROOT/root/include" + [ -L "$BUILD_ROOT/root/inc" ] || ln -s "$BUILD_ROOT/root/include" "$BUILD_ROOT/root/inc" + + mkdir -p "$BUILD_ROOT/root/lib" + + for libarch in lib64 lib32; do + [ -L "$BUILD_ROOT/root/$libarch" ] || ln -s "$BUILD_ROOT/root/lib" "$BUILD_ROOT/root/$libarch" + done + + [ -n "$target_platform" ] && { [ -L "$BUILD_ROOT/root/lib/$target_platform" ] || ln -s "$BUILD_ROOT/root/lib" "$BUILD_ROOT/root/lib/$target_platform"; } + + OPWD=$PWD + cd "$BUILD_ROOT/root" + for d in perl5 share etc man doc; do + [ -d "$d" ] || mkdir "$d" + done + cd "$OPWD" + + DIST_NAMES=$( table_column DISTS 0 3) + DIST_URLS=$( table_column DISTS 1 3) + DIST_TARGETS=$(table_column DISTS 2 3) + + DISTS_NUM=$(table_rows DISTS) + + NUM_CPUS=$(num_cpus) + + BUILD_ENV="$BUILD_ENV +export MAKEFLAGS=-j$NUM_CPUS +" + eval "$BUILD_ENV" + + CHECKOUT=$(find_checkout) + + TMP_DIR=${TMP_DIR:-/tmp/builder-$$} + + setup_tmp_dir + + UNPACK_DIR="$TMP_DIR/unpack" + mkdir "$UNPACK_DIR" + + DISTS_DIR="$BUILD_ROOT/dists" + mkdir -p "$DISTS_DIR" +} + +num_cpus() { + if command -v nproc >/dev/null; then + nproc + return $? + fi + + if path_exists /proc/cpuinfo; then + set -- $(grep '^processor *:' /proc/cpuinfo | wc -l) + puts $1 + return 0 + fi + + if command -v sysctl >/dev/null; then + sysctl -n hw.ncpu + return 0 + fi + + warn 'cannot determine number of CPU threads, using a default of 2' + + puts 2 +} + +setup_perl() { + if command -v perl >/dev/null; then + perl -MApp::cpanminus -le 1 2>/dev/null || perl -MApp::Cpan -e 'App::Cpan->run' -- App::cpanminus + fi +} + +clear_build_env() { + for var in CC CXX CFLAGS CPPFLAGS CXXFLAGS OBJCXXFLAGS LDFLAGS CMAKE_PREFIX_PATH PKG_CONFIG_PATH PERL_MM_USE_DEFAULT PERL_EXTUTILS_AUTOINSTALL OPENSSL_ROOT PERL_MB_OPT PERL_MM_OPT PERL5LIB PERL_LOCAL_LIB_ROOT; do + unset $var + done + export PATH="$ORIG_PATH" +} + +set_build_env() { + eval "$BUILD_ENV" +} + +install_core_deps() { + ${os}_install_core_deps + + # get platform now that we have gcc + detect_os + + # things like ccache may have been installed, re-eval build env + eval "$BUILD_ENV" +} + +installing_core_deps() { + puts "${NL}Installing core dependencies for your OS...${NL}${NL}" +} + +done_msg() { + puts "${NL}Done!!!${NL}${NL}" +} + +unknown_install_core_deps() { + : +} + +linux_install_core_deps() { + # detect host architecture + case "$(uname -a)" in + *x86_64*) + amd64=1 + ;; + *i686*) + i686=1 + ;; + esac + + if [ -f /etc/debian_version ]; then + debian_install_core_deps + elif [ -f /etc/fedora-release ]; then + fedora_install_core_deps + elif [ -f /etc/arch-release ]; then + archlinux_install_core_deps + elif [ -f /etc/solus-release ]; then + solus_install_core_deps + elif path_exists /etc/os-release && [ "$(. /etc/os-release; puts "$ID_LIKE")" = suse ]; then + suse_install_core_deps + fi +} + +debian_install_core_deps() { + installing_core_deps + + sudo apt-get -qq update || : + sudo apt-get -qy install build-essential g++ curl ccache perl + + done_msg +} + +fedora_install_core_deps() { + installing_core_deps + + sudo dnf install -y --nogpgcheck --best --allowerasing gcc gcc-c++ make redhat-rpm-config curl perl ccache file patch findutils +} + +suse_install_core_deps() { + installing_core_deps + + sudo zypper in -y gcc gcc-c++ binutils glibc-devel-static make curl perl ccache file patch +} + +archlinux_install_core_deps() { + installing_core_deps + + # check for gcc-multilib + gcc_pkg=gcc + if sudo pacman -Q gcc-multilib >/dev/null 2>&1; then + gcc_pkg=gcc-multilib + fi + + # update catalogs + sudo pacman -Sy + + # not using the base-devel group because it can break gcc-multilib + sudo pacman --noconfirm --needed -S $gcc_pkg binutils file grep gawk gzip make patch sed util-linux curl ccache perl + + done_msg +} + +solus_install_core_deps() { + installing_core_deps + + sudo eopkg -y update-repo + sudo eopkg -y install -c system.devel curl perl + + done_msg +} + +windows_install_core_deps() { + if [ -n "$msys2" ]; then + msys2_install_core_deps + elif [ -n "$cygwin" ]; then + cygwin_install_core_deps + fi +} + +cygwin_install_core_deps() { + : +} + +msys2_install_core_deps() { + case "$MSYSTEM" in + MINGW32) + target='mingw-w64-i686' + ;; + *) + target='mingw-w64-x86_64' + ;; + esac + + installing_core_deps + + # update catalogs + pacman -Sy + + set -- + for p in binutils curl crt-git gcc gcc-libs gdb headers-git tools-git windows-default-manifest libmangle-git; do + set -- "$@" "${target}-${p}" + done + + # install + # TODO: remove zip and add to dists + pacman --noconfirm --needed -S make tar patch diffutils ccache zip perl m4 msys2-w32api-headers msys2-runtime-devel gcc gcc-libs mpfr windows-default-manifest "$@" + + # make sure msys perl takes precedence over mingw perl if the latter is installed + mkdir -p "$BUILD_ROOT/root/bin" + ln -sf /usr/bin/perl.exe "$BUILD_ROOT/root/bin/perl.exe" + + # activate ccache + eval "$BUILD_ENV" + + done_msg +} + +mac_install_core_deps() { + if ! xcode-select -p >/dev/null 2>&1 && \ + ! pkgutil --pkg-info=com.apple.pkg.CLTools_Executables >/dev/null 2>&1 && \ + ! pkgutil --pkg-info=com.apple.pkg.DeveloperToolsCLI >/dev/null 2>&1; then + + error 'Please install XCode and the XCode Command Line Tools, then run this script again. On newer systems this can be done with: ;xcode-select --install' + fi +} + +setup_tmp_dir() { + # mkdir -m doesn't work on some versions of msys and similar + rm -rf "$TMP_DIR" + if ! ( mkdir -m 700 "$TMP_DIR" 2>/dev/null || mkdir "$TMP_DIR" 2>/dev/null || [ -d "$TMP_DIR" ] ); then + die "Failed to create temporary directory: '$TMP_DIR" + fi + + chmod 700 "$TMP_DIR" 2>/dev/null || : + + trap 'quit $?' EXIT PIPE HUP INT QUIT ILL TRAP KILL BUS TERM +} + +quit() { + cd "$HOME" || : + rm -rf "$TMP_DIR" || : + exit "${1:-0}" +} + +detect_os() { + case "$(uname -s)" in + Linux) + os=linux + ;; + Darwin) + os=mac + ;; + MINGW*|MSYS*) + os=windows + msys2=1 + ;; + CYGWIN*) + os=windows + cygwin=1 + ;; + *) + os=unknown + ;; + esac + + case "$(uname -a)" in + *x86_64*) + bits=64 + ;; + *i686*) + bits=32 + ;; + esac + + target_platform=$($CC -dumpmachine 2>/dev/null) || : + + LD_START_GROUP= LD_END_GROUP= + if ld -v 2>/dev/null | grep -Eq GNU; then + LD_START_GROUP='-Wl,--start-group' + LD_END_GROUP='-Wl,--end-group' + fi +} + +delete_outdated_dists() { + [ ! -d "$BUILD_ROOT/downloads" ] && return 0 + + files= + for current_dist in $DIST_NAMES; do + files="$files $(dist_file "$current_dist")" + done + + IFS=$NL + find "$BUILD_ROOT/downloads" -maxdepth 1 -type f -not -name '.*' | \ + while read -r file; do + IFS=$OIFS + if ! list_contains "$file" $files; then + puts "${NL}Deleting outdated dist archive: $file${NL}${NL}" + rm -f "$file" + + dist_dir="$BUILD_ROOT/dists/${file##*/}" + while [ ! -d "$dist_dir" ]; do + case "$file_dist" in + *-*) + dist_dir=${dist_dir%-*} + ;; + *) + dist_dir= + break + ;; + esac + done + + if [ -n "$dist_dir" ] && [ -d "$dist_dir" ]; then + puts "${NL}Deleting outdated dist unpack dir: $dist_dir${NL}${NL}" + rm -rf "$dist_dir" + fi + fi + done + IFS=$OIFS + + ( + cd "$BUILD_ROOT/dists" + + IFS=$NL + find . -maxdepth 1 -type d -not -name '.*' | \ + while read -r dir; do + IFS=$OIFS + dir=${dir#./} + if ! list_contains "$dir" $DIST_NAMES; then + puts "${NL}Deleting outdated dist unpack dir: $dir${NL}${NL}" + rm -rf "$dir" + fi + done + IFS=$OIFS + ) +} + +build_prerequisites() { + dists_are_installed $PRE_BUILD_DISTS && return 0 + + puts "${NL}Fetching and building prerequisites...${NL}${NL}" + + for current_dist in $PRE_BUILD_DISTS; do + get_dist $current_dist + build_dist_if_needed $current_dist + done + + puts "${NL}Done with prerequisites.${NL}${NL}" +} + +dists_are_installed() { + for current_dist; do + if ! path_exists "$(install_artifact $current_dist)"; then + return 1 + fi + done +} + +download_needed_dists() { + running_jobs= + max_jobs=25 + setup_jobs + job_failed_hook download_failed + for current_dist in $DIST_NAMES; do + if ! path_exists "$(dist_file "$current_dist")"; then + ( + start_job + write_job_info dist_name $current_dist + { + download_dist $current_dist + write_job_exit_status + } 2>&1 | write_job_output + ) & + running_jobs="$running_jobs $!" + + wait_jobs running_jobs $max_jobs + + # FIXME: this should only run on a job_success hook, hooks need to be fixed + DOWNLOADED_DISTS="$DOWNLOADED_DISTS $current_dist" + fi + done + + wait_all_jobs running_jobs + cleanup_jobs +} + +unpack_needed_dists() { + running_jobs= + max_jobs=$NUM_CPUS + setup_jobs + job_failed_hook unpack_failed + for current_dist in $DIST_NAMES; do + if list_contains "$current_dist" "$@" || ! path_exists "$(dist_dir "$current_dist")"; then + ( + start_job + write_job_info dist_name $current_dist + { + unpack_dist $current_dist + write_job_exit_status + } 2>&1 | write_job_output + ) & + running_jobs="$running_jobs $!" + + wait_jobs running_jobs $max_jobs + + # FIXME: this should only run on a job_success hook, hooks need to be fixed + UNPACKED_DISTS="$UNPACKED_DISTS $current_dist" + fi + done + + wait_all_jobs running_jobs + cleanup_jobs +} + +dist_url() { + current_dist=$1 + [ -n "$current_dist" ] || die 'dist_url: dist name required' + + dist_idx=$(list_index $current_dist $DIST_NAMES) + + putsln "$(list_get $dist_idx $DIST_URLS)" +} + +dist_file() { + current_dist=$1 + [ -n "$current_dist" ] || die 'dist_file: dist name required' + + dist_url=$(dist_url "$current_dist") + + dist_file=${dist_url##*/} + + # remove query string stuff + dist_file=${dist_file%\?*} + + putsln "$BUILD_ROOT/downloads/$current_dist-$dist_file" +} + +dist_dir() { + current_dist=$1 + [ -n "$current_dist" ] || die 'dist_dir: dist name required' + + putsln "$BUILD_ROOT/dists/$current_dist" +} + +get_dist() { + current_dist=$1 + [ -n "$current_dist" ] || die 'get_dist: dist name required' + + download_dist "$current_dist" + unpack_dist "$current_dist" +} + +download_dist() { + current_dist=$1 + [ -n "$current_dist" ] || die 'download_dist: dist name required' + + dist_url=$(dist_url "$current_dist") + dist_file=$(dist_file "$current_dist") + dist_dir="$DISTS_DIR/$current_dist" + + mkdir -p "$BUILD_ROOT/downloads" + cd "$BUILD_ROOT/downloads" + + if [ ! -f "$dist_file" ]; then + puts "${NL}Fetching $current_dist: $dist_url${NL}${NL}" + $CURL -SsL "$dist_url" -o "$dist_file" + fi +} + +download_failed() { + job_pid=$1 + + error "Fetching $current_dist failed, check the URL:${NL}${NL}$(cat "$TMP_DIR/job_output/$job_pid")" + + rm -f "$(dist_file "$current_dist")" + + exit 1 +} + +unpack_dist() { + current_dist=$1 + [ -n "$current_dist" ] || die 'unpack_dist: dist name required' + + dist_file=$(dist_file "$current_dist") + dist_dir="$DISTS_DIR/$current_dist" + + if [ ! -f "$dist_file" ]; then + error "unpack_dist: missing dist file fir dist '$current_dist': '$dist_file'" + fi + + puts "${NL}Unpacking $current_dist${NL}${NL}" + rm -rf "$dist_dir" + mkdir "$dist_dir" + + OPWD=$PWD + + unpack_dir="$UNPACK_DIR/$current_dist-$$" + mkdir "$unpack_dir" + cd "$unpack_dir" + + eval "set -- $(dist_tar_args "$current_dist")" + + case "$dist_file" in + *.tar) + $TAR $@ -xf "$dist_file" + ;; + *.tar.gz|*.tgz) + $TAR $@ -zxf "$dist_file" + ;; + *.tar.xz) + xzcat "$dist_file" | $TAR $@ -xf - + ;; + *.tar.bz2) + bzcat "$dist_file" | $TAR $@ -xf - + ;; + *.zip) + unzip -q "$dist_file" + ;; + esac + + if [ $(list_length *) -eq 1 ] && [ -d * ]; then + # one archive dir + cd * + fi + + $TAR -cf - . | (cd "$dist_dir"; $TAR -xf -) + + cd "$TMP_DIR" + rm -rf "$unpack_dir" + + ( + cd "$dist_dir" + dist_post_unpack "$current_dist" + ) + + cd "$OPWD" +} + +unpack_failed() { + job_pid=$1 + + error "Unpacking $current_dist failed:${NL}${NL}$(cat "$TMP_DIR/job_output/$job_pid")" + + rm -rf "$DISTS_DIR/$current_dist" + + exit 1 +} + +setup_jobs() { + rm -rf "$TMP_DIR/job_status" "$TMP_DIR/job_output" + mkdir -p "$TMP_DIR/job_status" "$TMP_DIR/job_output" + _job_failed_hook= +} + +cleanup_jobs() { + rm -rf "$TMP_DIR/job_status" "$TMP_DIR/job_output" + _job_failed_hook= +} + +start_job() { + current_job_pid=$(exec sh -c 'printf "%s" $PPID') +} + +write_job_exit_status() { + _exit_status=$? + putsln "job_exited='$_exit_status'" >> "$TMP_DIR/job_status/$current_job_pid" +} + +write_job_info() { + [ -n "$1" ] || die 'write_job_info: key name required' + putsln "${1}='${2}'" >> "$TMP_DIR/job_status/$current_job_pid" +} + +write_job_output() { + tee -a "$TMP_DIR/job_output/$current_job_pid" +} + +wait_all_jobs() { + [ -n "$1" ] || die 'wait_all_jobs: jobs list var name required' + + while [ "$(eval list_length "\$$1")" -gt 0 ]; do + sleep 0.2 + check_jobs $1 + done +} + +wait_jobs() { + [ -n "$1" ] || die 'limit_jobs: jobs list var name required' + [ -n "$2" ] && [ $2 -ge 0 ] || die 'limit_jobs: max jobs number required' + + while [ "$(eval list_length "\$$1")" -ge $2 ]; do + sleep 0.05 + check_jobs $1 + done +} + +running_jobs() { + alive_list_var=$1 + [ -n "$alive_list_var" ] || die 'running_jobs: alive list variable name required' + reaped_list_var=$2 + [ -n "$reaped_list_var" ] || die 'running_jobs: reaped list variable name required' + + jobs_file="$TMP_DIR/jobs_list.txt" + + jobs -l > "$jobs_file" + + eval "$alive_list_var=" + eval "$reaped_list_var=" + IFS=$NL + # will get pair: + for job in $(sed <"$jobs_file" -n 's/^\[[0-9]\{1,\}\] *[-+]\{0,1\} *\([0-9][0-9]*\) *\([A-Za-z]\{1,\}\).*/\1 \2/p'); do + IFS=$OIFS + set -- $job + pid=$1 state=$2 + + case "$state" in + Stopped) + kill $pid 2>/dev/null || : + eval "$reaped_list_var=\"\$$reaped_list_var $pid\"" + ;; + Running) + eval "$alive_list_var=\"\$$alive_list_var $pid\"" + ;; + esac + done + IFS=$OIFS + + rm -f "$jobs_file" +} + +check_jobs() { + jobs_list_var=$1 + [ -n "$jobs_list_var" ] || die 'check_jobs: jobs list variable name required' + + running_jobs alive reaped + + new_jobs= + for job in $(eval puts \$$jobs_list_var); do + if list_contains $job $alive; then + new_jobs="$new_jobs $job" + else + job_status_file="$TMP_DIR/job_status/$job" + job_output_file="$TMP_DIR/job_output/$job" + + if [ -f "$job_status_file" ]; then + job_exited= + eval "$(cat "$job_status_file")" + + if [ -n "$job_exited" ] && [ "$job_exited" -eq 0 ]; then + rm "$job_status_file" "$job_output_file" + else + current_dist=$dist_name + + error "A job has failed, winding down pending jobs..." + + while [ "$(list_length $alive)" -ne 0 ]; do + for pid in $alive; do + if ! list_contains $pid $last_alive; then + kill $pid 2>/dev/null || : + else + kill -9 $pid 2>/dev/null || : + fi + done + + last_alive=$alive + + sleep 0.2 + + running_jobs alive reaped + done + + # don't want signals to interrupt sleep + trap - PIPE HUP ALRM + + if [ "$os" != windows ]; then + sleep 30 || : + else + # this is painfully slow on msys2/cygwin + warn 'Please wait, this will take a while...' + + sleep 330 || : + fi + + call_job_failed_hook $job + fi + fi + fi + done + + eval "$jobs_list_var=\$new_jobs" +} + +job_failed_hook() { + [ -n "$1" ] || die 'job_failed_hoook: sh function name required' + + _job_failed_hook=$1 +} + +call_job_failed_hook() { + [ -n "$1" ] && [ $1 -gt 0 ] || die 'call_job_failed_hook: job pid required' + + if [ -n "$_job_failed_hook" ]; then + eval $_job_failed_hook '"$@"' + fi +} + +# fall back to 1 second sleeps if fractional sleep is not supported +sleep() { + if ! command sleep "$@" 2>/dev/null; then + sleep_secs=${1%%.*} + [ $# -gt 0 ] && shift + if [ -z "$sleep_secs" ] || [ "$sleep_secs" -lt 1 ]; then + sleep_secs=1 + fi + command sleep $sleep_secs "$@" + fi +} + +build_dists() { + for current_dist; do + build_dist "$current_dist" + BUILT_DISTS="$BUILT_DISTS $current_dist" + done +} + +build_needed_dists() { + for current_dist in $DIST_NAMES; do + if list_contains "$current_dist" "$@"; then + build_dist $current_dist + else + build_dist_if_needed $current_dist + fi + done +} + +build_dist_if_needed() { + current_dist=$1 + [ -n "$current_dist" ] || die 'build_dist_if_needed: dist name required' + shift + + if ! path_exists "$(install_artifact $current_dist)"; then + build_dist $current_dist "$@" + BUILT_DISTS="$BUILT_DISTS $current_dist" + fi +} + +rebuild_dist() { + current_dist=$1 + [ -n "$current_dist" ] || die 'rebuild_dist: dist name required' + shift + + rm -rf "$BUILD_ROOT/dists/$current_dist" + + unpack_dist "$current_dist" + + build_dist "$current_dist" "$@" +} + +build_dist() { + current_dist=$1 + [ -n "$current_dist" ] || die 'build_dist: dist name required' + shift + extra_dist_args=$@ + + cd "$DISTS_DIR/$current_dist" + + puts "${NL}Building $current_dist${NL}${NL}" + + ORIG_LDFLAGS=$LDFLAGS + ORIG_LIBS=$LIBS + + # have to make sure C++ flags are passed when linking, but only for C++ and **NOT** C + # this fails if there are any .c files in the project + if [ "$(find . -name '*.cpp' -o -name '*.cc' | wc -l)" -ne 0 -a "$(find . -name '*.c' | wc -l)" -eq 0 ]; then + export LDFLAGS="$CXXFLAGS $LDFLAGS" + fi + + export LDFLAGS="$LDFLAGS $(eval puts "$(dist_extra_ldflags "$current_dist")")" + export LIBS="$LIBS $(eval puts "$(dist_extra_libs "$current_dist")")" + + dist_patch "$current_dist" + dist_pre_build "$current_dist" + + configure_override=$(dist_configure_override "$current_dist") + install_override=$(dist_install_override "$current_dist") + build_override=$(dist_build_override "$current_dist") + config_type=$(dist_configure_type "$current_dist") + + if [ -n "$build_override" ]; then + eval "set -- $extra_dist_args" + echo_eval_run "$build_override $@" + + path_exists "$(install_artifact $current_dist)" + else + if [ "$config_type" = meson ] || [ -z "$config_type" -a -f meson.build ]; then + mkdir -p build + cd build + + if [ -n "$configure_override" ]; then + eval "set -- $extra_dist_args" + echo_eval_run "$configure_override $@" + else + eval "set -- $(dist_args "$current_dist" meson) $extra_dist_args" + echo_run meson .. "$@" + fi + dist_post_configure "$current_dist" + eval "set -- $(dist_make_args "$current_dist")" + echo_run ninja -j $NUM_CPUS "$@" + + if [ -z "$install_override" ]; then + rm -rf destdir + mkdir destdir + + echo_eval_run 'DESTDIR="$PWD/destdir" ninja '"$(dist_make_install_args "$current_dist")"' install || :' + + install_dist "$current_dist" + else + echo_eval_run "$install_override $(dist_make_install_args "$current_dist")" + fi + + path_exists "$(install_artifact $current_dist)" + elif [ "$config_type" = autoconf -o "$config_type" = autoreconf ] || [ -z "$config_type" -a \( -f configure -o -f Configure -o -f configure.ac -o -f configure.in -o -f Makefile.am \) ]; then + # workaround a sometimes autoconf bug + touch config.rpath + + if [ -n "$configure_override" ]; then + eval "set -- $extra_dist_args" + echo_eval_run "$configure_override $@" + else + autogen= + + if [ "$config_type" = autoreconf ] || [ ! -f configure ]; then + autogen=1 + + if [ -f autogen.sh ]; then + chmod +x autogen.sh + eval "set -- $REQUIRED_CONFIGURE_ARGS $(dist_args "$current_dist" autoconf) $extra_dist_args" + echo_run ./autogen.sh "$@" + elif [ -f buildconf.sh ]; then + chmod +x buildconf.sh + eval "set -- $REQUIRED_CONFIGURE_ARGS $(dist_args "$current_dist" autoconf) $extra_dist_args" + echo_run ./buildconf.sh "$@" + elif [ -f bootstrap ]; then + chmod +x bootstrap + eval "set -- $REQUIRED_CONFIGURE_ARGS $(dist_args "$current_dist" autoconf) $extra_dist_args" + echo_run ./bootstrap "$@" + else + if [ -d m4 ]; then + echo_run aclocal --force -I m4 + else + echo_run aclocal --force + fi + + if command -v glibtoolize >/dev/null; then + echo_run glibtoolize --force + elif command -v libtoolize >/dev/null; then + echo_run libtoolize --force + fi + + echo_run autoheader || : + echo_run autoconf --force + + if command -v gtkdocize >/dev/null; then + echo_run gtkdocize 2>/dev/null || : + fi + + [ -f Makefile.am ] && echo_run automake --foreign --add-missing --copy + fi + fi + + if [ -z "$autogen" ] || ! path_exists config.status; then + if path_exists Configure; then + chmod +x ./Configure + eval "set -- $REQUIRED_CONFIGURE_ARGS $(dist_args "$current_dist" autoconf) $extra_dist_args" + echo_run ./Configure "$@" + else + chmod +x ./configure + eval "set -- $REQUIRED_CONFIGURE_ARGS $(dist_args "$current_dist" autoconf) $extra_dist_args" + echo_run ./configure "$@" + fi + fi + fi + + dist_post_configure "$current_dist" + eval "set -- $(dist_make_args "$current_dist")" + echo_run make -j$NUM_CPUS "$@" + + if [ -z "$install_override" ]; then + rm -rf destdir + mkdir destdir + + eval "set -- $(dist_make_install_args "$current_dist")" + + make_install "$@" + install_dist "$current_dist" + else + echo_eval_run "$install_override $(dist_make_install_args "$current_dist")" + fi + + path_exists "$(install_artifact $current_dist)" + elif [ "$config_type" = cmake ] || [ -z "$config_type" -a -f CMakeLists.txt ]; then + mkdir -p build + cd build + + if [ -n "$configure_override" ]; then + eval "set -- $extra_dist_args" + echo_eval_run "$configure_override $@" + else + eval "set -- $REQUIRED_CMAKE_ARGS $(dist_args "$current_dist" cmake) $extra_dist_args" + echo_run cmake .. "$@" + fi + dist_post_configure "$current_dist" + eval "set -- $(dist_make_args "$current_dist")" + echo_run make -j$NUM_CPUS "$@" + + if [ -z "$install_override" ]; then + rm -rf destdir + mkdir destdir + + eval "set -- $(dist_make_install_args "$current_dist")" + + echo_run make "$@" install DESTDIR="$PWD/destdir" || : + + install_dist "$current_dist" + else + echo_eval_run "$install_override $(dist_make_install_args "$current_dist")" + fi + + path_exists "$(install_artifact $current_dist)" + elif [ "$config_type" = python ] || [ -z "$config_type" -a -f setup.py ]; then + if [ -z "$install_override" ]; then + pip= + if grep -Eq 'Python :: 3' PKG-INFO 2>/dev/null; then + pip=pip3 + fi + if grep -Eq 'Python :: 2' PKG-INFO 2>/dev/null; then + pip="$pip pip2" + fi + + # default to python2 if no package info + [ -z "$pip" ] && pip=pip + + for pip in $pip; do + if [ -n "$configure_override" ]; then + eval "set -- $extra_dist_args" + echo_eval_run "$configure_override $@" + else + eval "set -- $(dist_args "$current_dist" python) $extra_dist_args" + echo_run $pip install . "$@" + fi + done + else + echo_eval_run "$install_override $(dist_make_install_args "$current_dist")" + fi + + path_exists "$(install_artifact $current_dist)" + elif [ "$config_type" = perl ] || [ -z "$config_type" -a -f Makefile.PL ]; then + echo_run cpanm --notest --installdeps . + + if [ -n "$configure_override" ]; then + eval "set -- $extra_dist_args" + echo_eval_run "$configure_override $@" + else + eval "set -- $(dist_args "$current_dist" perl) $extra_dist_args" + echo_run perl Makefile.PL "$@" + fi + + dist_post_configure "$current_dist" + eval "set -- $(dist_make_args "$current_dist")" + echo_run $PERL_MAKE "$@" # dmake doesn't understand -j + + if [ -z "$install_override" ]; then + eval "set -- $(dist_make_install_args "$current_dist")" + echo_run $PERL_MAKE "$@" install || : + else + echo_eval_run "$install_override $(dist_make_install_args "$current_dist")" + fi + + path_exists "$(install_artifact $current_dist)" + elif [ "$config_type" = make ] || [ -z "$config_type" -a \( -f Makefile -o -f makefile \) ]; then + makefile=makefile + if [ -f Makefile ]; then + makefile=Makefile + fi + + eval "set -- $DIST_BARE_MAKE_ARGS $(dist_make_args "$current_dist")" + + echo_run make -j$NUM_CPUS "$@" + + if [ -z "$install_override" ]; then + eval "set -- $(dist_make_install_args "$current_dist")" + + make_install "$@" + + # some bare makefiles just have no DESTDIR mechanism of any sort + if [ -d destdir ]; then + install_dist "$current_dist" + fi + else + echo_eval_run "$install_override $(dist_make_install_args "$current_dist")" + fi + + path_exists "$(install_artifact $current_dist)" + else + die "don't know how to build $current_dist, please define a BUILD_OVERRIDE" + fi + fi + + dist_post_build "$current_dist" + + export LDFLAGS="$ORIG_LDFLAGS" + export LIBS="$ORIG_LIBS" + + done_msg +} + +make_install() { + rm -rf destdir + mkdir -p destdir + cd destdir + + # sometimes make install doesn't try to pre-create the dest dirs + mkdir -p usr/man/man1 usr/man/man3 usr/share/man/man1 usr/share/man/man3 usr/inc usr/include usr/bin usr/lib + + # some dists understand DESTDIR but not combined with prefix + for p in man share inc include bin lib; do + ln -s usr/$p $p + done + + cd .. + + if grep -Eq 'DESTDIR|cmake_install\.cmake' $(find . -name Makefile -o -name makefile -o -name '*.mk' -o -name '*.mak') 2>/dev/null; then + echo_run make install prefix="/usr" PREFIX="/usr" DESTDIR="$PWD/destdir" "$@" || : + else + echo_run make install prefix="$PWD/destdir/usr" PREFIX="$PWD/destdir/usr" INSTALL_PREFIX="$PWD/destdir/usr" INSTALL_ROOT="$PWD/destdir/usr" INSTALLTOP='/../usr/' "$@" || : + fi +} + +# assumes make install has run into ./destdir +install_dist() { + current_dist=$1 + [ -n "$current_dist" ] || die 'install_dist: dist name required' + [ -d destdir ] || die 'install_dist: ./destdir does not exist' + + # if there is an extra prefix, like e.g. 'msys64' on msys2 before 'usr/', + # remove it + if ([ "$(list_length destdir/*)" -eq 1 ] && [ ! -d destdir/usr ]) || \ + ([ "$(list_length destdir/*)" -eq 2 ] && [ "$(find destdir/usr -type f 2>/dev/null | wc -l)" -eq 0 ]); then + mv destdir/*/usr tmp-usr + rm -rf destdir/* + mv tmp-usr destdir/usr + fi + + # move libs out of platforms dirs like lib/x86_64-linux-gnu/ and lib64/ + # and adjust pkgconfig files + + dest_lib_dir='destdir/usr/lib' + + [ -n "$target_platform" ] && dest_platform_lib_dir="$dest_lib_dir/$target_platform" + [ -n "$bits" ] && dest_bits_lib_dir="destdir/usr/lib$bits" + + for platf_dir in "$dest_platform_lib_dir" "$dest_bits_lib_dir"; do + if [ -n "$platf_dir" ] && [ -d "$platf_dir" ]; then + if [ -d "$platf_dir/pkgconfig" ]; then + sed -i.bak "s,lib/$target_platform,lib,g" "$platf_dir/pkgconfig"/*.pc + rm -f "$platf_dir/pkgconfig"/*.pc.bak + fi + + mkdir -p "$dest_lib_dir" + + (cd "$platf_dir"; $TAR -cf - .) | (cd "$dest_lib_dir"; $TAR -xf -) + + rm -rf "$platf_dir" + fi + done + + # copy platform includes to the regular include dirs + IFS=$NL + for platform_inc_dir in $(find "destdir/usr/lib/" -mindepth 2 -maxdepth 2 -type d -name include 2>/dev/null || :); do + IFS=$OIFS + ( + inc_dir=${platform_inc_dir%/*} + inc_dir="destdir/usr/include/${inc_dir##*/}" + + mkdir -p "$inc_dir" + + (cd "$platform_inc_dir"; $TAR -cf - .) | (cd "$inc_dir"; $TAR -xf -) + ) + done + IFS=$OIFS + + # check that key file was built + path_exists "destdir/usr/$(install_artifact_relative "$current_dist")" + + # build file list and sed script to replace file paths in text files and + # scripts + + file_list="$TMP_DIR/file_list_$$.txt" + rm -f "$file_list" + + (cd "destdir"; IFS=$NL; + find usr etc 2>/dev/null | while read -r f; do + IFS=$OIFS + + f=$(normalize_relative_path "$f") + [ -n "$f" ] || continue + + putsln "$f" >> "$file_list" + done) + IFS=$OIFS + [ -f "$file_list" ] + + sed_scr="$TMP_DIR/sed_scr_$$.sed" + sed_scr_usr="$TMP_DIR/sed_scr_usr_$$.sed" + sed_scr_etc="$TMP_DIR/sed_scr_etc_$$.sed" + rm -f "$sed_scr" "$sed_scr_usr "$sed_scr_etc"" + + # build sed script using shortest possible common paths, + # ignoring docs, man and info pages and top level dirs + IFS=$NL + sed ' + /^[^\/]*$/d + /^usr\/man$/d + /^usr\/man\//d + /^usr\/share\/doc$/d + /^usr\/share\/doc\//d + /^usr\/share\/man$/d + /^usr\/share\/man\//d + /^usr\/share\/info$/d + /^usr\/share\/info\//d + /^usr\/[^\/][^\/]*$/d + s|^\(usr/[^/][^/]*/[^/][^/]*\)/[^/].*|\1| + s|^\(etc/[^/][^/]*\)/[^/].*|\1| + ' "$file_list" | sort -u | \ + while read -r f; do + IFS=$OIFS + variants=$f + [ "$f" != "${f%.exe}" ] && variants="$variants ${f%.exe}" + for f in $variants; do + case "$f" in + usr/*) + f=${f#usr/} + cat >>"$sed_scr_usr" <>"$sed_scr_usr" <"${sed_scr}.work" <>"${sed_scr}.work" </dev/null || : + + # rewrite symlinks pointing to /usr/* + if [ -h "$tmp_prefix/$f" ]; then + link_dest=$(expr "$(ls -l "$tmp_prefix/$f")" : '.* -> \(.*\)$' | sed 's|^/usr/|'"$BUILD_ROOT/root/|") + + # rewrite relative links to absolute ones + case "$link_dest" in + /*) + ;; + *) + link_dest="$PWD/${dest_f%/*}/$link_dest" + ;; + esac + + if [ -e "$link_dest" ]; then + echo_run ln -sf "$link_dest" "$dest_f" + else + # this is for windows as well, where symlinks can't point to a + # file that doesn't (yet) exist + defer_cmds="$defer_cmds +ln -sf \"$link_dest\" \"$dest_f\" +" + fi + continue + fi + + # don''t relocate headers, man and info pages and docs + case "$dest_f" in + share/doc/*|share/man/*|share/info/*|include/*) + echo_run cp -af "$tmp_prefix/$f" "$dest_f" + continue + ;; + esac + + if file "$tmp_prefix/$f" | grep -Eiq ':.*text'; then + ( + start_job + write_job_info dist_name "$current_dist" + write_job_info file_name "$tmp_prefix/$f" + + if [ -x "$tmp_prefix/$f" ]; then + putsln "Relocating executable script: $dest_f" + else + putsln "Relocating text file: $dest_f" + fi + + { + LANG=C sed -f "$sed_scr" "$tmp_prefix/$f" >"$dest_f" + + # rewrite prefix in pkgconfig and libtool files + case "$dest_f" in + lib/*.l[ao]|lib/pkgconfig/*.pc|share/pkgconfig/*.pc) + cp "$dest_f" "${dest_f}.work" + LANG=C sed ' + /\/usr/{ + s|\([^a-zA-Z0-9]\)/usr$|\1'"$BUILD_ROOT/root"'| + s|\([^a-zA-Z0-9]\)/usr/|\1'"$BUILD_ROOT/root/"'|g + s|\(-[IL]\)/usr/|\1'"$BUILD_ROOT/root/"'|g + } + ' "${dest_f}.work" > "$dest_f" + rm -f "${dest_f}.work" + ;; + esac + } 2>&1 | write_job_output + write_job_exit_status + + if [ -x "$tmp_prefix/$f" ]; then chmod +x "$dest_f" ; fi + ) & + running_jobs="$running_jobs $!" + + wait_jobs running_jobs $max_jobs + + continue + fi + + echo_run cp -af "$tmp_prefix/$f" "$dest_f" + done + IFS=$OIFS + + wait_all_jobs running_jobs + cleanup_jobs + + IFS=$NL + for cmd in $defer_cmds; do + IFS=$OIFS + eval echo_run "$cmd" + done + IFS=$OIFS + + cd "$OLDPWD" + + rm -f "$file_list" "$sed_scr" + + # things in build env may depend on what was just installed + eval "$BUILD_ENV" + + # find new things in PATH + hash -r +} + +relocation_failed() { + error "Relocating file '$file_name' from '$current_dist' failed:${NL}${NL}$(cat "$TMP_DIR/job_output/$1")" + + exit 1 +} + +normalize_relative_path() { + p=$1 + [ -n "$p" ] || die 'normalize_relative_path: path required' + + p=${p#.} + + while :; do + case "$p" in + /*) + p=${p#/} + ;; + */) + p=${p%/} + ;; + *) + break + ;; + esac + done + + putsln "$p" +} + +echo_run() { + putsln "Executing: $(cmd_with_quoted_args "$@")" + "$@" +} + +echo_eval_run() { + putsln "Executing: $@" + eval "$@" +} + +cmd_with_quoted_args() { + [ -n "$1" ] || error 'cmd_with_quoted_args: command required' + res="$1 " + shift + for arg; do + res="$res '$arg'" + done + puts "$res" +} + +remove_drive_prefix() { + path=$1 + [ -n "$path" ] || die 'remove_drive_prefix: path required' + + if [ -n "$msys2" ]; then + path=${path#/[a-zA-Z]/} + elif [ -n "$cygwin" ]; then + path=${path#/cygdrive/[a-zA-Z]/} + fi + + # remove windows drive prefixes such as c: + path=${path#[a-zA-Z]:} + + # remove all but one slash at the beginning (double slashes have special meaning on windows) + while :; do + case "$path" in + /*) + path=${path#/} + ;; + *) + break + ;; + esac + done + + puts "/$path" +} + +list_get() { + pos=$1 + [ -n "$pos" ] || die 'list_get: position to retrieve required' + shift + + i=0 + for item; do + if [ $i -eq $pos ]; then + puts "$item" + return 0 + fi + + i=$((i + 1)) + done +} + +list_index() { + item=$1 + [ -n "$item" ] || die 'list_index: item to find required' + shift + + i=0 + for element; do + if [ "$element" = "$item" ]; then + puts $i + return 0 + fi + + i=$((i + 1)) + done + + return 1 +} + +dist_args() { + current_dist=$1 + [ -n "$current_dist" ] || die 'dist_args: dist name required' + buildsys=$2 + + case "$buildsys" in + autoconf) + puts "$CONFIGURE_ARGS $(table_line DIST_ARGS $current_dist)" || : + ;; + cmake) + puts "$CMAKE_ARGS $(table_line DIST_ARGS $current_dist)" || : + ;; + meson) + puts "$MESON_ARGS $(table_line DIST_ARGS $current_dist)" || : + ;; + perl) + puts "$(table_line DIST_ARGS $current_dist)" || : + ;; + python) + puts "$(table_line DIST_ARGS $current_dist)" || : + ;; + *) + die "dist_args: buildsystem type required, must be 'autoconf', 'cmake' or 'perl'" + ;; + esac +} + +dist_tar_args() { + current_dist=$1 + [ -n "$current_dist" ] || die 'dist_tar_args: dist name required' + + puts "$(table_line DIST_TAR_ARGS $current_dist)" || : +} + +dist_configure_override() { + current_dist=$1 + [ -n "$current_dist" ] || die 'dist_configure_override: dist name required' + + puts "$(table_line DIST_CONFIGURE_OVERRIDES $current_dist)" || : +} + +dist_install_override() { + current_dist=$1 + [ -n "$current_dist" ] || die 'dist_install_override: dist name required' + + puts "$(table_line DIST_INSTALL_OVERRIDES $current_dist)" || : +} + +dist_build_override() { + current_dist=$1 + [ -n "$current_dist" ] || die 'dist_build_override: dist name required' + + puts "$(table_line DIST_BUILD_OVERRIDES $current_dist)" || : +} + +dist_configure_type() { + current_dist=$1 + [ -n "$current_dist" ] || die 'dist_configure_type: dist name required' + + puts "$(table_line DIST_CONFIGURE_TYPES $current_dist)" || : +} + +dist_make_args() { + current_dist=$1 + [ -n "$current_dist" ] || die 'dist_make_args: dist name required' + + puts "$(table_line DIST_MAKE_ARGS $current_dist)" || : +} + +dist_make_install_args() { + current_dist=$1 + [ -n "$current_dist" ] || die 'dist_make_install_args: dist name required' + + puts "$(table_line DIST_MAKE_INSTALL_ARGS $current_dist)" || : +} + +dist_extra_ldflags() { + current_dist=$1 + [ -n "$current_dist" ] || die 'dist_extra_ldflags: dist name required' + + puts "$(table_line DIST_EXTRA_LDFLAGS $current_dist)" || : +} + +dist_extra_libs() { + current_dist=$1 + [ -n "$current_dist" ] || die 'dist_extra_libs: dist name required' + + puts "$(table_line DIST_EXTRA_LIBS $current_dist)" || : +} + +dist_patch() { + current_dist=$1 + [ -n "$current_dist" ] || die 'dist_patch: dist name required' + + for _patch_url in $(table_line DIST_PATCHES $current_dist); do + _patch_file=${_patch_url##*/} + _patch_file=${_patch_file%%\?*} + + if [ ! -f "$_patch_file" ]; then + puts "${NL}Applying patch $_patch_url to $current_dist${NL}${NL}" + + $CURL -SsL "$_patch_url" -o "$_patch_file" + patch -l -p1 < "$_patch_file" + fi + + done_msg + done +} + +dist_pre_build() { + current_dist=$1 + [ -n "$current_dist" ] || die 'dist_pre_build: dist name required' + + if _cmd=$(table_line DIST_PRE_BUILD $current_dist); then + puts "${NL}Running pre-build for: $current_dist:${NL}$_cmd${NL}${NL}" + + eval "$_cmd" + fi +} + +dist_post_unpack() { + current_dist=$1 + [ -n "$current_dist" ] || die 'dist_post_unpack: dist name required' + + if _cmd=$(table_line DIST_POST_UNPACK $current_dist); then + puts "${NL}Running post-unpack for: $current_dist:${NL}$_cmd${NL}${NL}" + + eval "$_cmd" + fi +} + +dist_post_configure() { + current_dist=$1 + [ -n "$current_dist" ] || die 'dist_post_configure: dist name required' + + if _cmd=$(table_line DIST_POST_CONFIGURE $current_dist); then + puts "${NL}Running post-configure for: $current_dist:${NL}$_cmd${NL}${NL}" + + eval "$_cmd" + fi +} + +dist_post_build() { + current_dist=$1 + [ -n "$current_dist" ] || die 'dist_post_build: dist name required' + + if _cmd=$(table_line DIST_POST_BUILD $current_dist); then + puts "${NL}Running post-build for: $current_dist:${NL}$_cmd${NL}${NL}" + + eval "$_cmd" + fi +} + +install_docbook_dist() { + _type=$1 + + _dist_ver=$(echo "$PWD" | sed 's/.*[^0-9.]\([0-9.]*\)$/\1/') + + case "$_type" in + stylesheet) + _dir="stylesheet/${PWD##*/}" + ;; + schema) + _dir="schema/dtd/$_dist_ver" + ;; + *) + die "install_docbook_dist: type of dist required, must be 'stylesheet' or 'schema'" + ;; + esac + + _dir="$BUILD_ROOT/root/share/xml/docbook/$_dir" + + # on cygwin/msys write native POSIX paths to catalog + if command -v cygpath >/dev/null; then + _dir=$(cygpath -m "$_dir") + fi + + echo_run mkdir -p "$_dir" + echo_run cp -af * "$_dir" + + if [ -f "$_dir/catalog.xml" ]; then + echo_run xmlcatalog --noout --del "file://$_dir/catalog.xml" "$BUILD_ROOT/root/etc/xml/catalog.xml" || : + echo_run xmlcatalog --noout --add nextCatalog '' "file://$_dir/catalog.xml" "$BUILD_ROOT/root/etc/xml/catalog.xml" + fi +} + +install_fonts() { + if [ -d fontconfig ]; then + install -v -m644 fontconfig/*.conf "$BUILD_ROOT/root/etc/fonts/conf.d" + fi + + font_found= + IFS=$NL + for ttf in $(find . -name '*.ttf' -o -name '*.TTF' -o -name '*.pfm' -o -name '*.PFM' -o -name '*.pfb' -o -name '*.PFB' -o -name '*.afb' -o -name '*.AFB'); do + IFS=$OIFS + font_found=1 + if [ ! -d "$BUILD_ROOT/root/share/fonts/${PWD##*/}" ]; then + install -v -d -m755 "$BUILD_ROOT/root/share/fonts/${PWD##*/}" + fi + install -v -m644 "$ttf" "$BUILD_ROOT/root/share/fonts/${PWD##*/}" + done + IFS=$OIFS + + [ -n "$font_found" ] && echo_run fc-cache -fv "$BUILD_ROOT/root/share/fonts/${PWD##*/}" +} + +table_line() { + table=$1 + [ -n "$table" ] || die 'table_line: table name required' + name=$2 + [ -n "$name" ] || die 'table_line: item name required' + + table=$(table_contents $table) + + IFS=$NL + for line in $table; do + IFS=$OIFS + set -- $line + if [ "$1" = "$name" ]; then + shift + puts "$@" + return 0 + fi + done + IFS=$OIFS + + return 1 +} + +table_line_append() { + table=$1 + [ -n "$table" ] || die 'table_line_append: table name required' + name=$2 + [ -n "$name" ] || die 'table_line_append: item name required' + append_str=$3 + [ -n "$append_str" ] || die 'table_line_append: string to append required' + + table_name=$table + table=$(table_contents $table) + + new_table= + line_appended= + IFS=$NL + for line in $table; do + IFS=$OIFS + set -- $line + if [ "$1" = "$name" ]; then + new_table="${new_table}$@ ${append_str}${NL}" + line_appended=1 + else + new_table="${new_table}${@}${NL}" + fi + done + IFS=$OIFS + + if [ -z "$line_appended" ]; then + # make new entry + new_table="${new_table}${name} ${append_str}${NL}" + fi + + eval "$table_name=\$new_table" +} + +table_line_replace() { + table=$1 + [ -n "$table" ] || die 'table_line_replace: table name required' + name=$2 + [ -n "$name" ] || die 'table_line_replace: item name required' + set_str=$3 + [ -n "$set_str" ] || die 'table_line_replace: string to set required' + + table_name=$table + table=$(table_contents $table) + + new_table= + line_found= + IFS=$NL + for line in $table; do + IFS=$OIFS + set -- $line + if [ "$1" = "$name" ]; then + new_table="${new_table}$1 ${set_str}${NL}" + line_found=1 + else + new_table="${new_table}${@}${NL}" + fi + done + IFS=$OIFS + + if [ -z "$line_found" ]; then + # make new entry + new_table="${new_table}${name} ${set_str}${NL}" + fi + + eval "$table_name=\$new_table" +} + +table_insert_after() { + table=$1 + [ -n "$table" ] || die 'table_insert_after: table name required' + name=$2 + [ -n "$name" ] || die 'table_insert_after: item name to insert after required' + new_line=$3 + [ -n "$new_line" ] || die 'table_insert_after: new line required' + + table_name=$table + table=$(table_contents $table) + + new_table= + line_found= + IFS=$NL + for line in $table; do + IFS=$OIFS + set -- $line + new_table="${new_table}${@}${NL}" + + if [ "$1" = "$name" ]; then + new_table="${new_table}${new_line}${NL}" + line_found=1 + fi + done + IFS=$OIFS + + [ -n "$line_found" ] || error 'table_insert_after: item to insert after not found' + + eval "$table_name=\$new_table" +} + +table_insert_before() { + table=$1 + [ -n "$table" ] || die 'table_insert_before: table name required' + name=$2 + [ -n "$name" ] || die 'table_insert_before: item name to insert before required' + new_line=$3 + [ -n "$new_line" ] || die 'table_insert_before: new line required' + + table_name=$table + table=$(table_contents $table) + + new_table= + line_found= + IFS=$NL + for line in $table; do + IFS=$OIFS + set -- $line + + if [ "$1" = "$name" ]; then + new_table="${new_table}${new_line}${NL}" + line_found=1 + fi + + new_table="${new_table}${@}${NL}" + done + IFS=$OIFS + + [ -n "$line_found" ] || die 'table_insert_before: item to insert before not found' + + eval "$table_name=\$new_table" +} + +table_line_remove() { + table=$1 + [ -n "$table" ] || die 'table_line_remove: table name required' + name=$2 + [ -n "$name" ] || die 'table_line_remove: item name required' + + table_name=$table + table=$(table_contents $table) + + new_table= + IFS=$NL + for line in $table; do + IFS=$OIFS + set -- $line + if [ "$1" != "$name" ]; then + new_table="${new_table}${@}${NL}" + fi + done + IFS=$OIFS + + eval "$table_name=\$new_table" +} + +find_checkout() { + ( + cd "$(dirname "$0")" + while [ "$PWD" != / ]; do + if [ -f src/version.h.in ]; then + puts "$PWD" + exit 0 + fi + + cd .. + done + exit 1 + ) || die 'cannot find project checkout' +} + +error() { + puts >&2 "${NL}ERROR: $@${NL}${NL}" +} + +warn() { + puts >&2 "${NL}WARNING: $@${NL}${NL}" +} + +die() { + error "$@" + exit 1 +} + +build_project() { + puts "${NL}Building project: $CHECKOUT${NL}${NL}" + + mkdir -p "$BUILD_ROOT/project" + cd "$BUILD_ROOT/project" + + eval "set -- $CMAKE_BASE_ARGS" + # FIXME: turn LTO back on when everything works + echo_eval_run "cmake '$CHECKOUT' $REQUIRED_CMAKE_ARGS -DVBAM_STATIC=ON -DENABLE_FFMPEG=OFF -DENABLE_LTO=OFF $PROJECT_ARGS $@" + echo_run make -j$NUM_CPUS + + if [ "$os" = mac ]; then + 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 + fi + + puts "${NL}Build Successful!!!${NL}${NL}Build results can be found in: $BUILD_ROOT/project${NL}${NL}" +} + +duplicate_dist() { + src_dist=$1 + [ -n "$src_dist" ] || die 'duplicate_dist: source dist required' + dest_dist=$2 + [ -n "$dest_dist" ] || die 'duplicate_dist: destination dist required' + + IFS=$NL + for table in DISTS $(set | sed -n 's/^\(DIST_[A-Z_]*\)=.*/\1/p'); do + IFS=$OIFS + if line=$(table_line $table $src_dist); then + table_insert_after $table $src_dist "$dest_dist $line" + fi + done + IFS=$OIFS +} + +table_column() { + table=$1 + [ -n "$table" ] || die 'table_column: table name required' + col=$2 + [ -n "$col" ] || die 'table_column: column required' + row_size=$3 + [ -n "$row_size" ] || die 'table_column: row_size required' + + table=$(table_contents $table) + + i=0 + res= + for item in $table; do + if [ $((i % row_size)) -eq "$col" ]; then + res="$res $item" + fi + i=$((i + 1)) + done + + puts "$res" +} + +table_rows() { + table=$1 + [ -n "$table" ] || die 'table_rows: table name required' + + table=$(table_contents $table) + + i=0 + IFS=$NL + for line in $table; do + i=$((i + 1)) + done + IFS=$OIFS + + puts $i +} + +table_contents() { + table=$1 + [ -n "$table" ] || die 'table_contents: table name required' + + # filter comments and blank lines + eval puts "\"\$$table\"" | grep -Ev '^ *(#|$)' || : +} + +list_contains() { + _item=$1 + [ -n "$_item" ] || die 'list_contains: item required' + shift + + for _pos; do + [ "$_item" = "$_pos" ] && return 0 + done + + return 1 +} + +list_length() { + puts $# +} + +install_artifact() { + current_dist=$1 + [ -n "$current_dist" ] || die 'install_artifact: dist name required' + + set -- $(table_line DISTS $current_dist) + + eval "path=\"\$$#\"" + + # for cross builds, the files are absolute paths into the host and target + # trees + case "$path" in + /*) + puts "$path" + return 0 + ;; + esac + + puts "$BUILD_ROOT/root/$path" +} + +install_artifact_relative() { + current_dist=$1 + [ -n "$current_dist" ] || die 'install_artifact_relative: dist name required' + + set -- $(table_line DISTS $current_dist) + + eval "path=\"\$$#\"" + + # for cross builds, the files are absolute paths into the host and target + # trees + puts "$path" | sed 's, *'"$BUILD_ROOT"'/[^/]*/,,' +} + +echo() { + if [ -n "$BASH_VERSION" -a "$os" != mac ]; then + builtin echo -e "$@" + else + command echo "$@" + fi +} + +puts() { + [ $# -gt 0 ] || return 0 + + printf '%s' "$1" + shift + + for _str; do + printf ' %s' "$_str" + done +} + +putsln() { + puts "$@" + printf '\n' +} + +path_exists() { + [ -z "$1" ] && return 1 + # check unquoted versions in case of globs + [ -e "$1" ] || [ -L "$1" ] || [ -d "$1" ] || [ -e $1 ] || [ -L $1 ] || [ -d $1 ] +} + +# on msys2 `ln -sf` to an existing link silently fails +# so delete it first +ln() { + if [ $# -eq 3 ] && [ "$1" = "-sf" ] && [ -h "$3" ]; then + rm -f "$3" + fi + command ln "$@" +} + +# this needs to run on source, not just after entry +setup diff --git a/tools/builder/mingw.sh b/tools/builder/mingw.sh new file mode 100644 index 00000000..eeb708be --- /dev/null +++ b/tools/builder/mingw.sh @@ -0,0 +1,230 @@ +#!/bin/sh + +set -e + +[ -n "$BUILD_ENV" ] && eval "$BUILD_ENV" + +BUILD_ENV=$BUILD_ENV$(cat <, *$/\1.exe>,/; }' perl/config.pl;" + +table_line_append DIST_ARGS libsoxr '-DWITH_OPENMP=NO' + +table_line_append DIST_ARGS ffmpeg "--extra-ldflags='-Wl,-allow-multiple-definition' --extra-libs='-lwsock32 -lws2_32 -liphlpapi -lfreetype'" + +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 \ +" + +table_line_append DIST_PATCHES graphite2 "\ + https://raw.githubusercontent.com/Alexpux/MINGW-packages/master/mingw-w64-graphite2/001-graphite2-1.3.8-win64.patch \ +" + +table_line_append DIST_PATCHES libgsm "\ + https://raw.githubusercontent.com/Alexpux/MINGW-packages/master/mingw-w64-gsm/0001-adapt-makefile-to.mingw.patch \ + https://raw.githubusercontent.com/Alexpux/MINGW-packages/master/mingw-w64-gsm/0002-adapt-config-h-to.mingw.patch \ + https://raw.githubusercontent.com/Alexpux/MINGW-packages/master/mingw-w64-gsm/0003-fix-ln.mingw.patch \ +" + +table_line_append DIST_PATCHES libtheora "\ + http://src.fedoraproject.org/cgit/rpms/mingw-libtheora.git/plain/mingw-libtheora-1.1.1-rint.patch?id=a35cf93c3068ed4c8a59691a3cf129766d875444 \ +" + +table_line_append DIST_PRE_BUILD wxwidgets ":; \ + if path_exists $BUILD_ROOT/root/include/langinfo.h; then \ + mv $BUILD_ROOT/root/include/langinfo.h $BUILD_ROOT/root/include/langinfo.bak; \ + fi; +" + +table_line_append DIST_POST_BUILD wxwidgets ":; \ + if path_exists $BUILD_ROOT/root/include/langinfo.bak; then \ + mv $BUILD_ROOT/root/include/langinfo.bak $BUILD_ROOT/root/include/langinfo.h; \ + fi; +" diff --git a/tools/builder/unix.sh b/tools/builder/unix.sh new file mode 100644 index 00000000..fc264b31 --- /dev/null +++ b/tools/builder/unix.sh @@ -0,0 +1,170 @@ +set -e + +: ${BUILD_ROOT:=$HOME/vbam-build-unix} + +BUILD_ENV=$BUILD_ENV$(cat </dev/null; then - glibtoolize - else - libtoolize - fi - - autoheader || : - autoconf - [ -e Makefile.am ] && automake --add-missing - fi - fi - - eval "set -- $(dist_args "$dist" autoconf) $extra_dist_args" - ./configure "$@" - eval "set -- $(dist_make_args "$dist")" - make -j$NUM_CPUS "$@" - make install prefix=$BUILD_ROOT/root - elif [ -e CMakeLists.txt ]; then - mkdir -p build - cd build - - eval "set -- $(dist_args "$dist" cmake) $extra_dist_args" - cmake .. "$@" - eval "set -- $(dist_make_args "$dist")" - make -j$NUM_CPUS "$@" - rm -rf destdir - mkdir destdir - make install DESTDIR="$PWD/destdir" - - cd "destdir/$BUILD_ROOT/root" - OLDPWD=$PWD - find . ! -type d | (cd "$BUILD_ROOT/root";IFS=' -'; while read f; do - mkdir -p "${f%/*}" - cp -a "$OLDPWD/$f" "$f" - done) - elif [ -e Makefile.PL ]; then - eval "set -- $(dist_args "$dist" perl) $extra_dist_args" - perl Makefile.PL "$@" - eval "set -- $(dist_make_args "$dist")" - make -j$NUM_CPUS "$@" - make install - elif [ -e Makefile ]; then - eval "set -- $(dist_make_args "$dist")" - make -j$NUM_CPUS "$@" - make install PREFIX="$BUILD_ROOT/root" INSTALL_ROOT="$BUILD_ROOT/root" +# bash 3 does not work for this code +if [ -z "$IN_DASH" ]; then + if command -v dash >/dev/null; then + export IN_DASH=1 + exec dash "$0" "$@" else - error "don't know how to build $dist" - fi - - dist_post_build "$dist" - - export LDFLAGS=$ORIG_LDFLAGS - - echo "\nDone!!!\n" -} - -list_get() { - i=0 - n=${1:=0} - shift - - for item; do - if [ $i -eq $n ]; then - echo "$item" - return 0 - fi - - i=$((i + 1)) - done -} - -dist_args() { - dist=$1 - [ -n "$dist" ] || error 'dist_args: dist name required' - buildsys=$2 - case "$buildsys" in - autoconf|cmake|perl) - ;; - *) - error "dist_args: buildsystem type required, must be 'autoconf', 'cmake' or 'perl'" - ;; - esac - - args=$(table_line "$dist" "$DIST_OVERRIDES") - - if [ -z "$args" ]; then - case "$buildsys" in - autoconf) - args="$CONFIGURE_ARGS $(table_line "$dist" "$DIST_ARGS")" - ;; - cmake) - args="$CMAKE_ARGS $(table_line "$dist" "$DIST_ARGS")" - ;; - perl) - args="$(table_line "$dist" "$DIST_ARGS")" - ;; - esac - fi - - echo "$args" - - return 0 -} - -dist_make_args() { - dist=$1 - [ -n "$dist" ] || error 'dist_make_args: dist name required' - - echo "$(table_line "$dist" "$DIST_MAKE_ARGS")" - - return 0 -} - -dist_patch() { - [ -n "$1" ] || error 'dist_patch: dist name required' - - _patch_url="$(table_line "$1" "$DIST_PATCHES")" - - [ -n "$_patch_url" ] || return 0 - - echo "\nApplying patch $_patch_url to $1\n" - - curl -LO "$_patch_url" - patch -p1 < "${_patch_url##*/}" - - echo "\nDone!!!\n" -} - -dist_pre_build() { - [ -n "$1" ] || error 'dist_pre_build: dist name required' - - _cmd=$(table_line "$1" "$DIST_PRE_BUILD") - [ -n "$_cmd" ] || return 0 - - echo "\nRunning pre-build for: $dist:\n$_cmd\n" - - eval "$_cmd" -} - -dist_post_build() { - [ -n "$1" ] || error 'dist_post_build: dist name required' - - _cmd=$(table_line "$1" "$DIST_POST_BUILD") - [ -n "$_cmd" ] || return 0 - - if [ -z "$IN_DIST_POST_BUILD" ]; then - IN_DIST_POST_BUILD=1 - - echo "\nRunning post-build for: $dist:\n$_cmd\n" - - eval "$_cmd" - - IN_DIST_POST_BUILD= - fi -} - -table_line() { - name=$1 - [ -n "$name" ] || error 'item name required' - table=$2 - [ -n "$table" ] || error 'table string required' - - table=$(echo "$table" | grep -Ev '^ *#') - - OLDIFS=$IFS - IFS=' -' - for line in $table; do - IFS=$OLDIFS - set -- $line - if [ "$1" = "$name" ]; then - shift - echo "$@" - return 0 - fi - done - - IFS=$OLDIFS -} - -find_checkout() { - ( - cd "$(dirname "$0")" - while [ "$PWD" != / ]; do - if [ -e src/version.h.in ]; then - echo "$PWD" - exit 0 - fi - - cd .. - done + echo >&2 "please install dash from homebrew or macports to run this script" exit 1 - ) || error 'cannot find project checkout' -} + fi +fi -error() { - printf >&2 '\nERROR: %s\n\n' "$1" - [ -z "$2" ] && exit 1 -} +BUILD_ROOT=$HOME/vbam-build-mac -build_project() { - echo "\nBuilding project: $CHECKOUT\n" +BUILD_ENV=$(cat <<'EOF' +export MACOSX_DEPLOYMENT_TARGET=10.7 +export CC=clang +export CXX=clang++ +export CPPFLAGS="-DICONV_CONST=" +export CFLAGS="-framework Carbon -framework Foundation -framework CoreServices -arch x86_64 -Wno-unused-command-line-argument -DICONV_CONST=" +export CXXFLAGS="-stdlib=libc++ -framework Carbon -framework Foundation -framework CoreServices -arch x86_64 -Wno-unused-command-line-argument -DICONV_CONST=" +export OBJCXXFLAGS="-stdlib=libc++ -framework Carbon -framework Foundation -framework CoreServices -arch x86_64 -Wno-unused-command-line-argument -DICONV_CONST=" +export LDFLAGS="-framework Carbon -framework Foundation -framework CoreServices -arch x86_64 -Wno-unused-command-line-argument" +EOF +) - mkdir -p "$BUILD_ROOT/project" - cd "$BUILD_ROOT/project" +TAR=tar - cmake "$CHECKOUT" -DCMAKE_PREFIX_PATH="$BUILD_ROOT/root" -DCMAKE_BUILD_TYPE=Release -DSFML_STATIC_LIBRARIES=TRUE -DENABLE_FFMPEG=ON -DFFMPEG_STATIC=TRUE - make -j$NUM_CPUS +. "$(dirname "$0")/../builder/core.sh" - codesign -s "Developer ID Application" --deep ./visualboyadvance-m.app || : +table_line_remove DISTS flex +table_line_remove DISTS libsecret - rm -f ./visualboyadvance-m-Mac.zip - zip -9r ./visualboyadvance-m-Mac.zip ./visualboyadvance-m.app +table_line_replace DIST_CONFIGURE_OVERRIDES openssl './Configure darwin64-x86_64-cc no-shared --prefix=/usr --openssldir=/etc/ssl' - echo "\nBuild Successful!!!\n\nBuild results can be found in: $BUILD_ROOT/project\n" -} +table_line_replace DIST_CONFIGURE_TYPES libmodplug autoreconf +table_line_append DIST_PRE_BUILD libmodplug " \ + sed -i.bak '/-mmacosx-version-min=/d' configure.ac; \ + sed -i.bak 's/-lstdc++/-lc++/g' libmodplug.pc.in; \ +" -table_column() { - col=$1 - [ -n "$col" ] || error 'table_column: column required' - row_size=$2 - [ -n "$row_size" ] || error 'table_column: row_size required' - table=$3 - [ -n "$table" ] || error 'table_column: table required' +table_line_append DIST_PRE_BUILD libzmq "sed -i.bak 's/-lstdc++/-lc++/g' src/libzmq.pc.in" +table_line_append DIST_PRE_BUILD ffmpeg "sed -i.bak 's/-lstdc++/-lc++/g' configure" - table=$(echo "$table" | grep -Ev '^ *#') +table_line_append DIST_ARGS wxwidgets "--with-macosx-version-min=$MACOSX_DEPLOYMENT_TARGET LDFLAGS='$LDFLAGS -stdlib=libc++'" +table_line_append DIST_ARGS ffmpeg "--disable-videotoolbox --extra-ldflags='-framework CoreText'" +table_line_append DIST_ARGS libmodplug "CC=clang++ CXX=clang++" - i=0 - res= - for item in $table; do - if [ $((i % row_size)) -eq "$col" ]; then - res="$res $item" - fi - i=$((i + 1)) - done - - echo $res - - return 0 -} - -table_rows() { - table=$1 - [ -n "$table" ] || error 'table_rows: table required' - - table=$(echo "$table" | grep -Ev '^ *#') - - i=0 - OLDIFS=$IFS - IFS=' -'; for line in $table; do - i=$((i + 1)) - done - IFS=$OLDIFS - - echo $i - - return 0 -} - -list_contains() { - _item=$1 - [ -n "$_item" ] || error 'list_contains: item required' - shift - - for _pos; do - [ "$_item" = "$_pos" ] && return 0 - done - - return 1 -} - -main "$@" +builder "$@" diff --git a/tools/unix/builder b/tools/unix/builder new file mode 100755 index 00000000..d2de211c --- /dev/null +++ b/tools/unix/builder @@ -0,0 +1,11 @@ +#!/bin/sh + +set -e + +BUILD_ROOT=$HOME/vbam-build-unix + +. "$(dirname "$0")/../builder/core.sh" + +table_line_append DIST_ARGS glib '--disable-libmount' + +builder "$@" diff --git a/tools/win/builder b/tools/win/builder deleted file mode 100644 index cf182fc2..00000000 --- a/tools/win/builder +++ /dev/null @@ -1,351 +0,0 @@ -#!/bin/sh - -set -e - -BUILD_ROOT=$HOME/vbam-build - -# build env -export HOST_SYSTEM=x86_64-w64-mingw32 -export CFLAGS="-I$BUILD_ROOT/root/include" -export CPPFLAGS="-I$BUILD_ROOT/root/include" -export CXXFLAGS="-I$BUILD_ROOT/root/include -std=gnu++11" -export OBJCXXFLAGS="-I$BUILD_ROOT/root/include -std=gnu++11" -export LDFLAGS="-L$BUILD_ROOT/root/lib" -export CMAKE_PREFIX_PATH="$BUILD_ROOT/root" -export PKG_CONFIG_PATH="$BUILD_ROOT/root/lib/pkgconfig" -export PATH="$BUILD_ROOT/root/bin:$PATH" - -DISTS=' - libiconv https://ftp.gnu.org/gnu/libiconv/libiconv-1.15.tar.gz lib/libiconv.a - gettext http://ftp.gnu.org/pub/gnu/gettext/gettext-0.19.8.1.tar.xz lib/libintl.a - openssl https://www.openssl.org/source/openssl-1.0.2l.tar.gz lib/libssl.a - libpng https://download.sourceforge.net/libpng/libpng-1.6.32.tar.xz lib/libpng.a - libjpeg-turbo https://github.com/libjpeg-turbo/libjpeg-turbo/archive/1.5.2.tar.gz lib/libjpeg.a - libtiff http://dl.maptools.org/dl/libtiff/tiff-3.8.2.tar.gz lib/libtiff.a - sdl2 https://www.libsdl.org/release/SDL2-2.0.6.tar.gz lib/libSDL2.a - openal http://kcat.strangesoft.net/openal-releases/openal-soft-1.18.2.tar.bz2 lib/libOpenAL32.a - ogg http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.xz lib/libogg.a - vorbis http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.xz lib/libvorbis.a - flac https://ftp.osuosl.org/pub/xiph/releases/flac/flac-1.3.2.tar.xz libFLAC.a - sfml https://www.sfml-dev.org/files/SFML-2.4.2-sources.zip lib/libsfml-system-s.a - wxwidgets https://github.com/wxWidgets/wxWidgets/releases/download/v3.0.3/wxWidgets-3.0.3.tar.bz2 lib/libwx_baseu-3.0.a - ffmpeg http://ffmpeg.org/releases/ffmpeg-3.3.4.tar.xz lib/libavformat.a - xz https://tukaani.org/xz/xz-5.2.3.tar.xz lib/liblzma.a -' - -CONFIGURE_ARGS="--disable-shared --enable-static --prefix=$BUILD_ROOT/root --host=$HOST_SYSTEM" -CMAKE_ARGS="-DCMAKE_PREFIX_PATH=$BUILD_ROOT/root -DCMAKE_INSTALL_PREFIX=$BUILD_ROOT/root" - -DIST_OVERRIDES=" - openssl mingw64 no-shared --prefix=$BUILD_ROOT/root - gettext --host=$HOST_SYSTEM --prefix=$BUILD_ROOT/root --enable-static --with-included-glib --enable-threads=win32 --enable-static --with-included-libcroco --with-included-libunistring --with-included-libxml LDFLAGS='-L$BUILD_ROOT/root/lib' -" - -DIST_ARGS=" - sfml -DBUILD_SHARED_LIBS=NO - wxwidgets --enable-stl - openal -DLIBTYPE=STATIC -" - -main() { - setup - delete_outdated_dists - download_dists - build_dists - build_project -} - -setup() { - mkdir -p "$BUILD_ROOT" - - DIST_NAMES=$( table_column 0 3 "$DISTS") - DIST_URLS=$( table_column 1 3 "$DISTS") - DIST_TARGETS=$(table_column 2 3 "$DISTS") - - DISTS_NUM=$(table_rows "$DISTS") - - NUM_CPUS=$(nproc) - - CHECKOUT=$(find_checkout) -} - -delete_outdated_dists() { - files= - i=0 - for dist in $DIST_NAMES; do - dist_url=$(list_get $i $DIST_URLS) - dist_file="$BUILD_ROOT/dists/${dist_url##*/}" - - files="$files $dist_file" - - i=$((i + 1)) - done - - for file in $BUILD_ROOT/dists/*; do - if ! list_contains "$file" $files; then - echo "\nDeleting outdated dist: $file\n" - rm -f "$file" - fi - done -} - -download_dists() { - mkdir -p "$BUILD_ROOT/dists" - - i=0 - while [ $i -lt $DISTS_NUM ]; do - dist_name=$(list_get $i $DIST_NAMES) - dist_url=$( list_get $i $DIST_URLS) - dist_file="$BUILD_ROOT/dists/${dist_url##*/}" - - cd "$BUILD_ROOT/dists" - if [ ! -e "$dist_file" ]; then - echo "\nFetching $dist_name: $dist_url\n" - curl -LO "$dist_url" - - # force rebuild for new dist file - rm -f "$BUILD_ROOT/root/$(list_get $i $DIST_TARGETS)" - rm -rf "$BUILD_ROOT/libs/$dist_name" - fi - - dist_dir="$BUILD_ROOT/libs/$dist_name" - - if [ ! -d "$dist_dir" ]; then - mkdir -p "$dist_dir" - - tmp_dir="$BUILD_ROOT/libs/tmp" - mkdir -p "$tmp_dir" - cd "$tmp_dir" - - case "$dist_file" in - *.tar.gz) - tar zxf "$dist_file" - ;; - *.tar.xz) - xzcat "$dist_file" | tar xf - - ;; - *.tar.bz2) - bzcat "$dist_file" | tar xf - - ;; - *.zip) - unzip -q "$dist_file" - ;; - esac - - mv */* "$dist_dir" - rm -rf "$tmp_dir" - fi - - i=$((i + 1)) - done -} - -build_dists() { - cd "$BUILD_ROOT/libs" - - i=0 - for dist in $DIST_NAMES; do - target_lib="$BUILD_ROOT/root/$(list_get $i $DIST_TARGETS)" - - if [ ! -e "$target_lib" ]; then - cd "$dist" - - if [ -e configure -o -e configure.ac -o -e configure.in -o -e Makefile.am ]; then - echo "\nBuilding $dist\n" - - if [ ! -e configure ]; then - aclocal - - if command -v glibtoolize >/dev/null; then - glibtoolize - else - libtoolize - fi - - autoheader - autoconf - [ -e Makefile.am ] && automake --add-missing - fi - - ./configure $(dist_args "$dist" autoconf) - make -j$NUM_CPUS - make install prefix=$BUILD_ROOT/root - - echo "\nDone!!!\n" - elif [ -e CMakeLists.txt ]; then - echo "\nBuilding $dist\n" - - mkdir -p build - cd build - - cmake .. -G"MSYS Makefiles" $(dist_args "$dist" cmake) - make -j$NUM_CPUS - rm -rf destdir - mkdir destdir - make install DESTDIR="$PWD/destdir" - - cd "$PWD/destdir/$BUILD_ROOT/root" - find . ! -type d | (cd "$BUILD_ROOT/root"; IFS=' -'; while read f; do - mkdir -p "${f%/*}" - cp -a "$BUILD_ROOT/libs/$dist/build/destdir/$BUILD_ROOT/root/$f" "$f" - done) - - cd "$BUILD_ROOT/libs/$dist" - - echo "\nDone!!!\n" - fi - - cd .. - fi - - i=$((i + 1)) - done -} - -list_get() { - i=0 - n=${1:=0} - shift - - for item; do - if [ $i -eq $n ]; then - echo "$item" - return 0 - fi - - i=$((i + 1)) - done -} - -dist_args() { - dist=$1 - [ -n "$dist" ] || error 'dist name required' - buildsys=$2 - [ "$buildsys" = autoconf -o "$buildsys" = cmake ] || \ - error "buildsystem type required, must be 'autoconf' or 'cmake'" - - args=$(table_line "$dist" "$DIST_OVERRIDES") - - if [ -z "$args" ]; then - case "$buildsys" in - autoconf) - args="$CONFIGURE_ARGS $(table_line "$dist" "$DIST_ARGS")" - ;; - cmake) - args="$CMAKE_ARGS $(table_line "$dist" "$DIST_ARGS")" - ;; - esac - fi - - echo "$args" - - return 0 -} - -table_line() { - name=$1 - [ -n "$name" ] || error 'item name required' - table=$2 - [ -n "$table" ] || error 'table string required' - - OLDIFS=$IFS - IFS=' -' - for line in $table; do - IFS=$OLDIFS - set -- $line - if [ "$1" = "$name" ]; then - shift - echo "$@" - return 0 - fi - done - - IFS=$OLDIFS -} - -find_checkout() { - ( - cd "$(dirname "$0")" - while [ "$PWD" != / ]; do - if [ -e src/version.h.in ]; then - echo "$PWD" - exit 0 - fi - - cd .. - done - exit 1 - ) || error 'cannot find project checkout' -} - -error() { - printf >&2 '\nERROR: %s.\n\n' "$1" - [ -z "$2" ] && exit 1 -} - -build_project() { - echo "\nBuilding project: $CHECKOUT\n" - - mkdir -p "$BUILD_ROOT/project" - cd "$BUILD_ROOT/project" - - cmake "$CHECKOUT" -DCMAKE_PREFIX_PATH="$BUILD_ROOT/root" -DENABLE_FFMPEG=OFF -DSFML_STATIC_LIBRARIES=TRUE - make -j$NUM_CPUS - - echo "\nBuild Successful!!!\n\nBuild results can be found in: $BUILD_ROOT/project\n" -} - -table_column() { - col=$1 - [ -n "$col" ] || error 'table_column: column required' - row_size=$2 - [ -n "$row_size" ] || error 'table_column: row_size required' - table=$3 - [ -n "$table" ] || error 'table_column: table required' - - i=0 - res= - for item in $table; do - if [ $((i % row_size)) -eq "$col" ]; then - res="$res $item" - fi - i=$((i + 1)) - done - - echo $res - - return 0 -} - -table_rows() { - table=$1 - [ -n "$table" ] || error 'table_rows: table required' - - i=0 - OLDIFS=$IFS - IFS=' -'; for line in $table; do - i=$((i + 1)) - done - IFS=$OLDIFS - - echo $i - - return 0 -} - -list_contains() { - _item=$1 - [ -n "$_item" ] || error 'list_contains: item required' - shift - - for _pos; do - [ "$_item" = "$_pos" ] && return 0 - done - - return 1 -} - -main "$@" diff --git a/tools/win/linux-cross-builder b/tools/win/linux-cross-builder new file mode 100755 index 00000000..973e2353 --- /dev/null +++ b/tools/win/linux-cross-builder @@ -0,0 +1,95 @@ +#!/bin/sh + +set -e + +case "$1" in + -32) + target_bits=32 + target_cpu=i686 + ;; + -64) + target_bits=64 + target_cpu=x86_64 + ;; + *) + echo >&2 'First parameter must be -32 or -64 for 32 bit or 64 bit target respectively.' + exit 1 + ;; +esac +shift + +target_arch="${target_cpu}-w64-mingw32" + +export BUILD_ROOT="$HOME/vbam-build-mingw${target_bits}" + +do_not_remove_dists= + +host_dists=' + unzip zip cmake autoconf autoconf-archive automake libtool help2man texinfo + xmlto pkgconfig nasm yasm c2man 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='xz expat libpng freetype fontconfig' + +[ -n "$BUILD_ENV" ] && eval "$BUILD_ENV" + +BUILD_ENV=$BUILD_ENV$(cat <,include ,g'\'' *.c;' + +table_line_replace DIST_POST_BUILD harfbuzz "$(table_line DIST_POST_BUILD harfbuzz | sed 's/build_dist freetype /build_dist freetype-target /')" + +table_line_append DIST_ARGS libsoxr '-DHAVE_WORDS_BIGENDIAN_EXITCODE=0' + +vpx_target=x86-win32-gcc +[ "$target_bits" -eq 64 ] && vpx_target=x86_64-win64-gcc + +table_line_replace DIST_CONFIGURE_OVERRIDES libvpx "./configure --target=$vpx_target $CONFIGURE_ARGS $(table_line DIST_ARGS libvpx)" + +table_line_remove DIST_ARGS libvpx + +table_line_replace DIST_CONFIGURE_OVERRIDES ffmpeg "\ + ./configure --arch=$target_cpu --target-os=mingw32 --cross-prefix=${target_arch}- \ + --pkg-config='$BUILD_ROOT/host/bin/pkg-config' \ + $CONFIGURE_ARGS $(table_line DIST_ARGS ffmpeg) \ +" + +table_line_remove DIST_ARGS ffmpeg + +builder "$@" diff --git a/tools/win/msys2-builder b/tools/win/msys2-builder new file mode 100755 index 00000000..4878aee5 --- /dev/null +++ b/tools/win/msys2-builder @@ -0,0 +1,147 @@ +#!/bin/sh + +set -e + +case "$1" in + -32) + shift + if [ "$MSYSTEM" != MINGW32 ]; then + OPWD=$PWD + export MSYSTEM=MINGW32 + . /etc/profile + cd "$OPWD" + fi + ;; + -64) + shift + if [ "$MSYSTEM" != MINGW64 ]; then + OPWD=$PWD + export MSYSTEM=MINGW64 + . /etc/profile + cd "$OPWD" + fi + ;; +esac + +OMSYSTEM=$MSYSTEM + +case "$MSYSTEM" in + MINGW32) + export HOST_SYSTEM=i686-w64-mingw32 + sys_base=/mingw32 + BUILD_ROOT="$HOME/vbam-build-msys2-i686" + ;; + MINGW64) + export HOST_SYSTEM=x86_64-w64-mingw32 + sys_base=/mingw64 + BUILD_ROOT="$HOME/vbam-build-msys2-x86_64" + ;; + *) + echo >&2 'You must be in either the MINGW32 or MINGW64 environment.' + exit 1 + ;; +esac + +CMAKE_PREFIX_PATH= +for dir in /lib /bin "$HOST_SYSTEM/lib" "$HOST_SYSTEM/bin"; do + CMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH;$(cygpath -m "$sys_base/$dir")" +done + +export CMAKE_PREFIX_PATH="$(cygpath -m "$BUILD_ROOT/root");${CMAKE_PREFIX_PATH%;}" + +ignore_msys_paths= +for d in /usr /usr/include /usr/lib; do + ignore_msys_paths="$ignore_msys_paths;$(cygpath -m "$d")" +done +ignore_msys_paths=${ignore_msys_paths#;} + +CMAKE_BASE_ARGS="-G 'MSYS Makefiles' -DCMAKE_IGNORE_PATH='$ignore_msys_paths'" + +TMP_DIR="$BUILD_ROOT/tmp_$$" + +BUILD_ENV=$BUILD_ENV$(cat <<'EOF' + +# on don't translate prefix and defines by default +export MSYS2_ARG_CONV_EXCL="-D;/usr;/etc" + +EOF +) + +DIST_TAR_ARGS=" + help2man --exclude ChangeLog + sfml --exclude libs-osx + expat --exclude README.md + libsoxr --exclude inst-check-soxr-lsr + graphviz --exclude COPYING --exclude graphviz.spec +" + +. "$(dirname "$0")/../builder/mingw.sh" + +set_host_env() { + ln -sf "$BUILD_ROOT/host" "$BUILD_ROOT/root" + + OPWD=$PWD + MSYSTEM=MSYS . /etc/profile || : + eval "$BUILD_ENV" + cd "$OPWD" +} + +unset_host_env() { + ln -sf "$BUILD_ROOT/target" "$BUILD_ROOT/root" + + OPWD=$PWD + MSYSTEM=$OMSYSTEM . /etc/profile || : + eval "$BUILD_ENV" + cd "$OPWD" +} + +table_line_append DIST_PRE_BUILD c2man ":; sed -i.bak '/test -d c:\\//,/^fi\$/d' Configure" + +table_line_append DIST_PATCHES xmlto 'https://gist.githubusercontent.com/rkitover/55d51ab3d55af510b37872a49670436c/raw/b447beaffc2daa747ba6eaf222f69677c7d4a169/xmlto-0.0.28-mingw.patch' + +# FIXME: problems with autopoint that need to be sorted +table_line_remove DISTS flex + +table_line_replace DIST_CONFIGURE_TYPES fontconfig autoreconf +table_line_append DIST_PRE_BUILD fontconfig ":; \ + sed -i.bak 's|ln -s \\\$(templatedir)|cp -af \$(DESTDIR)/\$(templatedir)|g' conf.d/Makefile.am; \ +" + +if mime_info_libs=$(table_line DIST_EXTRA_LIBS shared-mime-info); then + table_line_replace DIST_EXTRA_LIBS shared-mime-info "$(puts "$mime_info_libs" | sed 's/-ldl//g; s/-lresolv//g;')" +fi + +table_line_remove DIST_CONFIGURE_OVERRIDES unzip +table_line_remove DIST_PRE_BUILD unzip + +table_line_replace DIST_MAKE_ARGS unzip '-f win32/Makefile.gcc NOASM=1 CC_CPU_OPT=' +table_line_replace DIST_INSTALL_OVERRIDES unzip 'cp -af $(find . -name "*.exe") "$BUILD_ROOT/root/bin"' + +table_line_replace DIST_PRE_BUILD unzip ":; \ + sed -i.bak 's,#include \"../unzip\\.h\",#include ,; \ + t; \ + s,#include ,#include \"../unzip.h\",' win32/win32.c win32/nt.c; \ +" + +table_line_append DIST_PATCHES zip 'https://gist.githubusercontent.com/rkitover/17e4c90185b7ad533e848b6230a90b8d/raw/67686e2332ae8712177957e4a4b871b24b3d07cf/zip-mingw.patch' + +table_line_remove DIST_CONFIGURE_OVERRIDES zip +table_line_remove DIST_PRE_BUILD zip + +table_line_replace DIST_MAKE_ARGS zip '-f win32/Makefile.gcc' +table_line_replace DIST_INSTALL_OVERRIDES zip 'cp -af *.exe "$BUILD_ROOT/root/bin"' + +table_line_replace DIST_POST_BUILD unzip ":; \ + mkdir -p \"\$BUILD_ROOT/root/bin\"; \ + cp -a \"\$BUILD_ROOT/dists/unzip\"/*.exe \"\$BUILD_ROOT/root/bin\"; \ +" + +table_line_replace DIST_CONFIGURE_OVERRIDES openssl "$(table_line DIST_CONFIGURE_OVERRIDES openssl | sed 's,^./config ,./Configure Cygwin-x86_64 ,')" + +table_line_append DIST_PRE_BUILD zlib ":; \ + sed -i.bak ' \ + s/defined(_WIN32) *|| *defined(__CYGWIN__)/defined(_WIN32)/ \ + ' gzguts.h; \ +" + +builder "$@"