1
0
Fork 0
forked from lthn/blockchain
blockchain/Makefile

162 lines
6.9 KiB
Makefile
Raw Normal View History

# Copyright (c) 2017-2025 Lethean https://lt.hn
2019-02-20 02:42:47 +00:00
# Copyright (c) 2014-2019 Zano Project
# Copyright (c) 2014 The Cryptonote developers
# Distributed under the MIT/X11 software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
2025-09-25 00:25:52 +01:00
# ------------------------------------------------------------
# Detect the number of logical CPU cores works on Linux,
# macOS, BSD, and Windows (both cmd.exe and PowerShell).
# ------------------------------------------------------------
# Default to “unknown” will be overwritten below.
CPU_CORES := 1
# -----------------------------------------------------------------
# Unixlike systems (Linux, macOS, *BSD, etc.)
# -----------------------------------------------------------------
UNAME_S := $(shell uname -s 2>/dev/null || echo Unknown)
ifeq ($(UNAME_S),Linux)
# Linux: try nproc first, fall back to /proc
CPU_CORES := $(shell nproc 2>/dev/null || \
grep -c ^processor /proc/cpuinfo 2>/dev/null || echo 1)
endif
ifeq ($(UNAME_S),Darwin)
# macOS: sysctl reports the number of logical CPUs
CPU_CORES := $(shell sysctl -n hw.logicalcpu 2>/dev/null || echo 1)
endif
ifeq ($(filter %BSD,$(UNAME_S)),%BSD)
# *BSD: also sysctl, but the key differs on some variants
CPU_CORES := $(shell sysctl -n hw.ncpu 2>/dev/null || echo 1)
endif
# -----------------------------------------------------------------
# Windows (detected by the builtin $(OS) variable set by GNU make)
# -----------------------------------------------------------------
ifeq ($(OS),Windows_NT)
# Prefer the environment variable that Windows sets for us.
# It works in both cmd.exe and PowerShell.
CPU_CORES := $(NUMBER_OF_PROCESSORS)
# If for some reason the env var is empty, fall back to PowerShell.
ifeq ($(CPU_CORES),)
CPU_CORES := $(shell powershell -NoProfile -Command ^ "[Environment]::ProcessorCount")
endif
endif
2025-09-25 15:38:18 +00:00
testnet-genesis-new:
$(eval command += $(cmake_release) $(testnet))
$(call CMAKE,$(dir_release),$(command) -DGENERATE_PREMINE_WALLET=1 -DPREMINE_WALLET_PASSWORD=12345678) && cmake --build ./src --target premine_wallet || true
$(eval command += $(cmake_release) $(testnet))
$(call CMAKE,$(dir_release),$(command) -DGENERATE_FRESH_GENESIS=1) && cmake --build ./src --target genesis_generator
$(eval command += $(cmake_release) $(testnet))
$(call CMAKE,$(dir_release),$(command)) && $(MAKE)
genesis-new:
$(eval command += $(cmake_release))
$(call CMAKE,$(dir_release),$(command) -DGENERATE_FRESH_GENESIS=1) && cmake --build ./src --target genesis_generator
$(eval command += $(cmake_release))
$(call CMAKE,$(dir_release),$(command)) && $(MAKE)
2025-09-25 00:25:52 +01:00
# -----------------------------------------------------------------
# Safety net ensure we always have a positive integer.
# -----------------------------------------------------------------
CPU_CORES := $(or $(CPU_CORES),1)
CPU_CORES := $(shell expr $(CPU_CORES) + 0 2>/dev/null || echo 1)
CONAN_CPU_COUNT=$(CPU_CORES)
2025-09-24 21:01:35 +01:00
2025-09-25 15:38:18 +00:00
2025-09-24 21:01:35 +01:00
PROFILES := $(patsubst cmake/profiles/%,%,$(wildcard cmake/profiles/*))
SORTED_PROFILES := $(sort $(PROFILES))
CONAN_CACHE := $(CURDIR)/build/sdk
DEFAULT_CONAN_PROFILE := $(CONAN_CACHE)/cmake/profiles/default
2018-12-27 18:50:45 +03:00
all: help
2018-12-27 18:50:45 +03:00
2025-09-24 21:01:35 +01:00
release: conan-profile-detect
@echo "Building profile: release"
CONAN_HOME=$(CONAN_CACHE) conan install . --output-folder=build/release --build=missing -s build_type=Release
cmake -S . -B build/release -DCMAKE_TOOLCHAIN_FILE=build/release/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
2025-09-25 00:25:52 +01:00
cmake --build build/release --config=Release --parallel=$(CPU_CORES)
2018-12-27 18:50:45 +03:00
2025-09-24 21:01:35 +01:00
debug: conan-profile-detect
@echo "Building profile: debug"
CONAN_HOME=$(CONAN_CACHE) conan install . --output-folder=build/debug --build=missing -s build_type=Debug
cmake -S . -B build/debug -DCMAKE_TOOLCHAIN_FILE=build/debug/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Debug
2025-09-25 00:25:52 +01:00
cmake --build build/debug --config=Debug --parallel=$(CPU_CORES)
static: static-release
2025-09-24 21:01:35 +01:00
static-release: conan-profile-detect
@echo "Building profile: release-static"
CONAN_HOME=$(CONAN_CACHE) conan install . --output-folder=build/release-static --build=missing
cmake -S . -B build/release-static -DCMAKE_TOOLCHAIN_FILE=build/release-static/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release -D STATIC=ON
2025-09-25 00:25:52 +01:00
cmake --build build/release-static --config=Release --parallel=$(CPU_CORES)
2025-09-24 21:01:35 +01:00
conan-profile-detect:
@if [ ! -f "$(DEFAULT_CONAN_PROFILE)" ]; then \
echo "Default conan profile not found. Detecting a new one..."; \
CONAN_HOME=$(CONAN_CACHE) conan profile detect --name=default --force; \
fi
# Rule for each profile
$(PROFILES): conan-profile-detect
@echo "Building profile: $@"
CONAN_HOME=$(CONAN_CACHE) conan install . --output-folder=build/$@ --profile=cmake/profiles/$@ --build=missing
cmake -S . -B build/$@ -DCMAKE_TOOLCHAIN_FILE=build/$@/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
2025-09-25 00:25:52 +01:00
cmake --build build/$@ --config=Release --parallel=$(CPU_CORES)
2025-09-24 21:01:35 +01:00
help:
@echo "Available targets:"
@printf " %-22s %s\n" "all:" "Build all profiles"
@printf " %-22s %s\n" "clean:" "Clean all build directories"
@printf " %-22s %s\n" "release:" "Build release"
@printf " %-22s %s\n" "static:" "Build static release"
@printf " %-22s %s\n" "debug:" "Build debug"
@$(foreach profile,$(SORTED_PROFILES),printf " %-22s %s\n" "make $(profile):" "Build the $(profile) profile";)
@printf " %-22s %s\n" "help:" "Show this help message"
#
# Tests
#
test: test-release
test-release:
2025-09-24 21:01:35 +01:00
@echo "Building profile: test-release"
CONAN_HOME=$(CONAN_CACHE) conan install . --output-folder=build/test-release --build=missing
cmake -S . -B build/test-release -DCMAKE_TOOLCHAIN_FILE=build/test-release/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release -D BUILD_TESTS=ON
2025-09-25 00:25:52 +01:00
cmake --build build/test-release --config=Release --parallel=$(CPU_CORES)
2025-09-24 21:01:35 +01:00
$(MAKE) test
test-debug:
2025-09-24 21:01:35 +01:00
@echo "Building profile: test-debug"
CONAN_HOME=$(CONAN_CACHE) conan install . --output-folder=build/test-debug --build=missing
cmake -S . -B build/test-debug -DCMAKE_TOOLCHAIN_FILE=build/test-debug/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Debug -D BUILD_TESTS=ON
2025-09-25 00:25:52 +01:00
cmake --build build/test-debug --config=Debug --parallel=$(CPU_CORES)
2025-09-24 21:01:35 +01:00
$(MAKE) test
2018-12-27 18:50:45 +03:00
configure:
@echo "Running Config: release"
CONAN_HOME=$(CONAN_CACHE) conan install . --output-folder=build/release --build=missing -s build_type=Release
cmake -S . -B build/release -DCMAKE_TOOLCHAIN_FILE=build/release/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
docs: configure
@echo "Building Documentation"
cmake --build build/release --target=docs --config=Release --parallel=$(CPU_CORES)
docs-dev: configure
@echo "Building Documentation"
cmake --build build/release --target=serve_docs --config=Release
2018-12-27 18:50:45 +03:00
clean:
rm -rf build
tags:
ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ src contrib tests/gtest
.PHONY: all release debug docs docs-dev configure static static-release test test-release test-debug clean tags conan-profile-detect $(PROFILES)