mirror of
https://github.com/logos-blockchain/logos-blockchain-circuits.git
synced 2026-05-22 09:19:25 +00:00
87 lines
2.9 KiB
Makefile
87 lines
2.9 KiB
Makefile
.PHONY: linux macos windows linux-lib macos-lib windows-lib build clean
|
|
|
|
# ---- Arguments ----
|
|
ifndef PROJECT
|
|
$(error PROJECT is not set. Usage: make PROJECT=<name>. E.g.: make PROJECT=pol linux)
|
|
endif
|
|
|
|
# ---- Common ----
|
|
CXX := g++
|
|
CXXFLAGS_COMMON := -std=c++11 -O3 -I. -Wno-address-of-packed-member -Dmain=circom_main
|
|
COMMON_SRCS := main.cpp calcwit.cpp fr.cpp $(PROJECT).cpp
|
|
COMMON_OBJS := $(COMMON_SRCS:.cpp=.o)
|
|
LIB_ONLY_SRCS := $(PROJECT)/ffi.cpp circom_adapter.cpp
|
|
LIB_ONLY_OBJS := $(LIB_ONLY_SRCS:.cpp=.o)
|
|
LIB_SRCS := $(COMMON_SRCS) $(LIB_ONLY_SRCS)
|
|
LIB_OBJS := $(COMMON_OBJS) $(LIB_ONLY_OBJS)
|
|
DEPS_HPP := circom.hpp calcwit.hpp fr.hpp types.hpp $(PROJECT)/ffi.hpp
|
|
BIN := $(PROJECT)
|
|
ifeq ($(OS),windows)
|
|
LIB_EXT := .lib
|
|
LIB_PREFIX :=
|
|
else
|
|
LIB_EXT := .a
|
|
LIB_PREFIX := lib
|
|
endif
|
|
LIB := $(LIB_PREFIX)$(PROJECT)$(LIB_EXT)
|
|
|
|
# ---- Linux (x86_64 and aarch64) ----
|
|
linux: CXXFLAGS=$(CXXFLAGS_COMMON)
|
|
linux: LDFLAGS=-static
|
|
linux: LDLIBS=-lgmp
|
|
linux: $(BIN)
|
|
|
|
linux-lib: CXXFLAGS=$(CXXFLAGS_COMMON) -fPIC
|
|
linux-lib: $(LIB)
|
|
|
|
# ---- macOS ----
|
|
macos: CXXFLAGS=$(CXXFLAGS_COMMON) -I/opt/homebrew/include -include gmp_patch.hpp
|
|
macos: LDFLAGS=-Wl,-search_paths_first -Wl,-dead_strip
|
|
macos: LDLIBS=/opt/homebrew/lib/libgmp.a
|
|
macos: $(BIN)
|
|
|
|
macos-lib: CXXFLAGS=$(CXXFLAGS_COMMON) -fPIC -I/opt/homebrew/include -include gmp_patch.hpp
|
|
macos-lib: $(LIB)
|
|
|
|
# ---- Windows (MinGW) ----
|
|
windows: CXXFLAGS=$(CXXFLAGS_COMMON) -I/include -Duint="unsigned int"
|
|
windows: LDFLAGS=-static
|
|
windows: LDLIBS=-L/lib -lgmp -lmman
|
|
windows: $(BIN)
|
|
|
|
windows-lib: CXXFLAGS=$(CXXFLAGS_COMMON) -fPIC -I/include -Duint="unsigned int"
|
|
windows-lib: $(LIB)
|
|
|
|
# Localizes all circuit-specific code to prevent conflicts when multiple circuit
|
|
# libraries are linked into the same binary. See CONTRIBUTING.md § "Symbol Isolation".
|
|
# On Linux/ELF: llvm-objcopy is required — it clears GRP_COMDAT when localizing
|
|
# COMDAT signature symbols, preventing "relocation refers to symbol in discarded
|
|
# section" errors that GNU objcopy causes. On Windows/COFF: GNU objcopy suffices
|
|
# because COFF COMDAT is per-section (not group-based) and is already deduplicated
|
|
# automatically by the linker — the ELF GRP_COMDAT problem does not apply.
|
|
PUBLIC_SYMS := $(PROJECT)_generate_witness $(PROJECT)_generate_witness_from_files
|
|
LOCAL_OBJ := $(PROJECT)_local.o
|
|
OBJCOPY := $(if $(filter windows,$(OS)),objcopy,llvm-objcopy)
|
|
|
|
UNAME := $(shell uname -s)
|
|
|
|
# ---- Rules ----
|
|
$(BIN): $(COMMON_OBJS)
|
|
$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@
|
|
|
|
$(LIB): $(LIB_OBJS)
|
|
ifeq ($(UNAME),Darwin)
|
|
ar rcs $@ $^ # macOS: two-level namespace, conflicts don't arise
|
|
else
|
|
ld -r -o $(LOCAL_OBJ) $(filter-out fr.o,$^)
|
|
$(OBJCOPY) $(foreach s,$(PUBLIC_SYMS),--keep-global-symbol=$(s)) $(LOCAL_OBJ)
|
|
ar rcs $@ fr.o $(LOCAL_OBJ)
|
|
rm $(LOCAL_OBJ)
|
|
endif
|
|
|
|
%.o: %.cpp $(DEPS_HPP)
|
|
$(CXX) $(CXXFLAGS) -c $< -o $@
|
|
|
|
clean:
|
|
rm -f $(COMMON_OBJS) $(LIB_ONLY_OBJS) $(BIN) $(LIB) $(LOCAL_OBJ)
|