commit ab3416055ed506c5bc2b691cd064b329042ad512
parent 36d5e031341c6be28c475f367cecbc4cf0013172
Author: William Casarin <jb55@jb55.com>
Date: Sun, 16 Jan 2022 09:31:06 -0800
make and bake
Diffstat:
2 files changed, 59 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
@@ -2,38 +2,50 @@
CFLAGS=-Wall -g -Og -Ideps/secp256k1/include -Ideps/libsodium/src/libsodium/include -Ideps
LDFLAGS=
+SUBMODULES = \
+ deps/libsodium \
+ deps/secp256k1
+
ARS=deps/secp256k1/.libs/libsecp256k1.a deps/libsodium/src/libsodium/.libs/libsodium.a
OBJS=sha256.o hkdf.o hmac.o sha512.o lnsocket.o error.o handshake.o
DEPS=$(OBJS) config.h
all: test
+submodcheck: $(FORCE)
+ @tools/refresh-submodules.sh $(SUBMODULES)
+
config.h: configurator
./configurator > $@
configurator: configurator.c
$(CC) $< -o $@
-%.o: %.c config.h
+%.o: %.c config.h $(ARS)
@echo "cc $<"
@$(CC) $(CFLAGS) -c $< -o $@
deps/secp256k1/src/libsecp256k1-config.h: deps/secp256k1/configure
+ cd deps/secp256k1; \
./configure --enable-module-ecdh
-deps/secp256k1/configure:
+deps/libsodium/src/config.status: deps/libsodium/configure
+ cd deps/libsodium; \
+ ./configure
+
+deps/secp256k1/configure: submodcheck
cd deps/secp256k1; \
./autogen.sh
-deps/libsodium/configure:
+deps/libsodium/configure: submodcheck
cd deps/libsodium; \
./autogen.sh
-deps/secp256k1/.libs/libsecp256k1.a: deps/secp256k1/configure
+deps/secp256k1/.libs/libsecp256k1.a: deps/secp256k1/src/libsecp256k1-config.h
cd deps/secp256k1; \
make -j2 libsecp256k1.la
-deps/libsodium/src/libsodium/.libs/libsodium.a: deps/libsodium/configure
+deps/libsodium/src/libsodium/.libs/libsodium.a: deps/libsodium/src/config.status
cd deps/libsodium/src/libsodium; \
make -j2 libsodium.la
diff --git a/tools/refresh-submodules.sh b/tools/refresh-submodules.sh
@@ -0,0 +1,42 @@
+#! /bin/sh
+
+if [ $# = 0 ]; then
+ echo "Usage: $0 <submoduledir1>..." >&2
+ exit 1
+fi
+
+# If no git dir (or, if we're a submodule, git file), forget it.
+[ -e .git ] || exit 0
+
+# git submodule can't run in parallel. Really.
+# Wait for it to finish if in parallel.
+if ! mkdir .refresh-submodules 2>/dev/null ; then
+ # If we don't make progress in ~60 seconds, force delete and retry.
+ LIMIT=$((50 + $$ % 20))
+ i=0
+ while [ $i -lt $LIMIT ]; do
+ [ -d .refresh-submodules ] || exit 0
+ sleep 1
+ i=$((i + 1))
+ done
+ rmdir .refresh-submodules
+ exec "$0" "$@" || exit 1
+fi
+
+trap "rmdir .refresh-submodules" EXIT
+
+# Be a little careful here, since we do rm -rf!
+for m in "$@"; do
+ if ! grep -q "path = $m\$" .gitmodules; then
+ echo "$m is not a submodule!" >&2
+ exit 1
+ fi
+done
+
+# git submodule can segfault. Really.
+if [ "$(git submodule status "$@" | grep -c '^ ')" != $# ]; then
+ echo Reinitializing submodules "$@" ...
+ git submodule sync "$@"
+ rm -rf "$@"
+ git submodule update --init --recursive "$@"
+fi