#!/usr/bin/env sh # This file is part of judy. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/judy/master/COPYRIGHT. No part of judy-sys, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file. # Copyright © 2016 The developers of judy. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/judy/master/COPYRIGHT. set -e set -u set -f _program_path_find() { if [ "${_program_fattening_program_path+set}" = 'set' ]; then printf '%s\n' "$_program_fattening_program_path" elif [ "${0%/*}" = "$0" ]; then # We've been invoked by the interpreter as, say, bash program if [ -r "$0" ]; then pwd -P # Clutching at straws; probably run via a download, anonymous script, etc, weird execve, etc else printf '\n' fi else # We've been invoked with a relative or absolute path (also when invoked via PATH in a shell) _program_path_find_parentPath() { parentPath="${scriptPath%/*}" if [ -z "$parentPath" ]; then parentPath='/' fi cd "$parentPath" 1>/dev/null } # pdksh / mksh have problems with unsetting a variable that was never set... if [ "${CDPATH+set}" = 'set' ]; then unset CDPATH fi if command -v realpath 1>/dev/null 2>/dev/null; then ( scriptPath="$(realpath "$0")" _program_path_find_parentPath pwd -P ) elif command -v readlink 1>/dev/null 2>/dev/null; then ( scriptPath="$0" while [ -L "$scriptPath" ] do _program_path_find_parentPath scriptPath="$(readlink "$scriptPath")" done _program_path_find_parentPath pwd -P ) else # This approach will fail in corner cases where the script itself is a symlink in a path not parallel with the concrete script ( scriptPath="$0" _program_path_find_parentPath pwd -P ) fi fi } compile_judy_fail() { local message="$1" printf 'compile-judy:FAIL:%s\n' "$message" 1>&2 exit 1 } compile_judy_ensureRequiredBinariesArePresent() { local reason="$1" shift 1 local binary local missing=false for binary in "$@" do if ! command -v "$binary" 1>/dev/null 2>/dev/null; then printf 'compile-judy:%s\n' "The binary '$binary' needs to be in the path" 1>&2 missing=true fi done if $missing; then compile_judy_fail "Please make sure that the missing binaries are installed because '$reason'" fi } _compile_judy_prepareForMacOSX_brewInstall() { compile_judy_ensureRequiredBinariesArePresent brew local packageName="$1" if ! brew ls --versions "$packageName" 1>/dev/null 2>/dev/null; then brew install "$packageName" 1>&2 fi } compile_judy_prepareForMacOSX() { _compile_judy_prepareForMacOSX_brewInstall make } compile_judy_parseCommandLine() { case "$#" in 0) : ;; 1) case "$1" in -h|--help) printf './compile-judy\n' printf './compile-judy -h|--help\n' printf 'Pass the environment variable NUM_JOBS to control the number of make jobs\n' exit 0 ;; *) compile_judy_fail "Does not take any arguments" ;; esac ;; *) compile_judy_fail "Does not take any arguments" ;; esac } compile_judy_findFolderPaths() { programFolderPath="$(_program_path_find)" cd "$programFolderPath"/.. 1>/dev/null 2>/dev/null homeFolderPath="$(pwd)" cd - 1>/dev/null 2>/dev/null configurationFolderPath="$homeFolderPath"/compile-judy.conf.d bindgenWrapperConfigurationFolderPath="$homeFolderPath"/bindgen-wrapper.conf.d } compile_judy_platformSpecificPreparation() { compile_judy_ensureRequiredBinariesArePresent uname platform="$(uname)" if [ -z "${NUM_JOBS+undefined}" ]; then numberOfMakeJobs=0 else numberOfMakeJobs="$NUM_JOBS" fi case "$platform" in Darwin) compile_judy_prepareForMacOSX if [ $numberOfMakeJobs -eq 0 ]; then compile_judy_ensureRequiredBinariesArePresent sysctl numberOfMakeJobs="$(sysctl -n hw.ncpu)" fi ;; Linux) compile_judy_ensureRequiredBinariesArePresent make sed x86_64-linux-musl-gcc x86_64-linux-musl-ar rm mkdir rsync cat if [ $numberOfMakeJobs -eq 0 ]; then compile_judy_ensureRequiredBinariesArePresent grep numberOfMakeJobs="$(grep -c '^processor' /proc/cpuinfo)" fi ;; *) compile_judy_fail "Only Darwin (Mac OS X) and Linux (specifically, Alpine Linux) are supported at this time" ;; esac } compile_judy_createTemporaryFolder() { if [ -z "${OUT_DIR+undefined}" ]; then temporaryFolderPath="$bindgenWrapperConfigurationFolderPath"/temporary rm -rf "$temporaryFolderPath" mkdir -m 0700 -p "$temporaryFolderPath" else temporaryFolderPath="$OUT_DIR" fi buildFolderPath="$temporaryFolderPath"/build rm -rf "$buildFolderPath" mkdir -m 0700 -p "$buildFolderPath" installRootFolderPath="$temporaryFolderPath"/root rm -rf "$installRootFolderPath" mkdir -m 0700 -p "$installRootFolderPath" } compile_judy_makeCopyToAlter() { rsync --archive --quiet --exclude=.git "$homeFolderPath"/lib/judy/ "$buildFolderPath"/ } compile_judy_moderniseConfigSubAndConfigGuess() { cp "$configurationFolderPath"/config/config.guess "$buildFolderPath"/ cp "$configurationFolderPath"/config/config.sub "$buildFolderPath"/ } compile_judy_configureMakeMakeInstall() { set -- --prefix="$installRootFolderPath"/usr --enable-static --disable-shared --disable-dependency-tracking --enable-fast-install if [ -z "${HOST+undefined}" ]; then : else set -- "$@" --build="$HOST" fi if [ -z "${TARGET+undefined}" ]; then : else set -- "$@" --host="$TARGET" fi cd "$buildFolderPath" 1>/dev/null 2>/dev/null CFLAGS='-O3 -g0' CXXFLAGS='-O3 -g0' ./configure "$@" 1>&2 cd - 1>/dev/null 2>/dev/null cd "$buildFolderPath"/src 1>/dev/null 2>/dev/null make 1>&2 make install 1>&2 cd - 1>/dev/null 2>/dev/null } compile_judy_main() { compile_judy_parseCommandLine "$@" local programFolderPath local homeFolderPath local configurationFolderPath local bindgenWrapperConfigurationFolderPath compile_judy_findFolderPaths local platform local numberOfMakeJobs compile_judy_platformSpecificPreparation local temporaryFolderPath local buildFolderPath local installRootFolderPath compile_judy_createTemporaryFolder compile_judy_makeCopyToAlter compile_judy_moderniseConfigSubAndConfigGuess compile_judy_configureMakeMakeInstall printf '\n\n\nFINISHED\n\n\n' 1>&2 } compile_judy_main "$@"