Skip to content

Commit

Permalink
external: build lowdown if not already found.
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and niftynei committed Sep 7, 2022
1 parent 5112329 commit 50d1043
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
[submodule "external/lowdown"]
path = external/lowdown
url = https://github.com/kristapsdz/lowdown.git
ignore = dirty
9 changes: 8 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ check_command()
shift 1

echo -n "checking for $name... "
if "$@" >/dev/null 2>&1; then
if "$@" >/dev/null 2>&1 </dev/null; then
echo 'found'
return 0
fi
Expand Down Expand Up @@ -425,6 +425,12 @@ else
HAVE_PYTHON3_MAKO=0
fi

if check_command 'lowdown' lowdown; then
HAVE_LOWDOWN=1
else
HAVE_LOWDOWN=0
fi

if echo | check_command sha256sum sha256sum; then
SHA256SUM=sha256sum
elif echo | check_command "shasum -a 256" shasum -a 256; then
Expand Down Expand Up @@ -463,6 +469,7 @@ add_var ASAN "$ASAN"
add_var UBSAN "$UBSAN"
add_var TEST_NETWORK "$TEST_NETWORK"
add_var HAVE_PYTHON3_MAKO "$HAVE_PYTHON3_MAKO"
add_var HAVE_LOWDOWN "$HAVE_LOWDOWN"
add_var SHA256SUM "$SHA256SUM"
add_var FUZZING "$FUZZING"
add_var RUST "$RUST"
Expand Down
13 changes: 12 additions & 1 deletion doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,19 @@ RBRACKET=)
$(MARKDOWN_WITH_SCHEMA): doc/lightning-%.7.md: doc/schemas/%.schema.json tools/fromschema.py
@if $(call SHA256STAMP_CHANGED); then $(call VERBOSE, "fromschema $@", tools/fromschema.py --markdownfile=$@ doc/schemas/$*.schema.json > $@.tmp && grep -v SHA256STAMP: $@.tmp > $@ && rm -f $@.tmp && $(call SHA256STAMP,[comment]: # $(LBRACKET),$(RBRACKET))); else touch $@; fi

# If we need to build lowdown, make tools/md2man.sh depend on it.
# That way it's not used in SHA256STAMP (which only uses direct
# dependencies), but make will be forced to build it.
ifeq ($(HAVE_LOWDOWN),0)
LOWDOWN := $(TARGET_DIR)/lowdown-build/bin/lowdown
tools/md2man.sh: $(LOWDOWN)
touch $@
else
LOWDOWN := lowdown
endif

$(MANPAGES): doc/%: doc/%.md tools/md2man.sh version_gen.h
@if $(call SHA256STAMP_CHANGED); then $(call VERBOSE, "md2man $<", VERSION=$(VERSION) tools/md2man.sh $< > $@ && $(call SHA256STAMP,\\\",)); else touch $@; fi
@if $(call SHA256STAMP_CHANGED); then $(call VERBOSE, "md2man $<", VERSION=$(VERSION) tools/md2man.sh $(LOWDOWN) $< > $@ && $(call SHA256STAMP,\\\",)); else touch $@; fi

$(MANPAGES): $(FORCE)
$(MARKDOWN_WITH_SCHEMA): $(FORCE)
Expand Down
14 changes: 14 additions & 0 deletions external/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ SUBMODULES = \
external/libbacktrace \
external/lnprototest

ifeq ($(HAVE_LOWDOWN),0)
SUBMODULES += external/lowdown
endif

TOP := ../..
ifdef BUILD
CROSSCOMPILE_OPTS := --host="$(MAKE_HOST)" --build="$(BUILD)"
Expand All @@ -29,6 +33,10 @@ LIBBACKTRACE_HEADERS := external/libbacktrace/backtrace.h
EXTERNAL_HEADERS := $(LIBSODIUM_HEADERS) $(LIBWALLY_HEADERS) $(LIBSECP_HEADERS) $(JSMN_HEADERS) $(GHEAP_HEADERS) $(LIBBACKTRACE_HEADERS)
EXTERNAL_LIBS := ${TARGET_DIR}/libwallycore.a ${TARGET_DIR}/libsecp256k1.a ${TARGET_DIR}/libjsmn.a ${TARGET_DIR}/libbacktrace.a

ifeq ($(HAVE_LOWDOWN),0)
EXTERNAL_HEADERS += external/lowdown/lowdown.h
endif

EXTERNAL_INCLUDE_FLAGS := \
-I external/libwally-core/include/ \
-I external/libwally-core/src/secp256k1/include/ \
Expand Down Expand Up @@ -106,6 +114,10 @@ $(TARGET_DIR)/libbacktrace.a: external/libbacktrace/backtrace.h
cd $(TARGET_DIR)/libbacktrace-build && $(TOP)/libbacktrace/configure CC="$(CC)" --enable-static=yes $(CROSSCOMPILE_OPTS) --enable-shared=no --prefix=/ --libdir=/ && $(MAKE)
$(MAKE) -C $(TARGET_DIR)/libbacktrace-build DESTDIR=$$(pwd)/$(TARGET_DIR) install-exec

$(TARGET_DIR)/lowdown-build/bin/lowdown: external/lowdown/lowdown.h
cd external/lowdown && CC="$(CC)" ./configure PREFIX=`pwd`/$(TOP)/$(TARGET_DIR)/lowdown-build/
$(MAKE) -C external/lowdown install

distclean: external-distclean
clean: external-clean

Expand All @@ -116,8 +128,10 @@ external-clean:
if [ -f ${TARGET_DIR}/libwally-core-build/Makefile ]; then make -C ${TARGET_DIR}/libwally-core-build clean; fi
if [ -f ${TARGET_DIR}/libwally-core-build/src/Makefile ]; then make -C ${TARGET_DIR}/libwally-core-build/src clean; fi
if [ -f ${TARGET_DIR}/libbacktrace-build/Makefile ]; then make -C ${TARGET_DIR}/libbacktrace-build clean; fi
[ -f external/lowdown/Makefile.configure ] && $(MAKE) -C external/lowdown clean

external-distclean:
make -C external/libsodium distclean || true
[ -f external/lowdown/Makefile.configure ] && $(MAKE) -C external/lowdown distclean
$(RM) -rf ${TARGET_DIR}/libbacktrace-build ${TARGET_DIR}/libsodium-build ${TARGET_DIR}/libwally-core-build ${TARGET_DIR}/jsmn-build
$(RM) -r `git status --ignored --porcelain external/libwally-core | grep '^!! ' | cut -c3-`
9 changes: 5 additions & 4 deletions tools/md2man.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#! /bin/sh

if [ $# != 1 ]; then
echo "Usage: $0 <markdownpage>" >&2
if [ $# != 2 ]; then
echo "Usage: $0 <lowdown> <markdownpage>" >&2
exit 1
fi
SOURCE=$1
LOWDOWN="$1"
SOURCE="$2"
SECTION="$(basename "$SOURCE" .md | cut -d. -f2-)"
TITLE="$(basename "$(basename "$SOURCE" .md)" ."$SECTION" | tr '[:lower:]' '[:upper:]')"

# First two lines are title, which needs to be turned into NAME for proper manpage
# format. mrkd used to do this for us, lowdown(1) doesn't.
TITLELINE="$(head -n1 "$SOURCE")"

(echo "NAME"; echo "----"; echo "$TITLELINE"; tail -n +3 "$SOURCE") | lowdown -s --out-no-smarty -Tman -m "title:$TITLE" -m "section:$SECTION" -m "source:Core Lightning $VERSION" -m "shiftheadinglevelby:-1"
(echo "NAME"; echo "----"; echo "$TITLELINE"; tail -n +3 "$SOURCE") | $LOWDOWN -s --out-no-smarty -Tman -m "title:$TITLE" -m "section:$SECTION" -m "source:Core Lightning $VERSION" -m "shiftheadinglevelby:-1"

0 comments on commit 50d1043

Please sign in to comment.