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:
submodules: true
script:
- "( brew install libsodium )"
- "( brew install libsodium json-c )"
- "( 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 macOS' )"

View File

@ -24,7 +24,6 @@ set -e
### CONFIGURATION
# Targets to build.
if [[ $targets ]]; then
read -ra targets <<< "$targets"
@ -40,28 +39,36 @@ fi
# Optional features.
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_json=${mpw_json:-1} # Support for JSON-based user configuration format.
# Default build flags.
export CFLAGS="-O3 $CFLAGS"
export LDFLAGS="$LDFLAGS"
cflags=( -O3 $CFLAGS )
ldflags=( $LDFLAGS )
# Version.
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
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() {
openssl sha -sha256 -binary < "$1" | od -t x1 -An -v | tr -d '[:space:]'
@ -101,6 +108,7 @@ unpack() {
rmdir "$files"
fi
}
fetchSource() (
local name=${PWD##*/}
source .source
@ -184,21 +192,17 @@ depend() {
if [[ -e configure.ac ]]; then
if [[ ! -e configure ]]; then
# create configure using autotools.
if ! hash aclocal || ! hash automake; then
echo >&2 "Need autotools to build $name. Please install automake and autoconf."
if ! hash autoreconf; then
echo >&2 "Need autoconf to build $name. Please install autoconf."
exit 1
fi
aclocal
autoheader
autoconf
mkdir -p config.aux
automake --add-missing
autoreconf --verbose --install --symlink --force 2>&1 | sed 's/^\([^:]*\):[0-9]\{1,\}: /\1: /'
fi
fi
if [[ -e configure ]]; then
./configure
CFLAGS="$CFLAGS ${cflags[*]}" LDFLAGS="$LDFLAGS ${ldflags[*]}" ./configure
fi
echo
@ -209,7 +213,7 @@ depend() {
exit 1
fi
make
CFLAGS="$CFLAGS ${cflags[*]}" LDFLAGS="$LDFLAGS ${ldflags[*]}" make
install -d "../../include/$name/"
find . -name '*.h' -exec install -m 444 {} "../../include/$name/" \;
else
@ -220,79 +224,102 @@ depend() {
popd
}
depend_scrypt() {
if (( mpw_sodium )) && haslib sodium; then
if [[ $CFLAGS != *HAS_SODIUM=1* ]]; then
CFLAGS+=" -DHAS_SODIUM=1"
LDFLAGS+=" -lsodium"
fi
if (( mpw_sodium )); then
if haslib sodium; then
cflags+=( -D"HAS_SODIUM=1" ) ldflags+=( -l"sodium" )
return
else
echo >&2 "mpw_sodium enabled but missing sodium library."
fi
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
depend scrypt
if [[ $CFLAGS != *HAS_CPERCIVA=1* ]]; then
local objects=(
cflags+=( -D"HAS_CPERCIVA=1" )
ldflags+=(
-L"lib/scrypt/src"
"lib/scrypt/src/libcperciva/"*/*.o
"lib/scrypt/src/lib/crypto/"*.o
)
CFLAGS+=" -DHAS_CPERCIVA=1"
LDFLAGS+=" -Llib/scrypt/src ${objects[*]}"
fi
}
### MPW
mpw() {
# dependencies
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 "Building target: $target..."
local CFLAGS=(
$CFLAGS
local cflags=(
"${cflags[@]}"
# library paths
-I"lib/include"
# mpw paths
-I"core" -I"cli"
)
local LDFLAGS=(
$LDFLAGS
local ldflags=(
"${ldflags[@]}"
# link libraries
-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
cc "${CFLAGS[@]}" "$@" -c core/mpw-algorithm.c -o core/mpw-algorithm.o
cc "${CFLAGS[@]}" "$@" -c core/mpw-types.c -o core/mpw-types.o
cc "${CFLAGS[@]}" "$@" -c core/mpw-util.c -o core/mpw-util.o
cc "${CFLAGS[@]}" "$@" -c core/mpw-marshall-util.c -o core/mpw-marshall-util.o
cc "${CFLAGS[@]}" "$@" -c core/mpw-marshall.c -o core/mpw-marshall.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" \
"${LDFLAGS[@]}" "cli/mpw-cli.c" -o "mpw"
echo "done! Now run ./install or use ./mpw"
# build
cc "${cflags[@]}" "$@" -c core/base64.c -o core/base64.o
cc "${cflags[@]}" "$@" -c core/mpw-algorithm.c -o core/mpw-algorithm.o
cc "${cflags[@]}" "$@" -c core/mpw-types.c -o core/mpw-types.o
cc "${cflags[@]}" "$@" -c core/mpw-util.c -o core/mpw-util.o
cc "${cflags[@]}" "$@" -c core/mpw-marshall-util.c -o core/mpw-marshall-util.o
cc "${cflags[@]}" "$@" -c core/mpw-marshall.c -o core/mpw-marshall.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" \
"${ldflags[@]}" "cli/mpw-cli.c" -o "mpw"
echo "done! Now run ./install or use ./$_"
}
### MPW-BENCH
mpw-bench() {
# dependencies
depend_scrypt
depend bcrypt
# target
echo
echo "Building target: $target..."
local CFLAGS=(
$CFLAGS
local cflags=(
"${cflags[@]}"
# library paths
-I"lib/include"
# mpw paths
-I"core" -I"cli"
)
local LDFLAGS=(
$LDFLAGS
local ldflags=(
"${ldflags[@]}"
# bcrypt
"lib/bcrypt/src/crypt_blowfish.o"
@ -305,24 +332,27 @@ mpw-bench() {
-l"crypto"
)
cc "${CFLAGS[@]}" "$@" -c core/base64.c -o core/base64.o
cc "${CFLAGS[@]}" "$@" -c core/mpw-algorithm.c -o core/mpw-algorithm.o
cc "${CFLAGS[@]}" "$@" -c core/mpw-types.c -o core/mpw-types.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" \
"${LDFLAGS[@]}" "cli/mpw-bench.c" -o "mpw-bench"
echo "done! Now use ./mpw-bench"
# build
cc "${cflags[@]}" "$@" -c core/base64.c -o core/base64.o
cc "${cflags[@]}" "$@" -c core/mpw-algorithm.c -o core/mpw-algorithm.o
cc "${cflags[@]}" "$@" -c core/mpw-types.c -o core/mpw-types.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" \
"${ldflags[@]}" "cli/mpw-bench.c" -o "mpw-bench"
echo "done! Now use ./$_"
}
### MPW-TESTS
mpw-tests() {
# dependencies
depend_scrypt
# target
echo
echo "Building target: $target..."
local CFLAGS=(
$CFLAGS
local cflags=(
"${cflags[@]}"
# library paths
-I"lib/include"
@ -331,42 +361,26 @@ mpw-tests() {
# mpw paths
-I"core" -I"cli"
)
local LDFLAGS=(
$LDFLAGS
local ldflags=(
"${ldflags[@]}"
# link libraries
-l"crypto" -l"xml2"
)
cc "${CFLAGS[@]}" "$@" -c core/base64.c -o core/base64.o
cc "${CFLAGS[@]}" "$@" -c core/mpw-algorithm.c -o core/mpw-algorithm.o
cc "${CFLAGS[@]}" "$@" -c core/mpw-types.c -o core/mpw-types.o
cc "${CFLAGS[@]}" "$@" -c core/mpw-util.c -o core/mpw-util.o
cc "${CFLAGS[@]}" "$@" -c cli/mpw-tests-util.c -o cli/mpw-tests-util.o
cc "${CFLAGS[@]}" "$@" "core/base64.o" "core/mpw-algorithm.o" "core/mpw-types.o" "core/mpw-util.o" \
"${LDFLAGS[@]}" "cli/mpw-tests-util.o" "cli/mpw-tests.c" -o "mpw-tests"
echo "done! Now use ./mpw-tests"
# build
cc "${cflags[@]}" "$@" -c core/base64.c -o core/base64.o
cc "${cflags[@]}" "$@" -c core/mpw-algorithm.c -o core/mpw-algorithm.o
cc "${cflags[@]}" "$@" -c core/mpw-types.c -o core/mpw-types.o
cc "${cflags[@]}" "$@" -c core/mpw-util.c -o core/mpw-util.o
cc "${cflags[@]}" "$@" -c cli/mpw-tests-util.c -o cli/mpw-tests-util.o
cc "${cflags[@]}" "$@" "core/base64.o" "core/mpw-algorithm.o" "core/mpw-types.o" "core/mpw-util.o" \
"${ldflags[@]}" "cli/mpw-tests-util.o" "cli/mpw-tests.c" -o "mpw-tests"
echo "done! Now use ./$_"
}
### TARGETS
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
}
### BUILD
echo "Will build targets: ${targets[*]}..."
for target in "${targets[@]}"; do
"$target" "$@"