2021-03-19 15:59:59 +00:00
|
|
|
#! /usr/bin/make -f
|
|
|
|
|
|
|
|
SAVED_PATH := $(PATH)
|
|
|
|
PWD := $(shell pwd)
|
|
|
|
|
2021-03-22 16:06:28 +00:00
|
|
|
ifeq ($(MSYSTEM),MINGW32)
|
|
|
|
# Under MinGW, the NIM doc compiler wants absolute pathname arguments
|
|
|
|
# looking like C:\\MinGW\\msys\\1.0\\home ...
|
|
|
|
DOC_ROOT := `pwd -W|sed 's|/|\\\\\\\\|g'`
|
|
|
|
else
|
|
|
|
DOC_ROOT := $(PWD)
|
|
|
|
endif
|
|
|
|
|
2021-03-19 15:59:59 +00:00
|
|
|
# Collect document names
|
|
|
|
SFX_FILTER := sed -e 's|^\./||;/\/\./d;/^docs\//d;s/\.[a-z]*$$//'
|
2021-06-04 17:20:37 +00:00
|
|
|
PNG_FILES := $(shell find -L . -name '*.png' -print|$(SFX_FILTER))
|
|
|
|
MD_FILES := $(shell find -L . -name '*.md' -print|$(SFX_FILTER))
|
|
|
|
EXE_FILES := $(shell find -L . -name '*.nim' -print|$(SFX_FILTER))
|
|
|
|
TXE_FILES := $(shell find -L ../tests -name '*.nim' -print|$(SFX_FILTER))
|
2021-03-19 15:59:59 +00:00
|
|
|
|
|
|
|
# Needed for the NIM compiler that comes with this repo
|
|
|
|
NIMBLE_DIR := $(dir $(PWD))/vendor/.nimble
|
|
|
|
NIM_PATH := $(dir $(PWD))/vendor/nimbus-build-system/vendor/Nim/bin
|
|
|
|
|
2021-03-22 16:06:28 +00:00
|
|
|
# Support for verbosity: V=1, V=2 etc.
|
|
|
|
ifneq ($(if $V,$V,0),0)
|
2021-03-19 15:59:59 +00:00
|
|
|
MUFFLE :=
|
|
|
|
else
|
|
|
|
MUFFLE := 2>/dev/null
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Support for external NIM compiler unless X=0
|
2023-02-01 18:56:06 +00:00
|
|
|
ifneq ($(if $X,$X,0),0)
|
2021-03-19 15:59:59 +00:00
|
|
|
PATH := $(SAVED_PATH):$(NIM_PATH):$(NIMBLE_DIR)/bin
|
|
|
|
else
|
|
|
|
PATH := $(NIM_PATH):$(NIMBLE_DIR)/bin:$(SAVED_PATH)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Compat version is used with external NIM compiler
|
2023-02-01 18:56:06 +00:00
|
|
|
# NIM_COMPAT := --useVersion:1.2
|
2021-03-19 15:59:59 +00:00
|
|
|
|
2021-04-12 15:36:00 +00:00
|
|
|
# Name of NIMDOC compiler, test for newer version on host OS
|
2021-03-19 15:59:59 +00:00
|
|
|
NIM_CMD := nim
|
|
|
|
NIM_TEST := $(NIM_CMD) $(NIM_COMPAT) --help >/dev/null 2>&1
|
|
|
|
NIM_SELECT := $(NIM_TEST) && echo "$(NIM_CMD) $(NIM_COMPAT)"|| echo "$(NIM_CMD)"
|
|
|
|
# Note that the back ticks are needed in the following assignment
|
|
|
|
NIM_EXE := `$(NIM_SELECT)`
|
|
|
|
|
2021-04-12 15:36:00 +00:00
|
|
|
# Extra nimdoc flags
|
|
|
|
NIMDOC_FLAGS := --verbosity:0 --hints:off --warnings:off
|
|
|
|
NIMDOC_FLAGS += -d:debug -d:disable_libbacktrace
|
|
|
|
NIMDOC_FLAGS += $(NIMFLAGS)
|
|
|
|
|
2021-04-26 12:03:20 +00:00
|
|
|
# Nim check flags
|
|
|
|
NIMCHK_FLAGS := c -r --verbosity:0 --hints:off --warnings:off
|
|
|
|
|
2021-03-19 15:59:59 +00:00
|
|
|
# Markdown compiler (test for discount tool with tables support)
|
|
|
|
MD_CMD := markdown
|
|
|
|
MD_TEST := $(MD_CMD) -VV 2>/dev/null|grep -q TABLES
|
|
|
|
|
|
|
|
# Default target
|
|
|
|
default: help
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Help page
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.SILENT: help
|
|
|
|
help::
|
|
|
|
echo "Usage: $(MAKE) <target> [<option> ..]"
|
|
|
|
echo
|
|
|
|
echo "<option>: V=1 -- verbose mode"
|
2023-02-01 18:56:06 +00:00
|
|
|
echo " X=1 -- preferring local nim compiler (this repo)"
|
2021-04-12 15:36:00 +00:00
|
|
|
echo " NIMFLAGS=.. -- additional flags for nim-docs generator"
|
2021-03-19 15:59:59 +00:00
|
|
|
echo
|
|
|
|
echo "<target>: docs -- build NIM docs"
|
|
|
|
echo " docs-update -- process missing doc pages"
|
|
|
|
echo " docs-index -- index collected docs"
|
|
|
|
echo
|
2021-04-26 12:03:20 +00:00
|
|
|
echo " check_vm -- run \"nim c -r ..\" on each native VM source file"
|
|
|
|
echo
|
2021-03-19 15:59:59 +00:00
|
|
|
echo " clean -- clean up generated and backup files (not docs)"
|
|
|
|
echo " clean-exe -- clean up generated executables"
|
|
|
|
echo " clean-docs -- clean up generated docs and extra files"
|
|
|
|
echo
|
|
|
|
echo " distclean -- purge unnecessary stuff including docs"
|
|
|
|
echo " clobber -- same as distclean"
|
|
|
|
echo
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2021-04-26 12:03:20 +00:00
|
|
|
# Build indexed docs
|
2021-03-19 15:59:59 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2021-04-12 15:36:00 +00:00
|
|
|
# Automatic rule for updating single html/idx file
|
2021-03-19 15:59:59 +00:00
|
|
|
docs/%.html : %.nim
|
|
|
|
# use compat option if it works with the nim compiler
|
|
|
|
@mkdir -p docs
|
2021-03-22 16:06:28 +00:00
|
|
|
@nim=$(NIM_EXE); doc_root="$(DOC_ROOT)"; \
|
2021-04-12 15:36:00 +00:00
|
|
|
export NIMBLE_DIR=$(NIMBLE_DIR); \
|
2021-03-22 16:06:28 +00:00
|
|
|
(set -x; $$nim doc --outdir:docs --docRoot:"$$doc_root" --index:on \
|
2022-09-26 04:56:54 +00:00
|
|
|
--errorMax:0 $(NIMDOC_FLAGS) \
|
2021-03-19 15:59:59 +00:00
|
|
|
"$<" $(MUFFLE)) || true
|
|
|
|
|
2021-04-12 15:36:00 +00:00
|
|
|
# Automatic rule for updating markdown files
|
2021-03-19 15:59:59 +00:00
|
|
|
docs/ex/%.html : %.md
|
|
|
|
@mkdir -p $(dir $@)
|
|
|
|
@if $(MD_TEST); then \
|
|
|
|
(set -x; $(MD_CMD) "$<"); \
|
|
|
|
else \
|
|
|
|
(echo "<pre>";(set -x;cat "$<");echo "</pre>"); \
|
|
|
|
fi > "$@"
|
|
|
|
|
2021-04-12 15:36:00 +00:00
|
|
|
# Automatic rule for collecting raw files
|
2021-03-19 15:59:59 +00:00
|
|
|
docs/ex/%.png : %.png
|
|
|
|
@mkdir -p $(dir $@)
|
|
|
|
@set -x; cp "$<" "$@"
|
|
|
|
|
|
|
|
.PHONY: docs-index-helper
|
|
|
|
.SILENT: docs-index-helper
|
2023-02-01 18:56:06 +00:00
|
|
|
docs-index-helper:
|
2021-03-19 15:59:59 +00:00
|
|
|
nim=$(NIM_EXE); \
|
|
|
|
$$nim --version | sed q ; set -x ;\
|
|
|
|
$$nim --skipProjCfg buildIndex -o:docs/theindex.html \
|
|
|
|
--verbosity:0 --hints:off --warnings:off docs
|
|
|
|
|
|
|
|
.PHONY: docs-update-helper
|
|
|
|
.SILENT: docs-update-helper
|
|
|
|
docs-update-helper::
|
|
|
|
$(NIM_EXE) --version | sed q
|
|
|
|
|
|
|
|
docs-update-helper:: $(foreach f,$(EXE_FILES),docs/$f.html)
|
|
|
|
|
|
|
|
# Kludge: some docs would only compile with the local NIM compiler
|
|
|
|
ifneq ($(X),0)
|
|
|
|
docs-update-helper::
|
|
|
|
$(MAKE) docs-update-helper X=0 V=$(V)
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
.PHONY: docs-extra-helper
|
|
|
|
.SILENT: docs-extra-helper
|
|
|
|
docs-extra-helper::
|
|
|
|
$(MD_TEST) || ( \
|
|
|
|
echo ;\
|
|
|
|
echo "*** Discount markdown command with table processing is unavailable." ;\
|
|
|
|
echo " On Debian/Ubuntu it is installed via \"apt install discount\".";\
|
|
|
|
echo " So \"make\" is going to fall back to text file wrapping which can" ;\
|
|
|
|
echo " be changed by passing \"MD_TEST=true\" to the \"make\" command line." ;\
|
|
|
|
echo ;\
|
|
|
|
)
|
|
|
|
|
|
|
|
docs-extra-helper:: $(foreach f,$(MD_FILES),docs/ex/$f.html)
|
|
|
|
docs-extra-helper:: $(foreach f,$(PNG_FILES),docs/ex/$f.png)
|
|
|
|
|
|
|
|
|
|
|
|
.PHONY: docs-update
|
|
|
|
.SILENT: docs-update
|
|
|
|
docs-update:: docs-update-helper
|
|
|
|
docs-update:: docs-extra-helper
|
|
|
|
|
|
|
|
.PHONY: docs-index
|
|
|
|
.SILENT: docs-index
|
|
|
|
docs-index:: docs-index-helper
|
|
|
|
|
|
|
|
.PHONY: docs
|
|
|
|
.SILENT: docs
|
|
|
|
docs:: docs-update
|
|
|
|
docs:: docs-index
|
|
|
|
|
2021-04-26 12:03:20 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Run local compilation by source file
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
check_vm:
|
2022-09-26 04:56:54 +00:00
|
|
|
@vmexe=`echo $(EXE_FILES)|tr ' ' '\n'|sed '/vm2\//!d'`;\
|
2021-04-26 12:03:20 +00:00
|
|
|
nim=$(NIM_EXE); \
|
|
|
|
export NIMBLE_DIR=$(NIMBLE_DIR); \
|
|
|
|
$$nim --version | sed q; \
|
|
|
|
for path in `echo "$$vmexe"`; do ( \
|
|
|
|
dir=`dirname "$$path"`; \
|
|
|
|
src=`basename "$$path"`; \
|
|
|
|
cd "$$dir" ; \
|
|
|
|
(set -x;$$nim $(NIMCHK_FLAGS) "$$src.nim" $(MUFFLE)) || \
|
|
|
|
echo "*** FAIL $$path"; \
|
|
|
|
); done || true
|
|
|
|
|
2021-03-19 15:59:59 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Clean up etc.
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.PHONY: clobber distclean clean clean-exe clean-docs
|
|
|
|
|
2021-06-04 17:20:37 +00:00
|
|
|
.SILENT: clean-exe clean-test-exe
|
2021-03-19 15:59:59 +00:00
|
|
|
clean-exe:
|
|
|
|
for f in $(EXE_FILES); do \
|
2021-04-12 15:36:00 +00:00
|
|
|
if [ -f "$$f" ]; then (set -x; rm -f "$$f"); \
|
|
|
|
elif [ -f "$$f.out" ]; then (set -x; rm -f "$$f.out"); \
|
|
|
|
fi ; \
|
2021-03-19 15:59:59 +00:00
|
|
|
done
|
|
|
|
|
2021-06-04 17:20:37 +00:00
|
|
|
clean-test-exe:
|
|
|
|
for f in $(TXE_FILES); do \
|
|
|
|
if [ -f "$$f" ]; then (set -x; rm -f "$$f"); \
|
|
|
|
elif [ -f "$$f.out" ]; then (set -x; rm -f "$$f.out"); \
|
|
|
|
fi ; \
|
|
|
|
done
|
|
|
|
|
2021-03-19 15:59:59 +00:00
|
|
|
.SILENT: clean-docs
|
|
|
|
clean-docs:
|
|
|
|
for f in $(foreach f,$(EXE_FILES),docs/$f) \
|
|
|
|
$(foreach f,$(PNG_FILES),docs/ex/$f) \
|
|
|
|
$(foreach f,$(MD_FILES),docs/ex/$f) \
|
2021-03-22 16:06:28 +00:00
|
|
|
docs/theindex; \
|
2021-03-19 15:59:59 +00:00
|
|
|
do \
|
|
|
|
[ ! -f "$$f.html" ] || (set -x; rm -f "$$f.html"); \
|
|
|
|
[ ! -f "$$f.idx" ] || (set -x; rm -f "$$f.idx"); \
|
|
|
|
[ ! -f "$$f.png" ] || (set -x; rm -f "$$f.png"); \
|
|
|
|
done
|
|
|
|
for d in $(shell find docs -depth -type d -print $(MUFFLE)); do \
|
|
|
|
(set -x; rmdir "$$d" $(MUFFLE)) || true; \
|
|
|
|
done
|
|
|
|
|
2021-06-04 17:20:37 +00:00
|
|
|
.SILENT: clean-bakfiles clean-test-bakfiles
|
2021-03-19 15:59:59 +00:00
|
|
|
clean-bakfiles:
|
|
|
|
for f in $(shell find . -type f \
|
2021-03-30 15:26:35 +00:00
|
|
|
\( -name '*~' -o -name '*.bak' \) -print); do \
|
2021-03-19 15:59:59 +00:00
|
|
|
(set -x; rm -f "$$f"); \
|
|
|
|
done
|
|
|
|
|
2021-06-04 17:20:37 +00:00
|
|
|
clean-test-bakfiles:
|
|
|
|
for f in $(shell find . -type f \
|
|
|
|
\( -name '*~' -o -name '*.bak' \) -print); do \
|
|
|
|
(set -x; rm -f "$$f"); \
|
|
|
|
done
|
|
|
|
|
|
|
|
.SILENT: clean-nimcache clean-test-nimcache
|
2021-03-19 15:59:59 +00:00
|
|
|
clean-nimcache:
|
2021-03-22 17:36:17 +00:00
|
|
|
# |while.. is like "|xargs -rn1 rm -rf" but with nicer log message
|
|
|
|
find . -name 'nimcache' -type d -print 2>/dev/null | \
|
|
|
|
while read d; do (set -x; rm -rf "$$d"); done
|
2021-03-19 15:59:59 +00:00
|
|
|
|
2021-06-04 17:20:37 +00:00
|
|
|
clean-test-nimcache:
|
|
|
|
find ../tests -name 'nimcache' -type d -print 2>/dev/null | \
|
|
|
|
while read d; do (set -x; rm -rf "$$d"); done
|
|
|
|
|
|
|
|
clean:: clean-exe clean-test-exe
|
|
|
|
clean:: clean-bakfiles clean-test-bakfiles
|
|
|
|
clean:: clean-nimcache clean-test-nimcache
|
2021-03-19 15:59:59 +00:00
|
|
|
|
|
|
|
distclean:: clean
|
|
|
|
distclean:: clean-docs
|
|
|
|
|
|
|
|
clobber:: distclean
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|