|
| 1 | +SHELL := /bin/sh |
| 2 | + |
| 3 | +BREW_PREFIX := $(shell brew --prefix 2>/dev/null) |
| 4 | +PREFIX ?= $(if $(BREW_PREFIX),$(BREW_PREFIX),/usr/local) |
| 5 | +LIBDIR ?= $(PREFIX)/lib |
| 6 | +INCLUDEDIR ?= $(PREFIX)/include |
| 7 | +PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig |
| 8 | + |
| 9 | +CABAL ?= cabal |
| 10 | +INSTALL ?= install |
| 11 | +DEPS_DIR ?= .build/deps |
| 12 | + |
| 13 | +SECP256K1_DIR := $(DEPS_DIR)/secp256k1 |
| 14 | +SECP256K1_REV := ac83be33d0956faf6b7f61a60ab524ef7d6a473a |
| 15 | + |
| 16 | +BLST_DIR := $(DEPS_DIR)/blst |
| 17 | +BLST_VERSION := v0.3.10 |
| 18 | +BLST_PC := $(BLST_DIR)/libblst.pc |
| 19 | + |
| 20 | +.PHONY: all build run help blst secp256k1 pre |
| 21 | + |
| 22 | +all: help |
| 23 | + |
| 24 | +help: |
| 25 | + @printf "\033[1;37mMakefile Targets\033[00m\n" |
| 26 | + @grep -E '^[a-z]+[^:]+:.*## &cmd ' Makefile | sort | while read -r l; do printf " \033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 3- -d'#' | sed 's/^ \&cmd//')\n"; done |
| 27 | + @echo "" |
| 28 | + |
| 29 | +pre: ## &cmd check required tools, libraries, and local build configuration |
| 30 | + @printf '%s\n' 'Checking build prerequisites' |
| 31 | + @set -eu; \ |
| 32 | + os_name="$$(uname -s)"; \ |
| 33 | + case "$$os_name" in \ |
| 34 | + Darwin) install_cmd='brew install' ;; \ |
| 35 | + Linux) install_cmd='sudo apt-get install' ;; \ |
| 36 | + *) install_cmd='install manually' ;; \ |
| 37 | + esac; \ |
| 38 | + failed=0; \ |
| 39 | + check_cmd() { \ |
| 40 | + label="$$1"; \ |
| 41 | + cmd="$$2"; \ |
| 42 | + hint="$$3"; \ |
| 43 | + if command -v "$$cmd" >/dev/null 2>&1; then \ |
| 44 | + printf '\033[1;32m%s\033[00m %s\n' ' ✓' "$$label"; \ |
| 45 | + else \ |
| 46 | + printf '\033[1;31m%s %s\033[00m → \033[1;37m%s %s\033[00m\n' ' ✗' "$$label" "$$install_cmd" "$$hint"; \ |
| 47 | + failed=1; \ |
| 48 | + fi; \ |
| 49 | + }; \ |
| 50 | + check_pkg() { \ |
| 51 | + label="$$1"; \ |
| 52 | + hint="$$2"; \ |
| 53 | + shift; \ |
| 54 | + shift; \ |
| 55 | + found=0; \ |
| 56 | + for pkg_name in "$$@"; do \ |
| 57 | + if pkg-config --exists "$$pkg_name"; then \ |
| 58 | + found=1; \ |
| 59 | + break; \ |
| 60 | + fi; \ |
| 61 | + done; \ |
| 62 | + if [ "$$found" -eq 1 ]; then \ |
| 63 | + printf '\033[1;32m%s\033[00m %s\n' ' ✓' "$$label"; \ |
| 64 | + else \ |
| 65 | + printf '\033[1;31m%s %s\033[00m → \033[1;37m%s %s\033[00m\n' ' ✗' "$$label" "$$install_cmd" "$$hint"; \ |
| 66 | + failed=1; \ |
| 67 | + fi; \ |
| 68 | + }; \ |
| 69 | + check_path() { \ |
| 70 | + label="$$1"; \ |
| 71 | + path="$$2"; \ |
| 72 | + hint="$$3"; \ |
| 73 | + if [ -e "$$path" ]; then \ |
| 74 | + printf '%s %s\n' ' ✓' "$$label"; \ |
| 75 | + else \ |
| 76 | + printf '%s %s (%s)\n' ' ✗' "$$label" "$$hint"; \ |
| 77 | + failed=1; \ |
| 78 | + fi; \ |
| 79 | + }; \ |
| 80 | + check_cmd 'git' git git; \ |
| 81 | + check_cmd 'cabal' cabal 'ghcup && ghcup tui'; \ |
| 82 | + check_cmd 'ghc' ghc 'ghcup && ghcup tui'; \ |
| 83 | + check_cmd 'pkg-config' pkg-config pkg-config; \ |
| 84 | + check_cmd 'autoconf' autoconf autoconf; \ |
| 85 | + check_cmd 'libtool' libtool libtool; \ |
| 86 | + if [ "$$os_name" = 'Darwin' ]; then \ |
| 87 | + check_cmd 'install_name_tool' install_name_tool CommandLineTools; \ |
| 88 | + fi; \ |
| 89 | + if command -v pkg-config >/dev/null 2>&1; then \ |
| 90 | + check_pkg 'libffi' libffi libffi; \ |
| 91 | + check_pkg 'gmp' gmp gmp; \ |
| 92 | + check_pkg 'pcre' pcre libpcre pcre; \ |
| 93 | + check_pkg 'libsodium' libsodium libsodium; \ |
| 94 | + check_pkg 'zlib' zlib zlib; \ |
| 95 | + check_pkg 'openssl' openssl openssl; \ |
| 96 | + check_pkg 'secp256k1' libsecp256k1 libsecp256k1; \ |
| 97 | + check_pkg 'blst' libblst libblst; \ |
| 98 | + fi; \ |
| 99 | + check_cmd 'llvm-config' llvm-config llvm; \ |
| 100 | + if [ "$$os_name" = 'Linux' ]; then \ |
| 101 | + check_path 'libnuma headers' '/usr/include/numa.h' 'sudo apt-get install libnuma-dev'; \ |
| 102 | + check_path 'libsystemd headers' '/usr/include/systemd/sd-daemon.h' 'sudo apt-get install libsystemd-dev'; \ |
| 103 | + fi; \ |
| 104 | + |
| 105 | +build: ## &cmd compile the main binary |
| 106 | + $(CABAL) build exe:haskell-node-extractor |
| 107 | + |
| 108 | +secp256k1: ## &cmd install secp256k1 as required for Cardano |
| 109 | + mkdir -p "$(DEPS_DIR)" |
| 110 | + if [ ! -d "$(SECP256K1_DIR)" ]; then git clone https://github.com/bitcoin-core/secp256k1.git "$(SECP256K1_DIR)"; fi |
| 111 | + cd "$(SECP256K1_DIR)" && git fetch --all --tags |
| 112 | + cd "$(SECP256K1_DIR)" && git checkout "$(SECP256K1_REV)" |
| 113 | + cd "$(SECP256K1_DIR)" && ./autogen.sh |
| 114 | + cd "$(SECP256K1_DIR)" && ./configure --prefix="$(PREFIX)" --libdir="$(LIBDIR)" --enable-module-schnorrsig --enable-experimental |
| 115 | + $(MAKE) -C "$(SECP256K1_DIR)" |
| 116 | + $(MAKE) -C "$(SECP256K1_DIR)" check |
| 117 | + $(MAKE) -C "$(SECP256K1_DIR)" install |
| 118 | + if [ "$$(uname -s)" = "Darwin" ] && [ -f "$(LIBDIR)/libsecp256k1.0.dylib" ]; then install_name_tool -id "$(LIBDIR)/libsecp256k1.0.dylib" "$(LIBDIR)/libsecp256k1.0.dylib"; fi |
| 119 | + |
| 120 | +blst: ## &cmd install blst as required for Cardano |
| 121 | + mkdir -p "$(DEPS_DIR)" |
| 122 | + if [ ! -d "$(BLST_DIR)" ]; then git clone https://github.com/supranational/blst "$(BLST_DIR)"; fi |
| 123 | + cd "$(BLST_DIR)" && git fetch --all --tags |
| 124 | + cd "$(BLST_DIR)" && git checkout "$(BLST_VERSION)" |
| 125 | + cd "$(BLST_DIR)" && ./build.sh |
| 126 | + mkdir -p "$(PKGCONFIGDIR)" "$(INCLUDEDIR)" "$(LIBDIR)" |
| 127 | + printf '%s\n' \ |
| 128 | + 'prefix=$(PREFIX)' \ |
| 129 | + 'exec_prefix=$${prefix}' \ |
| 130 | + 'libdir=$${exec_prefix}/lib' \ |
| 131 | + 'includedir=$${prefix}/include' \ |
| 132 | + 'Name: libblst' \ |
| 133 | + 'Description: Multilingual BLS12-381 signature library' \ |
| 134 | + 'URL: https://github.com/supranational/blst' \ |
| 135 | + 'Version: 0.3.10' \ |
| 136 | + 'Cflags: -I$${includedir}' \ |
| 137 | + 'Libs: -L$${libdir} -lblst' \ |
| 138 | + > "$(BLST_PC)" |
| 139 | + $(INSTALL) -m 0644 "$(BLST_PC)" "$(PKGCONFIGDIR)/libblst.pc" |
| 140 | + $(INSTALL) -m 0644 "$(BLST_DIR)/bindings/blst_aux.h" "$(INCLUDEDIR)/blst_aux.h" |
| 141 | + $(INSTALL) -m 0644 "$(BLST_DIR)/bindings/blst.h" "$(INCLUDEDIR)/blst.h" |
| 142 | + $(INSTALL) -m 0644 "$(BLST_DIR)/bindings/blst.hpp" "$(INCLUDEDIR)/blst.hpp" |
| 143 | + $(INSTALL) -m 0644 "$(BLST_DIR)/libblst.a" "$(LIBDIR)/libblst.a" |
0 commit comments