diff --git a/.gitignore b/.gitignore index f3698c9e..946463cf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /win32/Release *.user *.ncb +/libsodium /objs /objs_lib /objs_servald diff --git a/INSTALL.md b/INSTALL.md index cb813b1a..6a953315 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -9,7 +9,7 @@ These instructions will build [Serval DNA][] successfully for the following plat * Debian Linux, ix86 and x86\_64, kernels 2.6.x and 3.x, using [gcc 4.4][] to [gcc 4.8][] - * Mac OS X x86\_64, releases 10.7 “Lion” to 10.11 “El Capitan”, using [gcc + * Mac OS-X x86\_64, releases 10.7 “Lion” to 10.11 “El Capitan”, using [gcc 4.2][] available in [Xcode][] versions 3.2 to 7.2, and GNU tools available from [homebrew][] * Oracle SunOs 5.10 (Solaris), Sparc, using [gcc 4.4][] and GNU tools @@ -43,16 +43,21 @@ environment. Mandatory dependencies: - * standard C library `libc` and standard headers - * standard math library `libm` and headers `` `` - * network services library `libnsl` and headers - * dynamic link library `libdl` and header `` - * Native Posix Threads Library `libpthread` and header `` - * elliptic curve encryption library `libsodium` and header , 1.0.2 - or greater - * on Solaris, the realtime library `librt` (for the `nanosleep()` function) - * Autoconf 2.67-2.69 (2.70 may work but has not been tested) - * Automake 1.15 + * standard C library **libc** and standard headers + * standard math library **libm** and headers `` `` + * network services library **libnsl** and headers + * dynamic link library **libdl** and header `` + * Native Posix Threads Library **libpthread** and header `` + * elliptic curve encryption library **libsodium** and header ``, + version 1.0.2 or greater + * on Solaris, the realtime library **librt** (for the `nanosleep()` function) + * **autoconf** 2.67-2.69 (2.70 may work but has not been tested) + * **automake** 1.15 + +The **libsodium** development files are available on Debian/Ubuntu systems in +the `libsodium-dev` package. On other systems, like Mac OS-X, it must be +compiled from source. The [Notes for Developers](./doc/Development.md) give +more details. Optional: @@ -62,11 +67,11 @@ Optional: Test dependencies: * bash 3.2.48 or later - * GNU grep, sed and awk (on OSX and Solaris, as ggrep, gsed and gawk) + * GNU grep, sed and awk (on Mac OS-X and Solaris, as ggrep, gsed and gawk) * jq 1.3 or later * curl -The GNU grep, sed and awk programs can be installed on OSX using the +The GNU grep, sed and awk programs can be installed on Mac OS-X using the [homebrew][] package manager. The [Notes for Developers](./doc/Development.md) give more details. @@ -125,8 +130,11 @@ On Solaris, the system `make` command may not be GNU Make, and the system $ gmake $ -In the event of a build failure, first consult the [Notes for -Developers](./doc/Development.md), then [contact the Serval Project][]. +In the event of a build failure: + + * ensure that all the [dependencies](#dependencies) are present + * consult the [Notes for Developers](./doc/Development.md) + * as a last resort, [contact the Serval Project][] Built artifacts --------------- diff --git a/build-libsodium.sh b/build-libsodium.sh new file mode 100755 index 00000000..ded4d895 --- /dev/null +++ b/build-libsodium.sh @@ -0,0 +1,219 @@ +#!/bin/bash +# +# Copyright (C) 2016 Serval Project, Inc. +# +# This script downloads the libsodium source code from GitHub, then compiles it +# and sets up the Serval DNA source code to build against the compiled +# libsodium. +# +# This script is useful for building Serval DNA on platforms such as Max OS X +# that do not provide the libsodium development package. Debian and Ubuntu +# provide the libsodium-dev package which can be installed instead of using this +# script. +# +# By default, the script creates a 'libsodium' directory in the same directory +# that contains the 'serval-dna' directory, ie, '../libsodium' relative to the +# script. This location can be overridden by giving an alternative directory +# path on the command line, which the script will create if it does not exist. + +LIBSODIUM_URL_PATH="jedisct1/libsodium.git" +LIBSODIUM_GIT_URL_HTTPS="https://github.com/$LIBSODIUM_URL_PATH" +LIBSODIUM_GIT_URL_SSH="git@github.com:$LIBSODIUM_URL_PATH" +LIBSODIUM_GIT_URL="$LIBSODIUM_GIT_URL_HTTPS" + +# Exit on error +set -e + +usage() { + echo "Usage: ${0##*/} [--directory PATH] [--ssh] [--make-arg ARG]" + echo "Options: --directory PATH download and build in PATH [$LIBSODIUM_DIR]" + echo " --no-update do not update if already downloaded" + echo " --no-clean do not clean if already built" + echo " --ssh download from GitHub using SSH instead of HTTPS" + echo " --dist-build DIST build using libsodium's 'dist-build/DIST.sh' script" + echo " --make-arg ARG pass ARG to the 'make' command" +} + +usage_error() { + echo "${0##*/}: $*" >&2 + usage >&2 + exit 1 +} + +fatal() { + echo "${0##*/}: $*" >&2 + exit 1 +} + +# Work out the absolute path of the directory that contains this script. +case "$0" in +/*) SCRIPT_DIR="${0%/*}";; +./*) SCRIPT_DIR="$PWD";; +*/*) SCRIPT_DIR="$PWD/${0%/*}";; +*) SCRIPT_DIR="$PWD";; +esac + +# The directory in which to install the built libsodium. +LIBSODIUM_DIR_NAME="libsodium" +LIBSODIUM_INSTALL_DIR="$SCRIPT_DIR/$LIBSODIUM_DIR_NAME" + +# The default directory in which to download and build libsodium. +LIBSODIUM_DIR="$SCRIPT_DIR/../libsodium" + +# Parse the command-line, preserving all the arguments for later reference. +PRESERVED_ARGS=() +OPT_UPDATE=true +OPT_CLEAN=true +DIST= +MAKE_ARGS=() +while [ $# -ne 0 ]; do + opt="$1" + shift + case "$opt" in + -h | --help | '-?' ) + usage + exit 0 + ;; + --directory=*) + PRESERVED_ARGS+=("$opt") + LIBSODIUM_DIR="${opt#*=}" + ;; + --directory) + [ $# -ge 1 ] || usage_error "missing argument after $opt" + PRESERVED_ARGS+=("$opt" "$1") + LIBSODIUM_DIR="$1" + shift + ;; + --ssh) + PRESERVED_ARGS+=("$opt") + LIBSODIUM_GIT_URL="$LIBSODIUM_GIT_URL_SSH" + ;; + --no-update) + OPT_UPDATE=false + ;; + --no-clean) + OPT_CLEAN=false + ;; + --dist-build=*) + PRESERVED_ARGS+=("$opt") + DIST="${opt#*=}" + ;; + --dist-build) + [ $# -ge 1 ] || usage_error "missing argument after $opt" + PRESERVED_ARGS+=("$opt" "$1") + DIST="$1" + shift + ;; + --make-arg=*) + PRESERVED_ARGS+=("$opt") + MAKE_ARGS+=("${opt#*=}") + ;; + --make-arg) + [ $# -ge 1 ] || usage_error "missing argument after $opt" + PRESERVED_ARGS+=("$opt" "$1") + MAKE_ARGS+=("$1") + shift + ;; + -*) + usage_error "unrecognised option: $1" + ;; + *) + usage_error "spurious argument: $1" + ;; + esac +done + +if [ ! -d "$LIBSODIUM_DIR" ]; then + echo "Create $LIBSODIUM_DIR" + mkdir -p "$LIBSODIUM_DIR" +fi + +is_libsodium_downloaded() { + [ -r "$1/src/libsodium/include/sodium.h" -a \ + -r "$1/libsodium-uninstalled.pc.in" \ + ] +} + +if ! is_libsodium_downloaded "$LIBSODIUM_DIR"; then + echo "Download libsodium from $LIBSODIUM_GIT_URL..." + git clone --branch stable "$LIBSODIUM_GIT_URL" "$LIBSODIUM_DIR" + cd "$LIBSODIUM_DIR" >/dev/null + is_libsodium_downloaded . || fatal "Download did not produce expected source files" +else + echo "Libsodium appears to already be downloaded" + cd "$LIBSODIUM_DIR" >/dev/null + if $OPT_UPDATE; then + echo "Update from" $(git remote get-url origin) + git pull --ff-only + fi +fi + +if [ -d "$LIBSODIUM_INSTALL_DIR" ]; then + echo "Delete the previous installation" + rm -rf "$LIBSODIUM_INSTALL_DIR" +fi + +if $OPT_CLEAN && [ -r Makefile ]; then + echo "Clean the previous build" + make distclean >/dev/null +fi + +if [ -z "$DIST" ]; then + echo "Native build..." + [ -r Makefile ] || ./configure --prefix="$LIBSODIUM_INSTALL_DIR" + make -j3 "${MAKE_ARGS[@]}" check + make -j3 "${MAKE_ARGS[@]}" install +elif [ -x "dist-build/$DIST.sh" ]; then + installed="libsodium-$DIST" + case "$DIST" in + arm) installed="libsodium-armv6";; + esac + [ -e "$installed" ] && fatal "previous build remains in $installed" + echo "Build using 'dist-build/$DIST.sh'..." + "dist-build/$DIST.sh" + [ -d "$installed" ] || fatal "build did not produce $installed" + echo "Copy built installation into $LIBSODIUM_INSTALL_DIR" + cp -R -p "$installed" "$LIBSODIUM_INSTALL_DIR" +else + fatal "script "dist-build/$DIST_BUILD.sh" does not exist." +fi + +# Create a shell script that will set up the environment to use the built and +# installed libsodium. +cat >"$LIBSODIUM_INSTALL_DIR/settings.sh" <"$LIBSODIUM_INSTALL_DIR/README.txt" <` header. + +Before building Serval DNA on Mac OS X, the libsodium development files can be +locally installed by downloading the [libsodium source code][] and building it. +The [build-libsodium.sh](../build-libsodium.sh) script will do this: + + $ ./build-libsodium.sh + ... + The libsodium run-time and development files have been installed in: + /absolute/path/name/serval-dna/libsodium + + To use this installation of libsodium, set up the environment using the + shell's "dot" command to source its settings.sh script, for example: + + . libsodium/settings.sh ; ./configure + + $ + +In the event of failure, check that: + +* the [github.com][libsodium source code] web site can be reached +* there is at least 60 MB of available disk space +* there is no other libsodium development package already installed + +For more information, refer to the [libsodium installation documentation][] +and the script's help message: + + $ ./build-libsodium.sh --help + ... + $ + +### Test utilities + +The [OS X grep(1)][] , [OS X sed(1)][] and [OS X awk(1)][] tools provided by +Apple Mac OS X are the BSD variants. The test scripts require the GNU variants +with the names *ggrep*, *gsed* and *gawk*, which can be installed on Mac OS X +using the [homebrew][] package manager: $ brew install grep ==> Installing grep from homebrew/dupes @@ -174,8 +212,12 @@ Available under the [Creative Commons Attribution 4.0 International licence][CC [autoreconf]: https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf.html#autoreconf-Invocation [Debian]: http://www.debian.org/ [Ubuntu]: http://www.ubuntu.com/ -[OSX grep(1)]: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/grep.1.html -[OSX sed(1)]: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/sed.1.html -[OSX awk(1)]: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/awk.1.html +[libsodium]: https://download.libsodium.org/doc/ +[libsodium source code]: https://github.com/jedisct1/libsodium +[libsodium installation documentation]: https://download.libsodium.org/libsodium/content/installation/ +[apt-get]: https://www.debian.org/doc/manuals/apt-guide/ch2.en.html +[OS X grep(1)]: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/grep.1.html +[OS X sed(1)]: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/sed.1.html +[OS X awk(1)]: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/awk.1.html [homebrew]: http://brew.sh/ [Bourne shell]: http://en.wikipedia.org/wiki/Bourne_shell