2
0
MasterPassword/MasterPassword/C/build

219 lines
5.4 KiB
Plaintext
Raw Normal View History

2014-06-10 20:25:35 +00:00
#!/usr/bin/env bash
#
# 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
#
cd "${BASH_SOURCE%/*}"
shopt -s extglob
set -e
2014-10-15 20:26:09 +00:00
# optional features.
options=(
2014-10-15 20:27:33 +00:00
#-DDEBUG # Turn on debugging verbosity.
)
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
)
### DEPENDENCIES
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
echo "Fetching dependency: ${PWD##*/}..."
source .source
if [[ $git ]] && hash git 2>/dev/null; then
echo
echo "Fetching: ${PWD##*/}, using git..."
git-svn clone --prefix=origin/ --stdlayout "$svn" .
printf '%s' "$(git describe --always)" > "${PWD##*/}-version"
return
elif [[ $svn ]] && hash git-svn 2>/dev/null; then
echo
echo "Fetching: ${PWD##*/}, using git-svn..."
git-svn clone --prefix=origin/ --stdlayout "$svn" .
printf '%s' "$(git describe --always)" > "${PWD##*/}-version"
return
elif [[ $svn ]] && hash svn 2>/dev/null; then
echo
echo "Fetching: ${PWD##*/}, using svn..."
svn checkout "$svn/trunk" .
printf 'r%s' "$(svn info | awk '/^Revision:/{ print $2 }')" > "${PWD##*/}-version"
return
elif [[ $pkg ]]; then
echo
echo "Fetching: ${PWD##*/}, using package..."
fetch "$pkg"
if [[ $pkg = *.tar.gz || $pkg = *.tgz ]]; then
tar -xvzf "${pkg##*/}"
files=(!("${pkg##*/}"))
if [[ -d $files ]] && (( ${#files[@]} == 1 )); then
mv "$files"/* .
rmdir "$files"
fi
fi
return
fi
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() {
echo
echo "Checking dependency: $1..."
[[ -e "lib/$1/.built" ]] && return
pushd "lib/$1"
files=( * )
[[ -e $files ]] || fetchSource
echo
echo "Configuring dependency: $1..."
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 $1. Please install automake and autoconf."
exit 1
fi
aclocal
autoheader
autoconf
mkdir -p config.aux
automake --add-missing
fi
fi
if [[ -e configure ]]; then
./configure
fi
echo
echo "Building dependency: $1..."
if [[ -e Makefile ]]; then
if ! hash make; then
echo >&2 "Need make to build $1. Please install GNU make."
exit 1
fi
make
date > .built
else
echo >&2 "error: Don't know how to build: $1"
exit 1
fi
popd
}
2014-10-15 20:26:09 +00:00
### MPW
mpw() {
depend scrypt
echo
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() {
depend scrypt
depend bcrypt
echo
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
cc() {
if hash llvm-gcc 2>/dev/null; then
llvm-gcc "$@"
elif hash gcc 2>/dev/null; then
gcc -std=gnu99 "$@"
else
echo >&2 "Need a compiler. Please install GCC or LLVM."
exit 1
fi
}
echo "Will build targets: ${targets[*]}${options:+, using options: ${options[*]}}..."
2014-10-15 20:26:09 +00:00
for target in "${targets[@]}"; do
"$target" "$@"
done