From 1cb147c5b87969ffa22ea0cdbdc3d9fdfd5b4c97 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 8 Aug 2015 20:45:49 +0930 Subject: [PATCH] Version number, name, and build details. Signed-off-by: Rusty Russell --- .gitignore | 1 + Makefile | 13 ++++++++++--- test-cli/check-commit-sig.c | 2 ++ test-cli/close-channel.c | 2 ++ test-cli/create-anchor-tx.c | 2 ++ test-cli/create-close-tx.c | 2 ++ test-cli/create-commit-spend-tx.c | 2 ++ test-cli/create-commit-tx.c | 2 ++ test-cli/create-htlc-spend-tx.c | 2 ++ test-cli/create-steal-tx.c | 2 ++ test-cli/get-anchor-depth.c | 2 ++ test-cli/leak-anchor-sigs.c | 1 + test-cli/open-anchor.c | 2 ++ test-cli/open-channel.c | 2 ++ test-cli/open-commit-sig.c | 2 ++ test-cli/txid-of.c | 2 ++ test-cli/update-channel-accept.c | 2 ++ test-cli/update-channel-complete.c | 2 ++ test-cli/update-channel-htlc-complete.c | 2 ++ test-cli/update-channel-htlc-remove.c | 2 ++ test-cli/update-channel-htlc.c | 2 ++ test-cli/update-channel-signature.c | 2 ++ test-cli/update-channel.c | 2 ++ version.c | 11 +++++++++++ version.h | 11 +++++++++++ 25 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 version.c create mode 100644 version.h diff --git a/.gitignore b/.gitignore index 0d9b9a578..e518d9a33 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ TAGS ccan/tools/configurator/configurator libsecp256k1.a libsecp256k1.la +gen_* diff --git a/Makefile b/Makefile index ad7ed563e..ca8f13752 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ #! /usr/bin/make +NAME=MtGox's Cold Wallet # Needs to have oneof support: Ubuntu vivid's is too old :( PROTOCC:=protoc-c @@ -12,11 +13,11 @@ PROGRAMS := test-cli/open-channel test-cli/create-anchor-tx test-cli/open-commit BITCOIN_OBJS := bitcoin/address.o bitcoin/base58.o bitcoin/pubkey.o bitcoin/script.o bitcoin/shadouble.o bitcoin/signature.o bitcoin/tx.o -HELPER_OBJS := lightning.pb-c.o pkt.o permute_tx.o commit_tx.o opt_bits.o close_tx.o find_p2sh_out.o protobuf_convert.o funding.o test-cli/gather_updates.o +HELPER_OBJS := lightning.pb-c.o pkt.o permute_tx.o commit_tx.o opt_bits.o close_tx.o find_p2sh_out.o protobuf_convert.o funding.o test-cli/gather_updates.o version.o CCAN_OBJS := ccan-crypto-sha256.o ccan-crypto-shachain.o ccan-err.o ccan-tal.o ccan-tal-str.o ccan-take.o ccan-list.o ccan-str.o ccan-opt-helpers.o ccan-opt.o ccan-opt-parse.o ccan-opt-usage.o ccan-read_write_all.o ccan-str-hex.o ccan-tal-grab_file.o ccan-noerr.o ccan-crypto-ripemd160.o -HEADERS := $(wildcard *.h) $(wildcard bitcoin/*.h) +HEADERS := $(filter-out gen_*, $(wildcard *.h)) $(wildcard bitcoin/*.h) CCANDIR := ccan/ CFLAGS := -g -Wall -I $(CCANDIR) -I secp256k1/include/ -DVALGRIND_HEADERS=1 $(FEATURES) @@ -52,6 +53,12 @@ doc/deployable-lightning.pdf: doc/deployable-lightning.lyx doc/bitcoin.bib doc/deployable-lightning.tex: doc/deployable-lightning.lyx lyx -E latex $@ $< +gen_version.h: FORCE + @(echo "#define VERSION \"`git describe --always --dirty`\"" && echo "#define VERSION_NAME \"$(NAME)\"" && echo "#define BUILD_FEATURES \"$(FEATURES)\"") > $@.new + @if cmp $@.new $@ >/dev/null 2>&2; then rm -f $@.new; else mv $@.new $@; fi + +version.o: gen_version.h + update-ccan: mv ccan ccan.old DIR=$$(pwd)/ccan; cd ../ccan && ./tools/create-ccan-tree -a $$DIR `cd $$DIR.old/ccan && find * -name _info | sed s,/_info,, | sort` $(CCAN_NEW) @@ -63,7 +70,7 @@ update-ccan: $(RM) -r ccan.old distclean: clean - $(RM) lightning.pb-c.c lightning.pb-c.h ccan/config.h + $(RM) lightning.pb-c.c lightning.pb-c.h ccan/config.h gen_version.h $(RM) doc/deployable-lightning.pdf clean: diff --git a/test-cli/check-commit-sig.c b/test-cli/check-commit-sig.c index c60aec96c..34a551900 100644 --- a/test-cli/check-commit-sig.c +++ b/test-cli/check-commit-sig.c @@ -15,6 +15,7 @@ #include "bitcoin/privkey.h" #include "protobuf_convert.h" #include "funding.h" +#include "version.h" #include int main(int argc, char *argv[]) @@ -37,6 +38,7 @@ int main(int argc, char *argv[]) " []\n" "Check the commit sig is valid (either in open-anchor or commit-sig packet)", "Print this message."); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/close-channel.c b/test-cli/close-channel.c index db09d0702..f4f1c4266 100644 --- a/test-cli/close-channel.c +++ b/test-cli/close-channel.c @@ -20,6 +20,7 @@ #include "protobuf_convert.h" #include "gather_updates.h" #include "opt_bits.h" +#include "version.h" #include int main(int argc, char *argv[]) @@ -50,6 +51,7 @@ int main(int argc, char *argv[]) opt_register_arg("--close-fee=", opt_set_bits, opt_show_bits, &close_fee, "100's of satoshi to pay for close tx"); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/create-anchor-tx.c b/test-cli/create-anchor-tx.c index 2e6a9a130..171e9c7ae 100644 --- a/test-cli/create-anchor-tx.c +++ b/test-cli/create-anchor-tx.c @@ -18,6 +18,7 @@ #include #include #include "opt_bits.h" +#include "version.h" /* Bitcoin nodes are allowed to be 2 hours in the future. */ #define LOCKTIME_MIN (2 * 60 * 60) @@ -92,6 +93,7 @@ int main(int argc, char *argv[]) opt_register_arg("--anchor-fee=", opt_set_bits, opt_show_bits, &anchor_fee, "100's of satoshi to pay for anchor"); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/create-close-tx.c b/test-cli/create-close-tx.c index c96adcc15..b50788157 100644 --- a/test-cli/create-close-tx.c +++ b/test-cli/create-close-tx.c @@ -16,6 +16,7 @@ #include "protobuf_convert.h" #include "gather_updates.h" #include "funding.h" +#include "version.h" #include int main(int argc, char *argv[]) @@ -38,6 +39,7 @@ int main(int argc, char *argv[]) " [update-protobuf]...\n" "Create the close transaction from the signatures", "Print this message."); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/create-commit-spend-tx.c b/test-cli/create-commit-spend-tx.c index e6ae5784d..bb20df03e 100644 --- a/test-cli/create-commit-spend-tx.c +++ b/test-cli/create-commit-spend-tx.c @@ -20,6 +20,7 @@ #include "protobuf_convert.h" #include "test-cli/gather_updates.h" #include "funding.h" +#include "version.h" #include int main(int argc, char *argv[]) @@ -49,6 +50,7 @@ int main(int argc, char *argv[]) opt_register_arg("--fee=", opt_set_bits, opt_show_bits, &fee, "100's of satoshi to pay in transaction fee"); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/create-commit-tx.c b/test-cli/create-commit-tx.c index 8526a3e79..f8bf64c44 100644 --- a/test-cli/create-commit-tx.c +++ b/test-cli/create-commit-tx.c @@ -17,6 +17,7 @@ #include "protobuf_convert.h" #include "gather_updates.h" #include "funding.h" +#include "version.h" #include /* FIXME: this code doesn't work if we're not the ones proposing the delta */ @@ -40,6 +41,7 @@ int main(int argc, char *argv[]) " []\n" "Create the signature needed for the commit transaction", "Print this message."); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/create-htlc-spend-tx.c b/test-cli/create-htlc-spend-tx.c index 06dc4675f..42bb8c489 100644 --- a/test-cli/create-htlc-spend-tx.c +++ b/test-cli/create-htlc-spend-tx.c @@ -16,6 +16,7 @@ #include "bitcoin/privkey.h" #include "protobuf_convert.h" #include "find_p2sh_out.h" +#include "version.h" #include int main(int argc, char *argv[]) @@ -48,6 +49,7 @@ int main(int argc, char *argv[]) "Create a transaction which spends commit-tx's htlc output, and sends it P2SH to outpubkey\n" "It relies on timeout, unless --rvalue or --commit-preimage is specified", "Print this message."); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/create-steal-tx.c b/test-cli/create-steal-tx.c index feb50d26e..70a633907 100644 --- a/test-cli/create-steal-tx.c +++ b/test-cli/create-steal-tx.c @@ -14,6 +14,7 @@ #include "bitcoin/pubkey.h" #include "bitcoin/privkey.h" #include "protobuf_convert.h" +#include "version.h" #include int main(int argc, char *argv[]) @@ -37,6 +38,7 @@ int main(int argc, char *argv[]) " \n" "Create a transaction which spends commit-tx's revocable output, and sends it P2SH to outpubkey", "Print this message."); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/get-anchor-depth.c b/test-cli/get-anchor-depth.c index 5c99706a6..84387e34f 100644 --- a/test-cli/get-anchor-depth.c +++ b/test-cli/get-anchor-depth.c @@ -12,6 +12,7 @@ #include "bitcoin/signature.h" #include "commit_tx.h" #include "bitcoin/pubkey.h" +#include "version.h" #include int main(int argc, char *argv[]) @@ -25,6 +26,7 @@ int main(int argc, char *argv[]) "\n" "Prints anchor depth as contained in OpenChannel message", "Print this message."); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/leak-anchor-sigs.c b/test-cli/leak-anchor-sigs.c index b451bfa57..62e1f0cf2 100644 --- a/test-cli/leak-anchor-sigs.c +++ b/test-cli/leak-anchor-sigs.c @@ -18,6 +18,7 @@ int main(int argc, char *argv[]) "\n" "Create LeakAnchorSigsAndPretendWeDidnt to stdout", "Print this message."); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/open-anchor.c b/test-cli/open-anchor.c index 021061e1f..e0a000be3 100644 --- a/test-cli/open-anchor.c +++ b/test-cli/open-anchor.c @@ -21,6 +21,7 @@ #include #include #include "opt_bits.h" +#include "version.h" int main(int argc, char *argv[]) { @@ -44,6 +45,7 @@ int main(int argc, char *argv[]) " \n" "A test program to output open_anchor message on stdout.", "Print this message."); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/open-channel.c b/test-cli/open-channel.c index 4f8edfb2d..9fc59dcae 100644 --- a/test-cli/open-channel.c +++ b/test-cli/open-channel.c @@ -18,6 +18,7 @@ #include #include #include "opt_bits.h" +#include "version.h" /* Bitcoin nodes are allowed to be 2 hours in the future. */ #define LOCKTIME_MIN (2 * 60 * 60) @@ -58,6 +59,7 @@ int main(int argc, char *argv[]) opt_register_arg("--commitment-fee=", opt_set_bits, opt_show_bits, &commit_tx_fee, "100's of satoshi to pay for commitment"); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/open-commit-sig.c b/test-cli/open-commit-sig.c index 934fcfaea..21425a419 100644 --- a/test-cli/open-commit-sig.c +++ b/test-cli/open-commit-sig.c @@ -16,6 +16,7 @@ #include "bitcoin/privkey.h" #include "protobuf_convert.h" #include "funding.h" +#include "version.h" #include int main(int argc, char *argv[]) @@ -39,6 +40,7 @@ int main(int argc, char *argv[]) " \n" "Create the signature needed for the commit transaction", "Print this message."); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/txid-of.c b/test-cli/txid-of.c index 7f79bc48f..5ebee44e4 100644 --- a/test-cli/txid-of.c +++ b/test-cli/txid-of.c @@ -6,6 +6,7 @@ #include #include #include "bitcoin/tx.h" +#include "version.h" #include int main(int argc, char *argv[]) @@ -22,6 +23,7 @@ int main(int argc, char *argv[]) "\n" "Print txid of the transaction in the file", "Print this message."); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/update-channel-accept.c b/test-cli/update-channel-accept.c index 997e75d1c..2baa7a7fc 100644 --- a/test-cli/update-channel-accept.c +++ b/test-cli/update-channel-accept.c @@ -18,6 +18,7 @@ #include "protobuf_convert.h" #include "gather_updates.h" #include "funding.h" +#include "version.h" #include int main(int argc, char *argv[]) @@ -42,6 +43,7 @@ int main(int argc, char *argv[]) " \n" "Accept a new update message", "Print this message."); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/update-channel-complete.c b/test-cli/update-channel-complete.c index 0c64d0306..df9e5ce2f 100644 --- a/test-cli/update-channel-complete.c +++ b/test-cli/update-channel-complete.c @@ -18,6 +18,7 @@ #include "protobuf_convert.h" #include "gather_updates.h" #include "funding.h" +#include "version.h" #include int main(int argc, char *argv[]) @@ -40,6 +41,7 @@ int main(int argc, char *argv[]) " \n" "Create a new update-complete message", "Print this message."); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/update-channel-htlc-complete.c b/test-cli/update-channel-htlc-complete.c index d8afcb76c..1c09cddc1 100644 --- a/test-cli/update-channel-htlc-complete.c +++ b/test-cli/update-channel-htlc-complete.c @@ -14,6 +14,7 @@ #include "commit_tx.h" #include "bitcoin/pubkey.h" #include "find_p2sh_out.h" +#include "version.h" #include int main(int argc, char *argv[]) @@ -29,6 +30,7 @@ int main(int argc, char *argv[]) " \n" "Create a new HTLC complete message", "Print this message."); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/update-channel-htlc-remove.c b/test-cli/update-channel-htlc-remove.c index 8c6c3602b..b71e97a62 100644 --- a/test-cli/update-channel-htlc-remove.c +++ b/test-cli/update-channel-htlc-remove.c @@ -15,6 +15,7 @@ #include "bitcoin/pubkey.h" #include "find_p2sh_out.h" #include "protobuf_convert.h" +#include "version.h" #include int main(int argc, char *argv[]) @@ -31,6 +32,7 @@ int main(int argc, char *argv[]) " \n" "Create a new HTLC remove message", "Print this message."); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/update-channel-htlc.c b/test-cli/update-channel-htlc.c index a4f5540ec..211e2464b 100644 --- a/test-cli/update-channel-htlc.c +++ b/test-cli/update-channel-htlc.c @@ -14,6 +14,7 @@ #include "commit_tx.h" #include "bitcoin/pubkey.h" #include "find_p2sh_out.h" +#include "version.h" #include int main(int argc, char *argv[]) @@ -32,6 +33,7 @@ int main(int argc, char *argv[]) " \n" "Create a new HTLC update message", "Print this message."); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/update-channel-signature.c b/test-cli/update-channel-signature.c index 9133c245d..fbad4dbbf 100644 --- a/test-cli/update-channel-signature.c +++ b/test-cli/update-channel-signature.c @@ -18,6 +18,7 @@ #include "protobuf_convert.h" #include "gather_updates.h" #include "funding.h" +#include "version.h" #include int main(int argc, char *argv[]) @@ -42,6 +43,7 @@ int main(int argc, char *argv[]) " ...\n" "Create a new update-channel-signature message", "Print this message."); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/test-cli/update-channel.c b/test-cli/update-channel.c index 8608ec33a..e0bd5849f 100644 --- a/test-cli/update-channel.c +++ b/test-cli/update-channel.c @@ -14,6 +14,7 @@ #include "commit_tx.h" #include "bitcoin/pubkey.h" #include "find_p2sh_out.h" +#include "version.h" #include int main(int argc, char *argv[]) @@ -37,6 +38,7 @@ int main(int argc, char *argv[]) opt_register_arg("--from-them=", opt_set_ulonglongval_si, NULL, &from_them, "Amount to pay us (must use this or --to-them)"); + opt_register_version(); opt_parse(&argc, argv, opt_log_stderr_exit); diff --git a/version.c b/version.c new file mode 100644 index 000000000..1cf14090c --- /dev/null +++ b/version.c @@ -0,0 +1,11 @@ +#include "version.h" +#include "gen_version.h" +#include + +char *version_and_exit(const void *unused) +{ + printf("%s\n" + "aka. %s\n" + "Built with: %s\n", VERSION, VERSION_NAME, BUILD_FEATURES); + exit(0); +} diff --git a/version.h b/version.h new file mode 100644 index 000000000..8f688a0dc --- /dev/null +++ b/version.h @@ -0,0 +1,11 @@ +#ifndef LIGHTNING_VERSION_H +#define LIGHTNING_VERSION_H +#include + +char *version_and_exit(const void *unused); + +#define opt_register_version() \ + opt_register_noarg("--version|-V", version_and_exit, NULL, \ + "print version to standard output and exit") + +#endif /* LIGHTNING_VERSION_H */