Skip to content

Commit f0b659a

Browse files
committed
Add bcrypt dependency and ability to compile arbitrary dependencies in C build script.
1 parent 7736788 commit f0b659a

File tree

3 files changed

+96
-39
lines changed

3 files changed

+96
-39
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ MasterPassword/Java/**/target
3434
# C
3535
MasterPassword/C/*.o
3636
MasterPassword/C/mpw
37+
MasterPassword/C/mpw-bench
3738
MasterPassword/C/lib/*/*
3839
!MasterPassword/C/lib/*/.source

MasterPassword/C/build

Lines changed: 93 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# Maarten Billemont
1212
#
1313
cd "${BASH_SOURCE%/*}"
14+
shopt -s extglob
1415
set -e
1516

1617
# optional features.
@@ -26,55 +27,105 @@ targets=(
2627

2728
### DEPENDENCIES
2829

29-
if ! [[ -e lib/scrypt/scrypt-scryptenc.o ]]; then
30-
# libscrypt not built.
31-
pushd lib/scrypt
32-
if [[ ! -e configure ]]; then
33-
# libscrypt needs configure.
34-
if [[ ! -e configure.ac ]]; then
35-
# libscrypt needs sources.
36-
source .source
37-
if hash git-svn 2>/dev/null; then
38-
echo
39-
echo "Fetching libscrypt using git-svn..."
40-
git-svn clone --prefix=origin/ --stdlayout "$svn" .
41-
printf '%s' "$(git describe --always)" > scrypt-version
42-
elif hash svn 2>/dev/null; then
43-
echo
44-
echo "Fetching libscrypt using svn..."
45-
svn checkout http://scrypt.googlecode.com/svn/trunk/ .
46-
printf 'r%s' "$(svn info | awk '/^Revision:/{ print $2 }')" > scrypt-version
47-
else
48-
echo >&2 "error: Missing git-svn or svn."
49-
echo >&2 "error: Please install either or manually check out the sources"
50-
echo >&2 "error: from: $home"
51-
echo >&2 "error: into: $PWD"
52-
exit 1
30+
fetch() {
31+
if hash wget 2>/dev/null; then
32+
wget -O "${1##*/}" "$1"
33+
elif hash curl 2>/dev/null; then
34+
curl "$1" > "${1##*/}"
35+
fi
36+
}
37+
fetchSource() (
38+
echo
39+
echo "Fetching dependency ${PWD##*/}..."
40+
source .source
41+
42+
if [[ $git ]] && hash git 2>/dev/null; then
43+
echo
44+
echo "Fetching ${PWD##*/} using git..."
45+
git-svn clone --prefix=origin/ --stdlayout "$svn" .
46+
printf '%s' "$(git describe --always)" > "${PWD##*/}-version"
47+
return
48+
49+
elif [[ $svn ]] && hash git-svn 2>/dev/null; then
50+
echo
51+
echo "Fetching ${PWD##*/} using git-svn..."
52+
git-svn clone --prefix=origin/ --stdlayout "$svn" .
53+
printf '%s' "$(git describe --always)" > "${PWD##*/}-version"
54+
return
55+
56+
elif [[ $svn ]] && hash svn 2>/dev/null; then
57+
echo
58+
echo "Fetching ${PWD##*/} using svn..."
59+
svn checkout "$svn/trunk" .
60+
printf 'r%s' "$(svn info | awk '/^Revision:/{ print $2 }')" > "${PWD##*/}-version"
61+
return
62+
63+
elif [[ $pkg ]]; then
64+
set -x
65+
fetch "$pkg"
66+
if [[ $pkg = *.tar.gz || $pkg = *.tgz ]]; then
67+
tar -xvzf "${pkg##*/}"
68+
files=(!("${pkg##*/}"))
69+
if [[ -d $files ]] && (( ${#files[@]} == 1 )); then
70+
mv "$files"/* .
71+
rmdir "$files"
5372
fi
5473
fi
74+
return
5575

56-
# Sources available.
57-
echo
58-
echo "Generating libscrypt's build scripts..."
59-
aclocal
60-
autoheader
61-
autoconf
62-
mkdir -p config.aux
63-
automake --add-missing
6476
fi
65-
66-
# configure available.
77+
78+
echo >&2 "error: Missing git-svn or svn."
79+
echo >&2 "error: Please install either or manually check out the sources"
80+
echo >&2 "error: from: $home"
81+
echo >&2 "error: into: $PWD"
82+
exit 1
83+
)
84+
depend() {
85+
6786
echo
68-
echo "Building libscrypt..."
69-
./configure
70-
make
87+
echo "Checking dependency $1..."
88+
objects=( "lib/$1"/*.o )
89+
[[ -e $objects ]] && return
90+
91+
pushd "lib/$1"
92+
files=( * )
93+
[[ -e $files ]] || fetchSource
7194

95+
echo
96+
echo "Configuring dependency $1..."
97+
if [[ -e configure.ac ]]; then
98+
if [[ ! -e configure ]]; then
99+
# create configure using autotools.
100+
aclocal
101+
autoheader
102+
autoconf
103+
mkdir -p config.aux
104+
automake --add-missing
105+
fi
106+
fi
107+
108+
if [[ -e configure ]]; then
109+
./configure
110+
fi
111+
112+
echo
113+
echo "Building dependency $1..."
114+
if [[ -e Makefile ]]; then
115+
make
116+
else
117+
echo >&2 "error: Don't know how to build: $1"
118+
exit 1
119+
fi
72120
popd
73-
fi
121+
}
74122

75123

76124
### MPW
77125
mpw() {
126+
depend scrypt
127+
128+
echo "Building target: $target..."
78129
CFLAGS=(
79130
# include paths
80131
-I"lib/scrypt/lib" -I"lib/scrypt/libcperciva"
@@ -101,6 +152,10 @@ mpw() {
101152

102153
### MPW-BENCH
103154
mpw-bench() {
155+
depend scrypt
156+
depend bcrypt
157+
158+
echo "Building target: $target..."
104159
CFLAGS=(
105160
# include paths
106161
-I"lib/scrypt/lib" -I"lib/scrypt/libcperciva"
@@ -144,6 +199,5 @@ cc() {
144199

145200
for target in "${targets[@]}"; do
146201
echo
147-
echo "Building target: $target..."
148202
"$target" "$@"
149203
done

MasterPassword/C/lib/bcrypt/.source

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
home=http://www.openwall.com/crypt/
2+
pkg=http://www.openwall.com/crypt/crypt_blowfish-1.3.tar.gz

0 commit comments

Comments
 (0)