From aeeab7dbf62d3f25005157ed97db4531ae65d177 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Wed, 30 Aug 2017 10:18:23 -0400 Subject: [PATCH] Improve build script documentation and targets variable. --- .gitignore | 16 -------- platform-independent/cli-c/.gitignore | 10 +++++ platform-independent/cli-c/build | 54 +++++++++++++++------------ 3 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 platform-independent/cli-c/.gitignore diff --git a/.gitignore b/.gitignore index f4f67dcb..0954e9da 100644 --- a/.gitignore +++ b/.gitignore @@ -13,8 +13,6 @@ xcuserdata/ DerivedData/ # Generated -/platform-independent/cli-c/VERSION -/platform-independent/cli-c/mpw-*.tar.gz /platform-darwin/Resources/Media/Images.xcassets/ # Media @@ -31,17 +29,3 @@ local.properties # Maven target dependency-reduced-pom.xml - -# C -core/c/*.o -core/c/lib/*/.unpacked -core/c/lib/*/.patched -core/c/lib/*/src -core/c/lib/include -platform-independent/cli-c/cli/*.o -platform-independent/cli-c/mpw-*.tar.gz -platform-independent/cli-c/mpw-*.tar.gz.sig -platform-independent/cli-c/mpw -platform-independent/cli-c/mpw-bench -platform-independent/cli-c/mpw-tests -platform-independent/cli-c/VERSION diff --git a/platform-independent/cli-c/.gitignore b/platform-independent/cli-c/.gitignore new file mode 100644 index 00000000..ee9eeb7b --- /dev/null +++ b/platform-independent/cli-c/.gitignore @@ -0,0 +1,10 @@ +*.o +*.dSYM + +mpw +mpw-bench +mpw-tests + +VERSION +mpw-*.tar.gz +mpw-*.tar.gz.sig diff --git a/platform-independent/cli-c/build b/platform-independent/cli-c/build index 4c971b01..a89f39ee 100755 --- a/platform-independent/cli-c/build +++ b/platform-independent/cli-c/build @@ -1,9 +1,19 @@ #!/usr/bin/env bash # -# TROUBLESHOOTING -# - Take a look at the "Optional features" section. Some features have dependencies, -# either make sure you have them or disable those features. -# eg. mpw_color=0 ./build +# USAGE +# [targets='...'] [mpw_feature=0|1 ...] [CFLAGS='...'] [LDFLAGS='...'] ./build [cc arguments ...] +# +# By default, you should only need to run ./build +# +# You can customize the targets that are built using targets='...'. Use targets='all' to build all targets. +# By default, we only build the 'mpw' target. +# See targets_all for all possible targets as well as the features they support and require. +# +# Several features can be enabled or disabled using feature flags. +# See the Features section for an overview of the features, their default setting, their meaning and their dependencies. +# You will need to have each of the feature's dependencies installed for the build to succeed with that feature enabled. +# +# Finally, the C compiler can be tuned using CFLAGS, LDFLAGS and compiler arguments passed to the script. # # BUGS # masterpassword@lyndir.com @@ -18,19 +28,14 @@ set -e ### 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=( - 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). - ) -fi +targets_all=( + 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). +) +targets_default='mpw' # Override with: targets='...' ./build -# Optional features. +# Features. 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). @@ -76,7 +81,7 @@ mpw() { 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 ./$_" + echo "done! You can now run ./mpw-cli-tests, ./install or use ./$_" } @@ -105,7 +110,7 @@ mpw-bench() { 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 ./$_" + echo "done! You can now use ./$_" } @@ -136,7 +141,7 @@ mpw-tests() { 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 ./$_" + echo "done! You can now use ./$_" } @@ -206,9 +211,10 @@ use_mpw_xml() { ### BUILD TARGETS -echo "Will build targets: ${targets[*]}..." -for target in "${targets[@]}"; do - echo - echo "Building target: $target..." - ( "$target" "$@" ) +for target in "${targets_all[@]}"; do + if [[ ${targets:-$targets_default} == 'all' || " $target " = *" ${targets:-$targets_default} "* ]]; then + echo + echo "Building target: $target..." + ( "$target" "$@" ) + fi done