diff --git a/.gitmodules b/.gitmodules index d586dadaf2a5..cedab2e4d4bc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "daemon/jsmn"] path = daemon/jsmn url = https://github.com/zserge/jsmn +[submodule "bitcoin/libbase58"] + path = bitcoin/libbase58 + url = https://github.com/bitcoin/libbase58.git diff --git a/INSTALL.md b/INSTALL.md index 42341d09d089..4e63bf88a719 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -5,7 +5,6 @@ You will need several development libraries: * libprotoc: the Google protocol buffer v2 library, 2.6.0 or above. * protobuf-c: version 1.1.0 or above. * libsodium: for crypto. -* libbase58: for bitcoin's base58 encoding. * libsqlite3: for database support. * libgmp: for secp256k1 * asciidoc: for formatting the man page (if you change them) @@ -18,7 +17,7 @@ To Build on Ubuntu 16.04 Get dependencies: ``` -sudo apt-get install autoconf libtool libprotobuf-c-dev libsodium-dev libbase58-dev libsqlite3-dev libgmp-dev libsqlite3-dev asciidoc +sudo apt-get install autoconf libtool libprotobuf-c-dev libsodium-dev libsqlite3-dev libgmp-dev libsqlite3-dev asciidoc ``` Clone lightning and initialize submodules: diff --git a/Makefile b/Makefile index 79c15230782e..77e488fd18c0 100644 --- a/Makefile +++ b/Makefile @@ -179,11 +179,14 @@ CWARNFLAGS := -Werror -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations CDEBUGFLAGS := -g -fstack-protector CFLAGS := $(CWARNFLAGS) $(CDEBUGFLAGS) -I $(CCANDIR) -I secp256k1/include/ -I . $(FEATURES) -LDLIBS := -lprotobuf-c -lgmp -lsodium -lbase58 -lsqlite3 +LDLIBS := -lprotobuf-c -lgmp -lsodium -lsqlite3 $(PROGRAMS): CFLAGS+=-I. default: $(PROGRAMS) $(MANPAGES) daemon-all +include bitcoin/Makefile +include wire/Makefile + # Git doesn't maintain timestamps, so we only regen if git says we should. CHANGED_FROM_GIT = [ x"`git log $@ | head -n1`" != x"`git log $< | head -n1`" -o x"`git diff $<`" != x"" ] @@ -194,7 +197,7 @@ $(MANPAGES): doc/%: doc/%.txt $(CCAN_OBJS) $(CDUMP_OBJS) $(HELPER_OBJS) $(BITCOIN_OBJS) $(TEST_PROGRAMS:=.o) ccan/ccan/cdump/tools/cdump-enumstr.o: $(CCAN_HEADERS) # Except for CCAN, everything depends on bitcoin/ and core headers. -$(HELPER_OBJS) $(CORE_OBJS) $(BITCOIN_OBJS) $(TEST_PROGRAMS:=.o): $(BITCOIN_HEADERS) $(CORE_HEADERS) $(CCAN_HEADERS) $(GEN_HEADERS) +$(HELPER_OBJS) $(CORE_OBJS) $(BITCOIN_OBJS) $(LIBBASE58_OBJS) $(WIRE_OBJS) $(TEST_PROGRAMS:=.o): $(BITCOIN_HEADERS) $(CORE_HEADERS) $(CCAN_HEADERS) $(GEN_HEADERS) $(LIBBASE58_HEADERS) test-protocol: test/test_protocol set -e; TMP=`mktemp`; for f in test/commits/*.script; do if ! $(VALGRIND) test/test_protocol < $$f > $$TMP; then echo "test/test_protocol < $$f FAILED" >&2; exit 1; fi; diff -u $$TMP $$f.expected; done; rm $$TMP @@ -206,9 +209,6 @@ protocol-diagrams: $(patsubst %.script, doc/protocol-%.svg, $(notdir $(wildcard check: test-protocol -include bitcoin/Makefile -include wire/Makefile - # Keep includes in alpha order. check-src-include-order/%: % @if [ "$$(grep '^#include' < $<)" != "$$(grep '^#include' < $< | LC_ALL=C sort)" ]; then echo "$<:1: includes out of order"; grep '^#include' < $<; echo VERSUS; grep '^#include' < $< | LC_ALL=C sort; exit 1; fi @@ -260,7 +260,7 @@ secp256k1/libsecp256k1.la: lightning.pb-c.c lightning.pb-c.h: lightning.proto @if $(CHANGED_FROM_GIT); then echo $(PROTOCC) lightning.proto --c_out=.; $(PROTOCC) lightning.proto --c_out=.; else touch $@; fi -$(TEST_PROGRAMS): % : %.o $(BITCOIN_OBJS) $(WIRE_OBJS) $(CCAN_OBJS) utils.o version.o libsecp256k1.a +$(TEST_PROGRAMS): % : %.o $(BITCOIN_OBJS) $(LIBBASE58_OBJS) $(WIRE_OBJS) $(CCAN_OBJS) utils.o version.o libsecp256k1.a ccan/config.h: ccan/tools/configurator/configurator if $< > $@.new; then mv $@.new $@; else rm $@.new; exit 1; fi diff --git a/bitcoin/Makefile b/bitcoin/Makefile index 28e67a968949..6dd2dea20c12 100644 --- a/bitcoin/Makefile +++ b/bitcoin/Makefile @@ -14,3 +14,23 @@ $(BITCOIN_TEST_OBJS): $(CCAN_HEADERS) $(BITCOIN_HEADERS) $(BITCOIN_SRC) check: bitcoin-tests bitcoin-tests: $(BITCOIN_TEST_PROGRAMS:%=unittest/%) + +LIBBASE58_HEADERS := bitcoin/libbase58/libbase58.h + +LIBBASE58_SRC := bitcoin/libbase58/base58.c + +# Can't be inside submodule, as that makes git think it's dirty. +LIBBASE58_OBJS := bitcoin/libbase58.o + +# Git submodules are seriously broken. +bitcoin/libbase58/libbase58.h: + git submodule update bitcoin/libbase58/ + [ -f $@ ] || git submodule update --init bitcoin/libbase58/ + +# If we tell Make that the above builds both, it runs it twice in +# parallel. So we lie :( +bitcoin/libbase58/base58.c: bitcoin/libbase58/libbase58.h + [ -f $@ ] + +bitcoin/libbase58.o: bitcoin/libbase58/base58.c + $(COMPILE.c) $(OUTPUT_OPTION) $< diff --git a/bitcoin/base58.c b/bitcoin/base58.c index d45c906af707..07f94de20f73 100644 --- a/bitcoin/base58.c +++ b/bitcoin/base58.c @@ -5,6 +5,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "address.h" #include "base58.h" +#include "libbase58/libbase58.h" #include "privkey.h" #include "pubkey.h" #include "shadouble.h" @@ -12,7 +13,6 @@ #include #include #include -#include #include #include diff --git a/bitcoin/libbase58 b/bitcoin/libbase58 new file mode 160000 index 000000000000..16c252760805 --- /dev/null +++ b/bitcoin/libbase58 @@ -0,0 +1 @@ +Subproject commit 16c2527608053d2cc2fa05b2e3b5ae96065d1410 diff --git a/daemon/Makefile b/daemon/Makefile index 06cced2331bd..2e613c7f50f1 100644 --- a/daemon/Makefile +++ b/daemon/Makefile @@ -130,9 +130,9 @@ daemon/jsmn/jsmn.c: daemon/jsmn/jsmn.h daemon/jsmn.o: daemon/jsmn/jsmn.c $(COMPILE.c) -DJSMN_STRICT=1 $(OUTPUT_OPTION) $< -daemon/lightningd: $(DAEMON_OBJS) $(DAEMON_LIB_OBJS) $(DAEMON_JSMN_OBJS) $(CORE_OBJS) $(BITCOIN_OBJS) $(WIRE_OBJS) $(CCAN_OBJS) libsecp256k1.a +daemon/lightningd: $(DAEMON_OBJS) $(DAEMON_LIB_OBJS) $(DAEMON_JSMN_OBJS) $(CORE_OBJS) $(BITCOIN_OBJS) $(LIBBASE58_OBJS) $(WIRE_OBJS) $(CCAN_OBJS) libsecp256k1.a -daemon/lightning-cli: $(DAEMON_CLI_OBJS) $(DAEMON_LIB_OBJS) $(DAEMON_JSMN_OBJS) $(CORE_OBJS) $(BITCOIN_OBJS) $(WIRE_OBJS) $(CCAN_OBJS) libsecp256k1.a +daemon/lightning-cli: $(DAEMON_CLI_OBJS) $(DAEMON_LIB_OBJS) $(DAEMON_JSMN_OBJS) $(CORE_OBJS) $(BITCOIN_OBJS) $(LIBBASE58_OBJS) $(WIRE_OBJS) $(CCAN_OBJS) libsecp256k1.a daemon-clean: $(RM) $(DAEMON_OBJS) $(DAEMON_LIB_OBJS) $(DAEMON_CLI_OBJS) $(DAEMON_JSMN_OBJS) $(DAEMON_GEN_HEADERS) diff --git a/daemon/test/Makefile b/daemon/test/Makefile index b3b38d5ee25e..4e30d2d28556 100644 --- a/daemon/test/Makefile +++ b/daemon/test/Makefile @@ -78,7 +78,7 @@ update-mocks-daemon/test/%: daemon/test/% update-mocks: $(DAEMON_TEST_SRC:%=update-mocks-%) -$(DAEMON_TEST_PROGRAMS): $(CCAN_OBJS) $(BITCOIN_OBJS) libsecp256k1.a utils.o +$(DAEMON_TEST_PROGRAMS): $(CCAN_OBJS) $(BITCOIN_OBJS) $(LIBBASE58_OBJS) libsecp256k1.a utils.o $(DAEMON_TEST_OBJS): $(DAEMON_HEADERS) $(DAEMON_JSMN_HEADERS) $(BITCOIN_HEADERS) $(CORE_HEADERS) $(GEN_HEADERS) $(DAEMON_GEN_HEADERS) $(CCAN_HEADERS) diff --git a/wire/test/Makefile b/wire/test/Makefile index 7d375169ad44..ff3da731dc87 100644 --- a/wire/test/Makefile +++ b/wire/test/Makefile @@ -8,7 +8,7 @@ WIRE_TEST_PROGRAMS := $(WIRE_TEST_OBJS:.o=) update-mocks: $(WIRE_TEST_SRC:%=update-mocks/%) -$(WIRE_TEST_PROGRAMS): $(CCAN_OBJS) $(BITCOIN_OBJS) libsecp256k1.a utils.o +$(WIRE_TEST_PROGRAMS): $(CCAN_OBJS) $(BITCOIN_OBJS) $(LIBBASE58_OBJS) libsecp256k1.a utils.o $(WIRE_TEST_OBJS): $(WIRE_HEADERS) $(BITCOIN_HEADERS) $(CORE_HEADERS) $(GEN_HEADERS) $(WIRE_GEN_HEADERS) $(WIRE_GEN_SRC) $(CCAN_HEADERS)