Files
agrarian/depends/Makefile
T

192 lines
6.3 KiB
Makefile

.DEFAULT_GOAL := all
# Copyright (c) 2026 Agrarian Developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://www.opensource.org/licenses/mit-license.php.
SHELL := /bin/bash
BASEDIR := $(CURDIR)
BUILD ?= $(shell ./config.guess)
HOST ?= $(BUILD)
build := $(BUILD)
host := $(HOST)
PATCHES_PATH ?= $(BASEDIR)/patches
SOURCES_PATH ?= $(BASEDIR)/sources
BASE_CACHE ?= $(BASEDIR)/built
workdir ?= $(BASEDIR)/work
base_build_dir ?= $(workdir)/build
base_staging_dir ?= $(workdir)/staging
base_download_dir ?= $(workdir)/download
HASH_LENGTH ?= 8
# Derive build_os for builder tooling (host_os comes from hosts/$(host).mk)
build_os :=
ifneq (,$(findstring linux,$(build)))
build_os := linux
else ifneq (,$(findstring darwin,$(build)))
build_os := darwin
else
build_os := linux
endif
# Host-triplet file (must exist)
HOST_MK := hosts/$(host).mk
ifeq ($(wildcard $(HOST_MK)),)
$(error Missing $(HOST_MK). Create it under depends/hosts/.)
endif
# Common recipe dependencies for build-id hashing
meta_depends = \
Makefile \
funcs.mk \
builders/default.mk \
builders/$(build_os).mk \
hosts/default.mk \
$(HOST_MK) \
packages/packages.mk
include $(HOST_MK)
include builders/default.mk
include builders/$(build_os).mk
include packages/packages.mk
include funcs.mk
# --------------------------------------------------------------------
# IMPORTANT:
# Do NOT depend on $($(p)_cached_checksum) here — those vars are created
# later (inside funcs.mk macros), so they'd expand to empty at parse-time.
# Instead depend on the package phony targets (boost, openssl, etc).
# --------------------------------------------------------------------
.PHONY: all
all: install
# Optional convenience targets (only build what you need)
.PHONY: base wallet zmq upnp qt
base: $(packages)
wallet: $(wallet_packages)
zmq: $(zmq_packages)
upnp: $(upnp_packages)
qt: $(qt_packages) $(qt_$(host_os)_packages)
# Download-only: uses stage targets generated by funcs.mk
.PHONY: download
download: $(foreach p,$(all_packages),$($(p)_fetched))
# --------------------------------------------------------------------
# Beginner-friendly: populate depends/$(HOST)/ prefix from built cache
# and generate share/config.site for top-level ./configure.
# --------------------------------------------------------------------
.PHONY: install install-clean reinstall install-prefix
install: install-prefix
install-prefix: $(packages)
@echo "== Installing depends into: $(host_prefix)"
@rm -rf "$(host_prefix)"
@mkdir -p "$(host_prefix)"
@set -euo pipefail; \
for p in $(packages); do \
f="$(BASE_CACHE)/$(HOST)/$$p/"*.tar.gz; \
if ! ls $$f >/dev/null 2>&1; then \
echo "ERROR: missing built artifact for $$p (expected: $$f)"; \
exit 1; \
fi; \
echo " - $$p: $$f"; \
tar -xzf $$f -C "$(host_prefix)"; \
done
@echo "== Writing config.site: $(host_prefix)/share/config.site"
@mkdir -p "$(host_prefix)/share"
@{ \
echo "# Autoconf site defaults for Agrarian depends (generated)"; \
echo "depends_prefix='$(host_prefix)'"; \
echo "cross_compiling=maybe"; \
echo "host_alias='$(HOST)'"; \
echo "ac_tool_prefix='$(HOST)-'"; \
echo "with_boost='$(host_prefix)'"; \
echo "with_qt_plugindir='$(host_prefix)/plugins'"; \
echo "with_qt_translationdir='$(host_prefix)/translations'"; \
echo "with_qt_bindir='$(host_prefix)/native/bin'"; \
echo "with_protoc_bindir='$(host_prefix)/native/bin'"; \
echo "CPPFLAGS='-I$(host_prefix)/include'"; \
echo "LDFLAGS='-L$(host_prefix)/lib'"; \
echo "BOOST_CPPFLAGS='-I$(host_prefix)/include'"; \
echo "BOOST_LDFLAGS='-L$(host_prefix)/lib'"; \
echo "PATH=\"$(host_prefix)/native/bin:\$$PATH\""; \
echo "PKG_CONFIG='`which pkg-config` --static'"; \
echo "PKG_CONFIG_LIBDIR='$(host_prefix)/lib/pkgconfig:$(host_prefix)/share/pkgconfig'"; \
echo "PKG_CONFIG_PATH=\"$$PKG_CONFIG_LIBDIR\""; \
echo "export PKG_CONFIG_LIBDIR"; \
echo "export PKG_CONFIG_PATH"; \
echo "export PKG_CONFIG"; \
echo "BDB_CFLAGS='-I$(host_prefix)/include'"; \
echo "BDB_LIBS='-L$(host_prefix)/lib -ldb_cxx-4.8 -ldb-4.8'"; \
} > "$(host_prefix)/share/config.site"
@# Ensure boost headers are available under include/boost for configure probes.
@set -euo pipefail; \
if [[ ! -e "$(host_prefix)/include/boost" ]]; then \
boost_inc="$$(ls -d "$(host_prefix)"/include/boost-* 2>/dev/null | sort -V | tail -n 1)"; \
if [[ -n "$$boost_inc" && -d "$$boost_inc/boost" ]]; then \
ln -sfn "$$(basename "$$boost_inc")/boost" "$(host_prefix)/include/boost"; \
fi; \
fi
@# If Boost emits versioned/-mt libs, create non-mt and unversioned symlinks.
@set -euo pipefail; \
shopt -s nullglob; \
for f in "$(host_prefix)"/lib/libboost_*-mt*; do \
if [[ -f "$$f" || -L "$$f" ]]; then \
base="$${f/-mt/}"; \
if [[ "$$base" != "$$f" ]]; then \
ln -sf "$$(basename "$$f")" "$$base"; \
fi; \
fi; \
done
@set -euo pipefail; \
shopt -s nullglob; \
for f in "$(host_prefix)"/lib/libboost_*.a; do \
name="$$(basename "$$f")"; \
unversioned="$${name%%-gcc*}"; \
if [[ "$$unversioned" != "$$name" ]]; then \
if [[ ! -e "$(host_prefix)/lib/$$unversioned" ]]; then \
ln -sf "$$name" "$(host_prefix)/lib/$$unversioned"; \
fi; \
fi; \
done
@if [[ "$(NO_QT)" = "0" ]] && [[ "$(host_os)" = "linux" ]]; then \
for pc in Qt5Core Qt5Gui Qt5Network Qt5Widgets; do \
if [[ ! -f "$(host_prefix)/lib/pkgconfig/$${pc}.pc" ]] && [[ ! -f "$(host_prefix)/share/pkgconfig/$${pc}.pc" ]]; then \
echo "ERROR: missing Qt pkg-config file for $${pc} under $(host_prefix)/(lib|share)/pkgconfig"; \
echo "Fix: make -C $(BASEDIR) HOST=$(HOST) USE_WALLET=$(USE_WALLET)"; \
exit 1; \
fi; \
done; \
fi
@echo "== Done."
install-clean:
@rm -rf "$(host_prefix)"
reinstall: install-clean install
# --------------------------------------------------------------------
# Cleaning
# - clean: removes working dirs only (keeps built cache + sources)
# - clean-cache: removes built cache too
# - distclean: removes everything generated by depends
# --------------------------------------------------------------------
.PHONY: clean clean-cache distclean
clean:
@rm -rf "$(workdir)"
clean-cache: clean
@rm -rf "$(BASE_CACHE)"
distclean: clean-cache
@rm -rf "$(SOURCES_PATH)" "$(BASEDIR)/SDKs"