2
0

Build script update.

This commit is contained in:
Maarten Billemont 2017-08-13 11:02:05 -04:00
parent a8776eec58
commit 1b51c5efa4
2 changed files with 109 additions and 95 deletions

View File

@ -4,7 +4,7 @@ env: TERM=dumb SHLVL=0
git: git:
submodules: true submodules: true
script: script:
- "( brew install libsodium )" - "( brew install libsodium json-c )"
- "( cd ./platform-independent/cli-c && ./clean && targets='mpw mpw-bench mpw-tests' ./build && ./mpw-tests )" - "( cd ./platform-independent/cli-c && ./clean && targets='mpw mpw-bench mpw-tests' ./build && ./mpw-tests )"
- "( xcodebuild -workspace platform-darwin/MasterPassword.xcworkspace -configuration 'Test' -scheme 'MasterPassword iOS' -sdk iphonesimulator )" - "( xcodebuild -workspace platform-darwin/MasterPassword.xcworkspace -configuration 'Test' -scheme 'MasterPassword iOS' -sdk iphonesimulator )"
- "( xcodebuild -workspace platform-darwin/MasterPassword.xcworkspace -configuration 'Test' -scheme 'MasterPassword macOS' )" - "( xcodebuild -workspace platform-darwin/MasterPassword.xcworkspace -configuration 'Test' -scheme 'MasterPassword macOS' )"

View File

