This commit is contained in:
darshankabariya 2026-01-07 16:37:48 +05:30
parent 7e6ac9386c
commit 1a10e9829d
No known key found for this signature in database
GPG Key ID: 9A92CCD9899F0D22

View File

@ -11,16 +11,19 @@ BUILD_MSG := "\x1B[92mBuilding:\x1B[39m"
INFO_MSG := "\x1B[94mInfo:\x1B[39m"
WARN_MSG := "\x1B[93mWarning:\x1B[39m"
# Nim binary detection
NIM_BINARY := $(shell which nim 2>/dev/null)
ifeq ($(NIM_BINARY),)
$(error Nim compiler not found. Please install Nim >= 2.2.4)
endif
# Nimble binary detection
# Nimble binary detection (required for all targets)
NIMBLE_BINARY := $(shell which nimble 2>/dev/null)
ifeq ($(NIMBLE_BINARY),)
$(error Nimble not found. Please install Nimble)
$(error Nimble not found. Please install Nimble first)
endif
# Nim binary detection (skip check for 'update' and 'clean' targets which don't need Nim)
NIM_BINARY := $(shell which nim 2>/dev/null)
SKIP_NIM_CHECK_TARGETS := update clean
ifeq ($(filter $(MAKECMDGOALS),$(SKIP_NIM_CHECK_TARGETS)),)
ifeq ($(NIM_BINARY),)
$(error Nim compiler not found. Run 'make update' to install Nim from nimble.lock)
endif
endif
# Environment script (simplified - just use current env)
@ -325,21 +328,19 @@ networkmonitor: | build deps librln
############
.PHONY: build-nph install-nph clean-nph print-nph-path
# Default location for nph binary shall be next to nim binary to make it available on the path.
NPH:=$(shell dirname $(NIM_BINARY))/nph
# nph binary is placed next to nim binary so it's on PATH
# All nph targets use shell evaluation to find nim dynamically (after nimble setup installs it)
# nph is installed via Nimble, find it in nimble bin directory
NIMBLE_BIN_DIR := $(shell nimble path 2>/dev/null | head -1 | xargs dirname 2>/dev/null)/../bin
NPH_NIMBLE := $(NIMBLE_BIN_DIR)/nph
build-nph: | build deps
ifeq ("$(wildcard $(NPH))","")
@echo -e $(INFO_MSG) "Building nph from locked dependencies..."
cd $(shell nimble path nph) && nim c -d:release -o:$(NPH) src/nph.nim
@echo "nph utility is available at $(NPH)"
else
@echo "nph utility already exists at $(NPH)"
endif
build-nph:
@NPH_BIN="$$(dirname $$(which nim))/nph"; \
if [ ! -f "$$NPH_BIN" ]; then \
echo -e $(INFO_MSG) "Building nph from locked dependencies..."; \
NPH_SRC="$$(nimble path nph)"; \
cd "$$NPH_SRC" && nim c -d:release -o:"$$NPH_BIN" src/nph.nim; \
echo "nph utility is available at $$NPH_BIN"; \
else \
echo "nph utility already exists at $$NPH_BIN"; \
fi
GIT_PRE_COMMIT_HOOK := .git/hooks/pre-commit
@ -352,15 +353,17 @@ else
endif
nph/%: | build-nph
@NPH_BIN="$$(dirname $$(which nim))/nph"; \
echo -e $(FORMAT_MSG) "nph/$*" && \
$(NPH) $*
"$$NPH_BIN" $*
clean-nph:
rm -f $(NPH)
@NPH_BIN="$$(dirname $$(which nim 2>/dev/null || echo /tmp))/nph"; \
rm -f "$$NPH_BIN"
# To avoid hardcoding nph binary location in several places
print-nph-path:
echo "$(NPH)"
@echo "$$(dirname $$(which nim))/nph"
clean: | clean-nph