2014-06-10 20:25:35 +00:00
|
|
|
#!/usr/bin/env bash
|
2014-10-15 18:00:44 +00:00
|
|
|
#
|
|
|
|
# TROUBLESHOOTING
|
2014-11-21 13:06:29 +00:00
|
|
|
# - Take a look at the "Optional features" section. Some features have dependencies,
|
|
|
|
# either make sure you have them or disable those features.
|
2017-03-06 23:18:25 +00:00
|
|
|
# eg. mpw_color=0 ./build
|
2014-10-15 18:00:44 +00:00
|
|
|
#
|
|
|
|
# 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-19 00:56:28 +00:00
|
|
|
|
|
|
|
### CONFIGURATION
|
|
|
|
# Targets to build.
|
|
|
|
if [[ $targets ]]; then
|
|
|
|
read -ra targets <<< "$targets"
|
|
|
|
else
|
|
|
|
# Default targets.
|
|
|
|
# Modify here or override using targets='mpw mpw-bench' ./build
|
|
|
|
targets=(
|
2017-08-27 15:17:45 +00:00
|
|
|
mpw # C CLI version of Master Password (needs: mpw_sodium, optional: mpw_color, mpw_json).
|
|
|
|
#mpw-bench # C CLI Master Password benchmark utility (needs: mpw_sodium).
|
|
|
|
#mpw-tests # C Master Password algorithm test suite (needs: mpw_sodium, mpw_xml).
|
2014-10-19 00:56:28 +00:00
|
|
|
)
|
|
|
|
fi
|
2014-10-15 18:00:44 +00:00
|
|
|
|
2014-11-21 13:06:29 +00:00
|
|
|
# Optional features.
|
2017-08-27 15:17:45 +00:00
|
|
|
mpw_sodium=${mpw_sodium:-1} # Implement crypto functions with sodium (depends on libsodium).
|
|
|
|
mpw_json=${mpw_json:-1} # Support JSON-based user configuration format (depends on libjson-c).
|
|
|
|
mpw_color=${mpw_color:-1} # Colorized identicon (depends on libncurses).
|
|
|
|
mpw_xml=${mpw_xml:-1} # XML parsing (depends on libxml2).
|
2014-11-21 13:06:29 +00:00
|
|
|
|
2017-04-08 18:25:54 +00:00
|
|
|
# Default build flags.
|
2017-08-13 15:02:05 +00:00
|
|
|
cflags=( -O3 $CFLAGS )
|
|
|
|
ldflags=( $LDFLAGS )
|
2017-04-08 18:25:54 +00:00
|
|
|
|
2017-08-08 04:00:14 +00:00
|
|
|
# Version.
|
|
|
|
if { mpw_version=$(git describe --match '*-cli*' --long --dirty --broken) || mpw_version=$(<VERSION); } 2>/dev/null; then
|
2017-08-13 15:02:05 +00:00
|
|
|
cflags+=( -D"MP_VERSION=$mpw_version" )
|
2017-08-08 04:00:14 +00:00
|
|
|
fi
|
2017-08-27 15:17:45 +00:00
|
|
|
echo 2>&1 "Current mpw source version ${mpw_version:-<unknown>}..."
|
2017-08-08 04:00:14 +00:00
|
|
|
|
2014-10-15 18:00:44 +00:00
|
|
|
|
2017-08-27 15:17:45 +00:00
|
|
|
### TARGET: MPW
|
2014-10-15 20:26:09 +00:00
|
|
|
mpw() {
|
2017-08-13 15:02:05 +00:00
|
|
|
# dependencies
|
2017-08-27 15:17:45 +00:00
|
|
|
use_mpw_sodium
|
|
|
|
use_mpw_color
|
|
|
|
use_mpw_json
|
2014-10-16 02:17:49 +00:00
|
|
|
|
2017-08-13 15:02:05 +00:00
|
|
|
# target
|
2017-08-27 15:17:45 +00:00
|
|
|
cflags=(
|
2017-08-13 15:02:05 +00:00
|
|
|
"${cflags[@]}"
|
2017-04-08 18:25:54 +00:00
|
|
|
|
2017-03-21 18:07:40 +00:00
|
|
|
# library paths
|
2014-12-19 14:00:38 +00:00
|
|
|
-I"lib/include"
|
2017-03-21 18:07:40 +00:00
|
|
|
# mpw paths
|
|
|
|
-I"core" -I"cli"
|
2014-10-15 20:26:09 +00:00
|
|
|
)
|
2017-08-13 15:02:05 +00:00
|
|
|
local ldflags=(
|
|
|
|
"${ldflags[@]}"
|
2014-10-15 20:26:09 +00:00
|
|
|
)
|
2017-08-13 15:02:05 +00:00
|
|
|
|
|
|
|
# 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 ./$_"
|
2014-10-15 20:26:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-27 15:17:45 +00:00
|
|
|
### TARGET: MPW-BENCH
|
2014-10-15 20:26:09 +00:00
|
|
|
mpw-bench() {
|
2017-08-13 15:02:05 +00:00
|
|
|
# dependencies
|
2017-08-27 15:17:45 +00:00
|
|
|
use_mpw_sodium
|
2014-10-16 02:17:49 +00:00
|
|
|
|
2017-08-13 15:02:05 +00:00
|
|
|
# target
|
2017-08-27 15:17:45 +00:00
|
|
|
cflags=(
|
2017-08-13 15:02:05 +00:00
|
|
|
"${cflags[@]}"
|
2017-04-08 18:25:54 +00:00
|
|
|
|
2017-03-21 18:07:40 +00:00
|
|
|
# library paths
|
2014-12-19 14:00:38 +00:00
|
|
|
-I"lib/include"
|
2017-03-21 18:07:40 +00:00
|
|
|
# mpw paths
|
|
|
|
-I"core" -I"cli"
|
2014-10-15 20:26:09 +00:00
|
|
|
)
|
2017-08-13 15:02:05 +00:00
|
|
|
local ldflags=(
|
|
|
|
"${ldflags[@]}"
|
2014-10-15 20:26:09 +00:00
|
|
|
)
|
|
|
|
|
2017-08-13 15:02:05 +00:00
|
|
|
# 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 ./$_"
|
2014-10-15 20:26:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-27 15:17:45 +00:00
|
|
|
### TARGET: MPW-TESTS
|
2014-12-22 04:45:19 +00:00
|
|
|
mpw-tests() {
|
2017-08-13 15:02:05 +00:00
|
|
|
# dependencies
|
2017-08-27 15:17:45 +00:00
|
|
|
use_mpw_xml
|
|
|
|
use_mpw_sodium
|
2014-12-22 04:45:19 +00:00
|
|
|
|
2017-08-13 15:02:05 +00:00
|
|
|
# target
|
2017-08-27 15:17:45 +00:00
|
|
|
cflags=(
|
2017-08-13 15:02:05 +00:00
|
|
|
"${cflags[@]}"
|
2017-04-08 18:25:54 +00:00
|
|
|
|
2017-03-21 18:07:40 +00:00
|
|
|
# library paths
|
2014-12-22 04:45:19 +00:00
|
|
|
-I"lib/include"
|
2017-03-21 18:07:40 +00:00
|
|
|
# mpw paths
|
|
|
|
-I"core" -I"cli"
|
2014-12-22 04:45:19 +00:00
|
|
|
)
|
2017-08-13 15:02:05 +00:00
|
|
|
local ldflags=(
|
|
|
|
"${ldflags[@]}"
|
2014-12-22 04:45:19 +00:00
|
|
|
)
|
|
|
|
|
2017-08-13 15:02:05 +00:00
|
|
|
# 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 ./$_"
|
2014-12-22 04:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-27 15:17:45 +00:00
|
|
|
### 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
### DEPENDENCIES
|
|
|
|
use_mpw_sodium() {
|
|
|
|
! (( mpw_sodium )) && return
|
|
|
|
|
|
|
|
if ! haslib sodium; then
|
|
|
|
echo >&2 "WARNING: mpw_sodium enabled but missing sodium library, will disable mpw_sodium."
|
|
|
|
|
|
|
|
else
|
|
|
|
echo >&2 "Enabled mpw_sodium (libsodium)."
|
|
|
|
cflags+=( -D"MPW_SODIUM=1" ) ldflags+=( -l"sodium" )
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
use_mpw_color() {
|
|
|
|
! (( mpw_color )) && return
|
|
|
|
|
|
|
|
if ! haslib curses; then
|
|
|
|
echo >&2 "WARNING: mpw_color enabled but missing curses library, will disable mpw_color."
|
|
|
|
|
|
|
|
else
|
|
|
|
echo >&2 "Enabled mpw_color (libcurses)."
|
|
|
|
cflags+=( -D"MPW_COLOR=1" ) ldflags+=( -l"curses" )
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
use_mpw_json() {
|
|
|
|
! (( mpw_json )) && return
|
|
|
|
|
|
|
|
if ! haslib json-c; then
|
|
|
|
echo >&2 "WARNING: mpw_json enabled but missing json-c library, will disable mpw_json."
|
|
|
|
|
|
|
|
else
|
|
|
|
echo >&2 "Enabled mpw_json (libjson-c)."
|
|
|
|
cflags+=( -D"MPW_JSON=1" ) ldflags+=( -l"json-c" )
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
use_mpw_xml() {
|
|
|
|
! (( mpw_xml )) && return
|
|
|
|
|
|
|
|
if ! haslib xml2; then
|
|
|
|
echo >&2 "WARNING: mpw_xml enabled but missing xml2 library, will disable mpw_xml."
|
|
|
|
|
|
|
|
else
|
|
|
|
echo >&2 "Enabled mpw_xml (libxml2)."
|
|
|
|
cflags+=( -D"MPW_XML=1" -I"/usr/include/libxml2" -I"/usr/local/include/libxml2" ) ldflags+=( -l"xml2" )
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
### BUILD TARGETS
|
2014-10-19 00:56:28 +00:00
|
|
|
echo "Will build targets: ${targets[*]}..."
|
2014-10-15 20:26:09 +00:00
|
|
|
for target in "${targets[@]}"; do
|
2017-08-27 15:17:45 +00:00
|
|
|
echo
|
|
|
|
echo "Building target: $target..."
|
|
|
|
( "$target" "$@" )
|
2014-10-15 20:26:09 +00:00
|
|
|
done
|