2014-06-10 20:25:35 +00:00
|
|
|
#!/usr/bin/env bash
|
2014-10-15 18:00:44 +00:00
|
|
|
#
|
|
|
|
# TROUBLESHOOTING
|
|
|
|
# - See the 'options' array. Comment/uncomment lines as you see fit.
|
|
|
|
# - If you see 'undefined reference to `clock_gettime'', try ./build -lrt instead.
|
|
|
|
#
|
|
|
|
# BUGS
|
|
|
|
# masterpassword@lyndir.com
|
|
|
|
#
|
|
|
|
# AUTHOR
|
|
|
|
# Maarten Billemont
|
|
|
|
#
|
2014-10-15 12:44:41 +00:00
|
|
|
cd "${BASH_SOURCE%/*}"
|
2014-10-16 02:17:49 +00:00
|
|
|
shopt -s extglob
|
2014-10-15 12:44:41 +00:00
|
|
|
set -e
|
2014-06-07 05:27:18 +00:00
|
|
|
|
2014-10-15 20:26:09 +00:00
|
|
|
# optional features.
|
2014-10-15 18:00:44 +00:00
|
|
|
options=(
|
2014-10-15 20:27:33 +00:00
|
|
|
#-DDEBUG # Turn on debugging verbosity.
|
2014-10-15 18:00:44 +00:00
|
|
|
)
|
2014-10-15 20:26:09 +00:00
|
|
|
# available targets.
|
|
|
|
targets=(
|
|
|
|
mpw # C CLI version of Master Password.
|
2014-10-16 02:18:16 +00:00
|
|
|
#mpw-bench # C CLI Master Password benchmark utility.
|
2014-10-15 20:26:09 +00:00
|
|
|
)
|
2014-10-15 18:00:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
### DEPENDENCIES
|
|
|
|
|
2014-10-16 02:17:49 +00:00
|
|
|
fetch() {
|
|
|
|
if hash wget 2>/dev/null; then
|
|
|
|
wget -O "${1##*/}" "$1"
|
|
|
|
elif hash curl 2>/dev/null; then
|
|
|
|
curl "$1" > "${1##*/}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
fetchSource() (
|
|
|
|
echo
|
2014-10-18 19:38:51 +00:00
|
|
|
echo "Fetching dependency: ${PWD##*/}..."
|
2014-10-16 02:17:49 +00:00
|
|
|
source .source
|
|
|
|
|
|
|
|
if [[ $git ]] && hash git 2>/dev/null; then
|
|
|
|
echo
|
2014-10-18 19:38:51 +00:00
|
|
|
echo "Fetching: ${PWD##*/}, using git..."
|
2014-10-18 21:13:01 +00:00
|
|
|
git clone "$svn" .
|
2014-10-16 02:17:49 +00:00
|
|
|
printf '%s' "$(git describe --always)" > "${PWD##*/}-version"
|
|
|
|
return
|
|
|
|
|
2014-10-18 22:22:29 +00:00
|
|
|
elif [[ $svn ]] && hash git 2>/dev/null && [[ -x "$(git --exec-path)/git-svn" ]]; then
|
2014-10-16 02:17:49 +00:00
|
|
|
echo
|
2014-10-18 19:38:51 +00:00
|
|
|
echo "Fetching: ${PWD##*/}, using git-svn..."
|
2014-10-18 21:13:01 +00:00
|
|
|
git svn clone --prefix=origin/ --stdlayout "$svn" .
|
2014-10-16 02:17:49 +00:00
|
|
|
printf '%s' "$(git describe --always)" > "${PWD##*/}-version"
|
|
|
|
return
|
|
|
|
|
|
|
|
elif [[ $svn ]] && hash svn 2>/dev/null; then
|
|
|
|
echo
|
2014-10-18 19:38:51 +00:00
|
|
|
echo "Fetching: ${PWD##*/}, using svn..."
|
2014-10-16 02:17:49 +00:00
|
|
|
svn checkout "$svn/trunk" .
|
|
|
|
printf 'r%s' "$(svn info | awk '/^Revision:/{ print $2 }')" > "${PWD##*/}-version"
|
|
|
|
return
|
|
|
|
|
|
|
|
elif [[ $pkg ]]; then
|
2014-10-18 19:38:51 +00:00
|
|
|
echo
|
|
|
|
echo "Fetching: ${PWD##*/}, using package..."
|
2014-10-16 02:17:49 +00:00
|
|
|
fetch "$pkg"
|
|
|
|
if [[ $pkg = *.tar.gz || $pkg = *.tgz ]]; then
|
|
|
|
tar -xvzf "${pkg##*/}"
|
|
|
|
files=(!("${pkg##*/}"))
|
|
|
|
if [[ -d $files ]] && (( ${#files[@]} == 1 )); then
|
|
|
|
mv "$files"/* .
|
|
|
|
rmdir "$files"
|
2014-10-15 12:44:41 +00:00
|
|
|
fi
|
|
|
|
fi
|
2014-10-16 02:17:49 +00:00
|
|
|
return
|
2014-10-15 12:44:41 +00:00
|
|
|
fi
|
2014-10-16 02:17:49 +00:00
|
|
|
|
|
|
|
echo >&2 "error: Missing git-svn or svn."
|
|
|
|
echo >&2 "error: Please install either or manually check out the sources"
|
|
|
|
echo >&2 "error: from: $home"
|
|
|
|
echo >&2 "error: into: $PWD"
|
|
|
|
exit 1
|
|
|
|
)
|
|
|
|
depend() {
|
|
|
|
|
2014-10-15 12:44:41 +00:00
|
|
|
echo
|
2014-10-18 19:38:51 +00:00
|
|
|
echo "Checking dependency: $1..."
|
2014-10-17 21:10:43 +00:00
|
|
|
[[ -e "lib/$1/.built" ]] && return
|
2014-10-16 02:17:49 +00:00
|
|
|
|
|
|
|
pushd "lib/$1"
|
|
|
|
files=( * )
|
|
|
|
[[ -e $files ]] || fetchSource
|
2014-06-07 19:51:11 +00:00
|
|
|
|
2014-10-16 02:17:49 +00:00
|
|
|
echo
|
2014-10-18 19:38:51 +00:00
|
|
|
echo "Configuring dependency: $1..."
|
2014-10-16 02:17:49 +00:00
|
|
|
if [[ -e configure.ac ]]; then
|
|
|
|
if [[ ! -e configure ]]; then
|
|
|
|
# create configure using autotools.
|
2014-10-18 19:38:51 +00:00
|
|
|
if ! hash aclocal || ! hash automake; then
|
|
|
|
echo >&2 "Need autotools to build $1. Please install automake and autoconf."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-10-16 02:17:49 +00:00
|
|
|
aclocal
|
|
|
|
autoheader
|
|
|
|
autoconf
|
|
|
|
mkdir -p config.aux
|
|
|
|
automake --add-missing
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -e configure ]]; then
|
|
|
|
./configure
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo
|
2014-10-18 19:38:51 +00:00
|
|
|
echo "Building dependency: $1..."
|
2014-10-16 02:17:49 +00:00
|
|
|
if [[ -e Makefile ]]; then
|
2014-10-18 19:38:51 +00:00
|
|
|
if ! hash make; then
|
|
|
|
echo >&2 "Need make to build $1. Please install GNU make."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-10-16 02:17:49 +00:00
|
|
|
make
|
2014-10-17 21:10:43 +00:00
|
|
|
date > .built
|
2014-10-16 02:17:49 +00:00
|
|
|
else
|
|
|
|
echo >&2 "error: Don't know how to build: $1"
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-10-15 12:44:41 +00:00
|
|
|
popd
|
2014-10-16 02:17:49 +00:00
|
|
|
}
|
2014-10-15 12:44:41 +00:00
|
|
|
|
2014-10-15 20:26:09 +00:00
|
|
|
|
|
|
|
### MPW
|
|
|
|
mpw() {
|
2014-10-16 02:17:49 +00:00
|
|
|
depend scrypt
|
|
|
|
|
2014-10-17 21:10:43 +00:00
|
|
|
echo
|
2014-10-16 02:17:49 +00:00
|
|
|
echo "Building target: $target..."
|
2014-10-15 20:26:09 +00:00
|
|
|
CFLAGS=(
|
|
|
|
# include paths
|
|
|
|
-I"lib/scrypt/lib" -I"lib/scrypt/libcperciva"
|
|
|
|
)
|
|
|
|
LDFLAGS=(
|
|
|
|
# library paths
|
|
|
|
-L"." -L"lib/scrypt"
|
|
|
|
# link libraries
|
|
|
|
-l"crypto"
|
|
|
|
# scrypt
|
|
|
|
"lib/scrypt/scrypt-crypto_aesctr.o"
|
|
|
|
"lib/scrypt/scrypt-sha256.o"
|
|
|
|
"lib/scrypt/scrypt-crypto_scrypt-nosse.o"
|
|
|
|
"lib/scrypt/scrypt-memlimit.o"
|
|
|
|
"lib/scrypt/scrypt-scryptenc_cpuperf.o"
|
|
|
|
"lib/scrypt/scrypt-scryptenc.o"
|
|
|
|
)
|
|
|
|
|
|
|
|
cc "${CFLAGS[@]}" "${options[@]}" -c types.c -o types.o "$@"
|
|
|
|
cc "${CFLAGS[@]}" "${LDFLAGS[@]}" "${options[@]}" "types.o" mpw.c -o mpw "$@"
|
|
|
|
echo "done! Now run ./install or use ./mpw"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
### MPW-BENCH
|
|
|
|
mpw-bench() {
|
2014-10-16 02:17:49 +00:00
|
|
|
depend scrypt
|
|
|
|
depend bcrypt
|
|
|
|
|
2014-10-17 21:10:43 +00:00
|
|
|
echo
|
2014-10-16 02:17:49 +00:00
|
|
|
echo "Building target: $target..."
|
2014-10-15 20:26:09 +00:00
|
|
|
CFLAGS=(
|
|
|
|
# include paths
|
|
|
|
-I"lib/scrypt/lib" -I"lib/scrypt/libcperciva"
|
|
|
|
-I"lib/bcrypt"
|
|
|
|
)
|
|
|
|
LDFLAGS=(
|
|
|
|
# library paths
|
|
|
|
-L"." -L"lib/scrypt"
|
|
|
|
-L"lib/bcrypt"
|
|
|
|
# libraries
|
|
|
|
-l"crypto"
|
|
|
|
# scrypt
|
|
|
|
"lib/scrypt/scrypt-crypto_aesctr.o"
|
|
|
|
"lib/scrypt/scrypt-sha256.o"
|
|
|
|
"lib/scrypt/scrypt-crypto_scrypt-nosse.o"
|
|
|
|
"lib/scrypt/scrypt-memlimit.o"
|
|
|
|
"lib/scrypt/scrypt-scryptenc_cpuperf.o"
|
|
|
|
"lib/scrypt/scrypt-scryptenc.o"
|
|
|
|
# bcrypt
|
|
|
|
"lib/bcrypt/crypt_blowfish.o"
|
|
|
|
"lib/bcrypt/crypt_gensalt.o"
|
|
|
|
"lib/bcrypt/wrapper.o"
|
|
|
|
"lib/bcrypt/x86.o"
|
|
|
|
)
|
|
|
|
|
|
|
|
cc "${CFLAGS[@]}" "${options[@]}" -c types.c -o types.o "$@"
|
|
|
|
cc "${CFLAGS[@]}" "${LDFLAGS[@]}" "${options[@]}" "types.o" mpw-bench.c -o mpw-bench "$@"
|
|
|
|
echo "done! Now use ./mpw-bench"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
### TARGETS
|
2014-10-15 12:44:41 +00:00
|
|
|
|
2014-10-15 18:00:44 +00:00
|
|
|
cc() {
|
2014-10-15 19:32:10 +00:00
|
|
|
if hash llvm-gcc 2>/dev/null; then
|
2014-10-15 20:03:46 +00:00
|
|
|
llvm-gcc "$@"
|
2014-10-18 19:38:51 +00:00
|
|
|
elif hash gcc 2>/dev/null; then
|
2014-10-15 19:32:10 +00:00
|
|
|
gcc -std=gnu99 "$@"
|
2014-10-18 22:22:29 +00:00
|
|
|
elif hash clang 2>/dev/null; then
|
|
|
|
clang "$@"
|
2014-10-18 19:38:51 +00:00
|
|
|
else
|
|
|
|
echo >&2 "Need a compiler. Please install GCC or LLVM."
|
|
|
|
exit 1
|
2014-10-15 18:00:44 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-10-18 19:38:51 +00:00
|
|
|
echo "Will build targets: ${targets[*]}${options:+, using options: ${options[*]}}..."
|
2014-10-15 20:26:09 +00:00
|
|
|
for target in "${targets[@]}"; do
|
|
|
|
"$target" "$@"
|
|
|
|
done
|