@ -24,7 +24,6 @@ set -e
### CONFIGURATION ### CONFIGURATION
# Targets to build. # Targets to build.
if [[ $targets ]]; then if [[ $targets ]]; then
read -ra targets <<< "$targets" read -ra targets <<< "$targets"
@ -33,35 +32,43 @@ else
# Modify here or override using targets='mpw mpw-bench' ./build # Modify here or override using targets='mpw mpw-bench' ./build
targets=( targets=(
mpw # C CLI version of Master Password, requires libsodium or openssl-dev. mpw # C CLI version of Master Password, requires libsodium or openssl-dev.
#mpw-bench # C CLI Master Password benchmark utility. #mpw-bench # C CLI Master Password benchmark utility.
#mpw-tests # C Master Password algorithm test suite, requires libxml2. #mpw-tests # C Master Password algorithm test suite, requires libxml2.
) )
fi fi
# Optional features. # Optional features.
mpw_color=${mpw_color:-1} # Colorized Identicon, requires libncurses-dev. mpw_color=${mpw_color:-1} # Colorized Identicon, requires libncurses-dev.
mpw_json=${mpw_json:-1} # Support for JSON-based user configuration format.
mpw_sodium=${mpw_sodium:-1} # Use libsodium if available instead of cperciva's libscrypt. mpw_sodium=${mpw_sodium:-1} # Use libsodium if available instead of cperciva's libscrypt.
mpw_json=${mpw_json:-1} # Support for JSON-based user configuration format.
# Default build flags. # Default build flags.
export CFLAGS="-O3 $CFLAGS" cflags=( -O3 $CFLAGS )
export LDFLAGS="$LDFLAGS" ldflags=( $LDFLAGS )
# Version. # Version.
if { mpw_version=$(git describe --match '*-cli*' --long --dirty --broken) || mpw_version=$(<VERSION); } 2>/dev/null; then if { mpw_version=$(git describe --match '*-cli*' --long --dirty --broken) || mpw_version=$(<VERSION); } 2>/dev/null; then
CFLAGS+=" -DMP_VERSION=$mpw_version" cflags+=( -D"MP_VERSION=$mpw_version" )
fi fi
echo 2>&1 "Building mpw version ${mpw_version:-<unknown>}..." echo 2>&1 "Building mpw version ${mpw_version:-<unknown>}..."
# Distribution specific configuration.
# Homebrew - openssl for scrypt
if hash brew 2>/dev/null; then
opensslPath=$(brew --prefix openssl)
CFLAGS+=" -I$opensslPath/include"
LDFLAGS+=" -L$opensslPath/lib"
fi
### DEPENDENCIES ### TOOLS
haslib() {
cc -l"$1" -x c -o /dev/null - <<< 'int main() { return 0; }'
}
cc() {
if hash llvm-gcc 2>/dev/null; then
llvm-gcc "$@"
elif hash gcc 2>/dev/null; then
gcc -std=gnu99 "$@"
elif hash clang 2>/dev/null; then
clang "$@"
else
echo >&2 "Need a compiler. Please install GCC or LLVM."
exit 1
fi
}
digest() { digest() {
openssl sha -sha256 -binary < "$1" | od -t x1 -An -v | tr -d '[:space:]' openssl sha -sha256 -binary < "$1" | od -t x1 -An -v | tr -d '[:space:]'
@ -101,6 +108,7 @@ unpack() {
rmdir "$files" rmdir "$files"
fi fi
} }
fetchSource() ( fetchSource() (
local name=${PWD##*/} local name=${PWD##*/}
source .source source .source
@ -184,21 +192,17 @@ depend() {
if [[ -e configure.ac ]]; then if [[ -e configure.ac ]]; then
if [[ ! -e configure ]]; then if [[ ! -e configure ]]; then
# create configure using autotools. # create configure using autotools.
if ! hash aclocal || ! hash automake; then if ! hash autoreconf; then
echo >&2 "Need autotools to build $name. Please install automake and autoconf." echo >&2 "Need autoconf to build $name. Please install autoconf."
exit 1 exit 1
fi fi
aclocal autoreconf --verbose --install --symlink --force 2>&1 | sed 's/^\([^:]*\):[0-9]\{1,\}: /\1: /'
autoheader
autoconf
mkdir -p config.aux
automake --add-missing
fi fi
fi fi
if [[ -e configure ]]; then if [[ -e configure ]]; then
./configure CFLAGS="$CFLAGS ${cflags[*]}" LDFLAGS="$LDFLAGS ${ldflags[*]}" ./configure
fi fi
echo echo
@ -209,7 +213,7 @@ depend() {
exit 1 exit 1
fi fi
make CFLAGS="$CFLAGS ${cflags[*]}" LDFLAGS="$LDFLAGS ${ldflags[*]}" make
install -d "../../include/$name/" install -d "../../include/$name/"
find . -name '*.h' -exec install -m 444 {} "../../include/$name/" \; find . -name '*.h' -exec install -m 444 {} "../../include/$name/" \;
else else
@ -220,79 +224,102 @@ depend() {
popd popd
} }
depend_scrypt() { depend_scrypt() {
if (( mpw_sodium )) && haslib sodium; then if (( mpw_sodium )); then
if [[ $CFLAGS != *HAS_SODIUM=1* ]]; then if haslib sodium; then
CFLAGS+=" -DHAS_SODIUM=1" cflags+=( -D"HAS_SODIUM=1" ) ldflags+=( -l"sodium" )
LDFLAGS+=" -lsodium" return
else
echo >&2 "mpw_sodium enabled but missing sodium library."
fi fi
return fi
# Homebrew - openssl for scrypt
if hash brew 2>/dev/null; then
opensslPath=$(brew --prefix openssl)
cflags+=( -I"$opensslPath/include" )
ldflags+=( -L"$opensslPath/lib" )
fi fi
depend scrypt depend scrypt
if [[ $CFLAGS != *HAS_CPERCIVA=1* ]]; then cflags+=( -D"HAS_CPERCIVA=1" )
local objects=( ldflags+=(
"lib/scrypt/src/libcperciva/"*/*.o -L"lib/scrypt/src"
"lib/scrypt/src/lib/crypto/"*.o
) "lib/scrypt/src/libcperciva/"*/*.o
CFLAGS+=" -DHAS_CPERCIVA=1" "lib/scrypt/src/lib/crypto/"*.o
LDFLAGS+=" -Llib/scrypt/src ${objects[*]}" )
fi
} }
### MPW ### MPW
mpw() { mpw() {
# dependencies
depend_scrypt depend_scrypt
if (( mpw_color )); then
if haslib curses; then
cflags+=( -D"MPW_COLOR=1" ) ldflags+=( -l"curses" )
else
echo >&2 "mpw_color enabled but missing curses library."
fi
fi
if (( mpw_json )); then
if haslib json-c; then
cflags+=( -D"MPW_JSON=1" ) ldflags+=( -l"json-c" )
else
echo >&2 "mpw_json enabled but missing json-c library."
fi
fi
# target
echo echo
echo "Building target: $target..." echo "Building target: $target..."
local CFLAGS=( local cflags=(
$CFLAGS "${cflags[@]}"
# library paths # library paths
-I"lib/include" -I"lib/include"
# mpw paths # mpw paths
-I"core" -I"cli" -I"core" -I"cli"
) )
local LDFLAGS=( local ldflags=(
$LDFLAGS "${ldflags[@]}"
# link libraries # link libraries
-l"crypto" -l"crypto"
) )
# optional features
(( mpw_color )) && CFLAGS+=( -DMPW_COLOR ) LDFLAGS+=( -l"curses" )
(( mpw_json )) && CFLAGS+=( -DMPW_JSON ) LDFLAGS+=( -l"json-c" )
cc "${CFLAGS[@]}" "$@" -c core/base64.c -o core/base64.o # build
cc "${CFLAGS[@]}" "$@" -c core/mpw-algorithm.c -o core/mpw-algorithm.o cc "${cflags[@]}" "$@" -c core/base64.c -o core/base64.o
cc "${CFLAGS[@]}" "$@" -c core/mpw-types.c -o core/mpw-types.o cc "${cflags[@]}" "$@" -c core/mpw-algorithm.c -o core/mpw-algorithm.o
cc "${CFLAGS[@]}" "$@" -c core/mpw-util.c -o core/mpw-util.o cc "${cflags[@]}" "$@" -c core/mpw-types.c -o core/mpw-types.o
cc "${CFLAGS[@]}" "$@" -c core/mpw-marshall-util.c -o core/mpw-marshall-util.o cc "${cflags[@]}" "$@" -c core/mpw-util.c -o core/mpw-util.o
cc "${CFLAGS[@]}" "$@" -c core/mpw-marshall.c -o core/mpw-marshall.o cc "${cflags[@]}" "$@" -c core/mpw-marshall-util.c -o core/mpw-marshall-util.o
cc "${CFLAGS[@]}" "$@" "core/base64.o" "core/mpw-algorithm.o" "core/mpw-types.o" "core/mpw-util.o" "core/mpw-marshall-util.o" "core/mpw-marshall.o" \ cc "${cflags[@]}" "$@" -c core/mpw-marshall.c -o core/mpw-marshall.o
"${LDFLAGS[@]}" "cli/mpw-cli.c" -o "mpw" cc "${cflags[@]}" "$@" "core/base64.o" "core/mpw-algorithm.o" "core/mpw-types.o" "core/mpw-util.o" "core/mpw-marshall-util.o" "core/mpw-marshall.o" \
echo "done! Now run ./install or use ./mpw" "${ldflags[@]}" "cli/mpw-cli.c" -o "mpw"
echo "done! Now run ./install or use ./$_"
} }
### MPW-BENCH ### MPW-BENCH
mpw-bench() { mpw-bench() {
# dependencies
depend_scrypt depend_scrypt
depend bcrypt depend bcrypt
# target
echo echo
echo "Building target: $target..." echo "Building target: $target..."
local CFLAGS=( local cflags=(
$CFLAGS "${cflags[@]}"
# library paths # library paths
-I"lib/include" -I"lib/include"
# mpw paths # mpw paths
-I"core" -I"cli" -I"core" -I"cli"
) )
local LDFLAGS=( local ldflags=(
$LDFLAGS "${ldflags[@]}"
# bcrypt # bcrypt
"lib/bcrypt/src/crypt_blowfish.o" "lib/bcrypt/src/crypt_blowfish.o"
@ -305,24 +332,27 @@ mpw-bench() {
-l"crypto" -l"crypto"
) )
cc "${CFLAGS[@]}" "$@" -c core/base64.c -o core/base64.o # build
cc "${CFLAGS[@]}" "$@" -c core/mpw-algorithm.c -o core/mpw-algorithm.o cc "${cflags[@]}" "$@" -c core/base64.c -o core/base64.o
cc "${CFLAGS[@]}" "$@" -c core/mpw-types.c -o core/mpw-types.o cc "${cflags[@]}" "$@" -c core/mpw-algorithm.c -o core/mpw-algorithm.o
cc "${CFLAGS[@]}" "$@" -c core/mpw-util.c -o core/mpw-util.o cc "${cflags[@]}" "$@" -c core/mpw-types.c -o core/mpw-types.o
cc "${CFLAGS[@]}" "$@" "core/base64.o" "core/mpw-algorithm.o" "core/mpw-types.o" "core/mpw-util.o" \ cc "${cflags[@]}" "$@" -c core/mpw-util.c -o core/mpw-util.o
"${LDFLAGS[@]}" "cli/mpw-bench.c" -o "mpw-bench" cc "${cflags[@]}" "$@" "core/base64.o" "core/mpw-algorithm.o" "core/mpw-types.o" "core/mpw-util.o" \
echo "done! Now use ./mpw-bench" "${ldflags[@]}" "cli/mpw-bench.c" -o "mpw-bench"
echo "done! Now use ./$_"
} }
### MPW-TESTS ### MPW-TESTS
mpw-tests() { mpw-tests() {
# dependencies
depend_scrypt depend_scrypt
# target
echo echo
echo "Building target: $target..." echo "Building target: $target..."
local CFLAGS=( local cflags=(
$CFLAGS "${cflags[@]}"
# library paths # library paths
-I"lib/include" -I"lib/include"
@ -331,42 +361,26 @@ mpw-tests() {
# mpw paths # mpw paths
-I"core" -I"cli" -I"core" -I"cli"
) )
local LDFLAGS=( local ldflags=(
$LDFLAGS "${ldflags[@]}"
# link libraries # link libraries
-l"crypto" -l"xml2" -l"crypto" -l"xml2"
) )
cc "${CFLAGS[@]}" "$@" -c core/base64.c -o core/base64.o # build
cc "${CFLAGS[@]}" "$@" -c core/mpw-algorithm.c -o core/mpw-algorithm.o cc "${cflags[@]}" "$@" -c core/base64.c -o core/base64.o
cc "${CFLAGS[@]}" "$@" -c core/mpw-types.c -o core/mpw-types.o cc "${cflags[@]}" "$@" -c core/mpw-algorithm.c -o core/mpw-algorithm.o
cc "${CFLAGS[@]}" "$@" -c core/mpw-util.c -o core/mpw-util.o cc "${cflags[@]}" "$@" -c core/mpw-types.c -o core/mpw-types.o
cc "${CFLAGS[@]}" "$@" -c cli/mpw-tests-util.c -o cli/mpw-tests-util.o cc "${cflags[@]}" "$@" -c core/mpw-util.c -o core/mpw-util.o
cc "${CFLAGS[@]}" "$@" "core/base64.o" "core/mpw-algorithm.o" "core/mpw-types.o" "core/mpw-util.o" \ cc "${cflags[@]}" "$@" -c cli/mpw-tests-util.c -o cli/mpw-tests-util.o
"${LDFLAGS[@]}" "cli/mpw-tests-util.o" "cli/mpw-tests.c" -o "mpw-tests" cc "${cflags[@]}" "$@" "core/base64.o" "core/mpw-algorithm.o" "core/mpw-types.o" "core/mpw-util.o" \
echo "done! Now use ./mpw-tests" "${ldflags[@]}" "cli/mpw-tests-util.o" "cli/mpw-tests.c" -o "mpw-tests"
echo "done! Now use ./$_"
} }
### TARGETS ### BUILD
haslib() {
cc -l"$1" -x c -o /dev/null - <<< 'int main() { return 0; }'
}
cc() {
if hash llvm-gcc 2>/dev/null; then
llvm-gcc "$@"
elif hash gcc 2>/dev/null; then
gcc -std=gnu99 "$@"
elif hash clang 2>/dev/null; then
clang "$@"
else
echo >&2 "Need a compiler. Please install GCC or LLVM."
exit 1
fi
}
echo "Will build targets: ${targets[*]}..." echo "Will build targets: ${targets[*]}..."
for target in "${targets[@]}"; do for target in "${targets[@]}"; do
"$target" "$@" "$target" "$@"