mirror of https://github.com/zcash/libsnark.git
Makefile and prepare-depends improvements
- Refactor CXXFLAGS so that feature flags and optimization flags can be easily overriden from command line - Add NO_SUPERCOP=1 option - Avoid need to manually create ./depinst directory when ./prepare-depends is not needed (i.e., when BN128 and SUPERCOP are not used) - Fix the flags for static build - Build executables that need GTest even if we used an existing GTest rather than compiling it - Minor cleanups and comments
This commit is contained in:
parent
f403f084dc
commit
998a23735a
82
Makefile
82
Makefile
|
@ -6,24 +6,34 @@
|
||||||
#* @copyright MIT license (see LICENSE file)
|
#* @copyright MIT license (see LICENSE file)
|
||||||
#*******************************************************************************/
|
#*******************************************************************************/
|
||||||
|
|
||||||
CXXFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -Wno-comment -march=native -mtune=native -std=c++11 -Wfatal-errors
|
# To override these, use "make OPTFLAGS=..." etc.
|
||||||
|
CURVE = BN128
|
||||||
|
OPTFLAGS = -O2 -march=native -mtune=native
|
||||||
|
FEATUREFLAGS = -DUSE_ASM -DMONTGOMERY_OUTPUT
|
||||||
|
|
||||||
|
# Initialize this using "CXXFLAGS=... make". The makefile appends to that.
|
||||||
|
CXXFLAGS += -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-comment -Wfatal-errors $(OPTFLAGS) $(FEATUREFLAGS) -DCURVE_$(CURVE)
|
||||||
|
|
||||||
DEPSRC=depsrc
|
DEPSRC=depsrc
|
||||||
DEPINST=depinst
|
DEPINST=depinst
|
||||||
|
|
||||||
LDFLAGS += -L $(DEPINST)/lib -Wl,-rpath $(DEPINST)/lib
|
LDFLAGS += -L $(DEPINST)/lib -Wl,-rpath $(DEPINST)/lib
|
||||||
LDLIBS += -lgmpxx -lgmp -lboost_program_options -lsupercop -lcrypto
|
LDLIBS += -lgmpxx -lgmp -lboost_program_options
|
||||||
CXXFLAGS += -I $(DEPINST)/include -I src -DUSE_ASM -DMONTGOMERY_OUTPUT
|
LDLIBS += -lcrypto -ldl -lz # OpenSSL and its dependencies (needed explicitly for static builds)
|
||||||
DEFAULT_CURVE=BN128
|
CXXFLAGS += -I $(DEPINST)/include -I src
|
||||||
|
|
||||||
ifneq ($(NO_GTEST),1)
|
ifneq ($(NO_GTEST),1)
|
||||||
GTESTDIR=/usr/src/gtest
|
GTESTDIR=/usr/src/gtest
|
||||||
# Recompile GTest, if we can (e.g., Ubuntu). Otherwise use precompiled one (e.g., Fedora).
|
# Compile GTest from sourcecode if we can (e.g., Ubuntu). Otherwise use precompiled one (e.g., Fedora).
|
||||||
# See https://code.google.com/p/googletest/wiki/FAQ#Why_is_it_not_recommended_to_install_a_pre-compiled_copy_of_Goog .
|
# See https://code.google.com/p/googletest/wiki/FAQ#Why_is_it_not_recommended_to_install_a_pre-compiled_copy_of_Goog .
|
||||||
COMPILE_GTEST:=$(shell test -d $(GTESTDIR) && echo 1) # Found GTest sourcecode?
|
COMPILE_GTEST:=$(shell test -d $(GTESTDIR) && echo -n 1)
|
||||||
GTEST_LDLIBS += -lgtest -lpthread
|
GTEST_LDLIBS += -lgtest -lpthread
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifneq ($(NO_SUPERCOP),1)
|
||||||
|
SUPERCOP_LDLIBS += -lsupercop
|
||||||
|
endif
|
||||||
|
|
||||||
SRCS = \
|
SRCS = \
|
||||||
src/algebra/curves/alt_bn128/alt_bn128_g1.cpp \
|
src/algebra/curves/alt_bn128/alt_bn128_g1.cpp \
|
||||||
src/algebra/curves/alt_bn128/alt_bn128_g2.cpp \
|
src/algebra/curves/alt_bn128/alt_bn128_g2.cpp \
|
||||||
|
@ -74,11 +84,6 @@ SRCS = \
|
||||||
src/relations/ram_computations/rams/fooram/fooram_aux.cpp \
|
src/relations/ram_computations/rams/fooram/fooram_aux.cpp \
|
||||||
src/relations/ram_computations/rams/tinyram/tinyram_aux.cpp
|
src/relations/ram_computations/rams/tinyram/tinyram_aux.cpp
|
||||||
|
|
||||||
ifeq ($(CURVE),)
|
|
||||||
CURVE = $(DEFAULT_CURVE)
|
|
||||||
endif
|
|
||||||
CXXFLAGS += -DCURVE_$(CURVE)
|
|
||||||
|
|
||||||
ifeq ($(CURVE),BN128)
|
ifeq ($(CURVE),BN128)
|
||||||
SRCS += \
|
SRCS += \
|
||||||
src/algebra/curves/bn128/bn128_g1.cpp \
|
src/algebra/curves/bn128/bn128_g1.cpp \
|
||||||
|
@ -127,8 +132,7 @@ EXECUTABLES = \
|
||||||
src/zk_proof_systems/ppzksnark/uscs_ppzksnark/profiling/profile_uscs_ppzksnark \
|
src/zk_proof_systems/ppzksnark/uscs_ppzksnark/profiling/profile_uscs_ppzksnark \
|
||||||
src/zk_proof_systems/ppzksnark/uscs_ppzksnark/tests/test_uscs_ppzksnark \
|
src/zk_proof_systems/ppzksnark/uscs_ppzksnark/tests/test_uscs_ppzksnark \
|
||||||
src/zk_proof_systems/zksnark/ram_zksnark/profiling/profile_ram_zksnark \
|
src/zk_proof_systems/zksnark/ram_zksnark/profiling/profile_ram_zksnark \
|
||||||
src/zk_proof_systems/zksnark/ram_zksnark/tests/test_ram_zksnark \
|
src/zk_proof_systems/zksnark/ram_zksnark/tests/test_ram_zksnark
|
||||||
src/zk_proof_systems/ppzkadsnark/r1cs_ppzkadsnark/examples/demo_r1cs_ppzkadsnark
|
|
||||||
|
|
||||||
|
|
||||||
ifneq ($(NO_GTEST),1)
|
ifneq ($(NO_GTEST),1)
|
||||||
|
@ -137,6 +141,11 @@ ifneq ($(NO_GTEST),1)
|
||||||
src/gadgetlib2/tests/gadgetlib2_test
|
src/gadgetlib2/tests/gadgetlib2_test
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifneq ($(NO_SUPERCOP),1)
|
||||||
|
EXECUTABLES_WITH_SUPERCOP = \
|
||||||
|
src/zk_proof_systems/ppzkadsnark/r1cs_ppzkadsnark/examples/demo_r1cs_ppzkadsnark
|
||||||
|
endif
|
||||||
|
|
||||||
DOCS= README.html
|
DOCS= README.html
|
||||||
|
|
||||||
# For documentation of the following options, see README.md .
|
# For documentation of the following options, see README.md .
|
||||||
|
@ -151,16 +160,17 @@ ifeq ($(LOWMEM),1)
|
||||||
CXXFLAGS += -DLOWMEM
|
CXXFLAGS += -DLOWMEM
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(PROFILE_OP_COUNTS),1)
|
||||||
|
STATIC = 1
|
||||||
|
CXXFLAGS += -DPROFILE_OP_COUNTS
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(STATIC),1)
|
ifeq ($(STATIC),1)
|
||||||
CXXFLAGS += -static -DSTATIC
|
CXXFLAGS += -static -DSTATIC
|
||||||
else
|
else
|
||||||
CXXFLAGS += -fPIC
|
CXXFLAGS += -fPIC
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(PROFILE_OP_COUNTS),1)
|
|
||||||
CXXFLAGS += -static -DPROFILE_OP_COUNTS
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(MULTICORE),1)
|
ifeq ($(MULTICORE),1)
|
||||||
CXXFLAGS += -DMULTICORE -fopenmp
|
CXXFLAGS += -DMULTICORE -fopenmp
|
||||||
endif
|
endif
|
||||||
|
@ -175,29 +185,32 @@ ifeq ($(DEBUG),1)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(PERFORMANCE),1)
|
ifeq ($(PERFORMANCE),1)
|
||||||
CXXFLAGS += -flto -fuse-linker-plugin
|
# OPTFLAGS could be changed here, but the default set above is already OK
|
||||||
CXXFLAGS += -march=native -mtune=native
|
|
||||||
CXXFLAGS += -DNDEBUG
|
CXXFLAGS += -DNDEBUG
|
||||||
|
CXXFLAGS += -flto -fuse-linker-plugin # enable link-time optimization
|
||||||
LDFLAGS += -flto
|
LDFLAGS += -flto
|
||||||
endif
|
endif
|
||||||
|
|
||||||
OBJS=$(patsubst %.cpp,%.o,$(SRCS))
|
OBJS=$(patsubst %.cpp,%.o,$(SRCS))
|
||||||
|
|
||||||
ifeq ($(strip $(COMPILE_GTEST)),1)
|
all: $(if $(NO_GTEST),,$(if $(COMPILE_GTEST),libgtest.a) $(EXECUTABLES_WITH_GTEST)) \
|
||||||
all: libgtest.a $(EXECUTABLES) $(EXECUTABLES_WITH_GTEST) doc
|
$(EXECUTABLES) \
|
||||||
else
|
$(if $(NO_SUPERCOP),,$(EXECUTABLES_WITH_SUPERCOP)) \
|
||||||
all: $(EXECUTABLES) doc
|
$(if $(NO_DOCS),,doc)
|
||||||
endif
|
|
||||||
|
|
||||||
doc: $(DOCS)
|
doc: $(DOCS)
|
||||||
|
|
||||||
|
deplib:
|
||||||
|
# Placeholder. Some make settings (including the default) require actually running ./prepare-depends
|
||||||
|
mkdir -p $(DEPINST)/lib
|
||||||
|
|
||||||
# In order to detect changes to #include dependencies. -MMD below generates a .d file for .cpp file. Include the .d file.
|
# In order to detect changes to #include dependencies. -MMD below generates a .d file for .cpp file. Include the .d file.
|
||||||
-include $(SRCS:.cpp=.d)
|
-include $(SRCS:.cpp=.d)
|
||||||
|
|
||||||
$(OBJS): %.o: %.cpp
|
$(OBJS): %.o: %.cpp
|
||||||
$(CXX) -o $@ $< -c -MMD $(CXXFLAGS)
|
$(CXX) -o $@ $< -c -MMD $(CXXFLAGS)
|
||||||
|
|
||||||
libgtest.a: $(GTESTDIR)/src/gtest-all.cc
|
libgtest.a: $(GTESTDIR)/src/gtest-all.cc deplib
|
||||||
$(CXX) -I $(GTESTDIR) -c -isystem $(GTESTDIR)/include $< $(CXXFLAGS) -o $(DEPINST)/lib/gtest-all.o
|
$(CXX) -I $(GTESTDIR) -c -isystem $(GTESTDIR)/include $< $(CXXFLAGS) -o $(DEPINST)/lib/gtest-all.o
|
||||||
$(AR) -rv $(DEPINST)/lib/libgtest.a $(DEPINST)/lib/gtest-all.o
|
$(AR) -rv $(DEPINST)/lib/libgtest.a $(DEPINST)/lib/gtest-all.o
|
||||||
|
|
||||||
|
@ -209,11 +222,14 @@ src/gadgetlib2/tests/gadgetlib2_test: \
|
||||||
src/gadgetlib2/tests/protoboard_UTEST.cpp \
|
src/gadgetlib2/tests/protoboard_UTEST.cpp \
|
||||||
src/gadgetlib2/tests/variable_UTEST.cpp
|
src/gadgetlib2/tests/variable_UTEST.cpp
|
||||||
|
|
||||||
$(EXECUTABLES): %: %.o $(OBJS)
|
$(EXECUTABLES): %: %.o $(OBJS) deplib
|
||||||
$(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) $(LDLIBS)
|
$(CXX) -o $@ $@.o $(OBJS) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS)
|
||||||
|
|
||||||
$(EXECUTABLES_WITH_GTEST): %: %.o $(OBJS)
|
$(EXECUTABLES_WITH_GTEST): %: %.o $(OBJS) deplib
|
||||||
$(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) $(GTEST_LDLIBS)
|
$(CXX) -o $@ $@.o $(OBJS) $(CXXFLAGS) $(LDFLAGS) $(GTEST_LDLIBS) $(LDLIBS)
|
||||||
|
|
||||||
|
$(EXECUTABLES_WITH_SUPERCOP): %: %.o $(OBJS) deplib
|
||||||
|
$(CXX) -o $@ $@.o $(OBJS) $(CXXFLAGS) $(LDFLAGS) $(SUPERCOP_LDLIBS) $(LDLIBS)
|
||||||
|
|
||||||
ifeq ($(STATIC),1)
|
ifeq ($(STATIC),1)
|
||||||
libsnark.a: $(OBJS)
|
libsnark.a: $(OBJS)
|
||||||
|
@ -229,11 +245,9 @@ lib: $(LIBOBJ)
|
||||||
|
|
||||||
|
|
||||||
$(DOCS): %.html: %.md
|
$(DOCS): %.html: %.md
|
||||||
ifneq ($(NO_DOCS),1)
|
|
||||||
markdown_py -f $@ $^ -x toc -x extra --noisy
|
markdown_py -f $@ $^ -x toc -x extra --noisy
|
||||||
# TODO: Would be nice to enable "-x smartypants" but Ubuntu 12.04 doesn't support that.
|
# TODO: Would be nice to enable "-x smartypants" but Ubuntu 12.04 doesn't support that.
|
||||||
# TODO: switch to redcarpet, to produce same output as GitHub's processing of README.md. But what about TOC?
|
# TODO: switch to redcarpet, to produce same output as GitHub's processing of README.md. But what about TOC?
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(PREFIX),)
|
ifeq ($(PREFIX),)
|
||||||
install:
|
install:
|
||||||
|
@ -246,7 +260,7 @@ $(HEADERS_DEST): $(PREFIX)/include/libsnark/%: src/%
|
||||||
mkdir -p $(shell dirname $@)
|
mkdir -p $(shell dirname $@)
|
||||||
cp $< $@
|
cp $< $@
|
||||||
|
|
||||||
install: lib $(HEADERS_DEST)
|
install: lib $(HEADERS_DEST) deplib
|
||||||
mkdir -p $(PREFIX)/lib
|
mkdir -p $(PREFIX)/lib
|
||||||
cp $(LIBOBJ) $(PREFIX)/lib/$(LIBOBJ)
|
cp $(LIBOBJ) $(PREFIX)/lib/$(LIBOBJ)
|
||||||
cp -rv $(DEPINST)/lib $(PREFIX)
|
cp -rv $(DEPINST)/lib $(PREFIX)
|
||||||
|
@ -270,6 +284,6 @@ clean:
|
||||||
|
|
||||||
# Clean all, including locally-compiled dependencies
|
# Clean all, including locally-compiled dependencies
|
||||||
clean-all: clean
|
clean-all: clean
|
||||||
rm -fr $(DEPSRC) $(DEPINST)
|
$(RM) -fr $(DEPSRC) $(DEPINST)
|
||||||
|
|
||||||
.PHONY: all clean clean-all doc doxy lib
|
.PHONY: all clean clean-all doc doxy lib deplib
|
||||||
|
|
|
@ -209,10 +209,6 @@ compile it. (Required only when using the default bn128 curve.)
|
||||||
|
|
||||||
$ ./prepare-depends.sh
|
$ ./prepare-depends.sh
|
||||||
|
|
||||||
If not using bn128 option the depinst directory, referred to in Makefile, needs to be created manually:
|
|
||||||
|
|
||||||
$ mkdir -p depinst/include depinst/src
|
|
||||||
|
|
||||||
Then, to compile the library, tests, profiling harness and documentation, run:
|
Then, to compile the library, tests, profiling harness and documentation, run:
|
||||||
|
|
||||||
$ make
|
$ make
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# This script fetches, builds and locally installs the external ate-pairing library (and its dependency, xbyak)
|
# This script fetches, builds and locally installs external dependencies.
|
||||||
|
|
||||||
set -x -e
|
set -x -e
|
||||||
|
|
||||||
|
@ -10,19 +10,22 @@ DEPINST=./depinst
|
||||||
mkdir -p $DEPINST
|
mkdir -p $DEPINST
|
||||||
mkdir -p $DEPSRC
|
mkdir -p $DEPSRC
|
||||||
|
|
||||||
|
# ate-pairing library, and its dependency, xbyak (needed for BN128 curve)
|
||||||
cd $DEPSRC
|
cd $DEPSRC
|
||||||
[ ! -d xbyak ] && git clone git://github.com/herumi/xbyak.git
|
[ ! -d xbyak ] && git clone git://github.com/herumi/xbyak.git
|
||||||
[ ! -d ate-pairing ] && git clone git://github.com/herumi/ate-pairing.git
|
[ ! -d ate-pairing ] && git clone git://github.com/herumi/ate-pairing.git
|
||||||
[ ! -d libsnark-supercop ] && git clone git://github.com/mbbarbosa/libsnark-supercop.git
|
|
||||||
cd ate-pairing
|
cd ate-pairing
|
||||||
make -j SUPPORT_SNARK=1
|
make -j SUPPORT_SNARK=1
|
||||||
cd ..
|
cd ../..
|
||||||
cd libsnark-supercop
|
|
||||||
sh "do"
|
|
||||||
cd ..
|
|
||||||
cd ..
|
|
||||||
cp -rv $DEPSRC/ate-pairing/include $DEPINST/
|
cp -rv $DEPSRC/ate-pairing/include $DEPINST/
|
||||||
cp -rv $DEPSRC/ate-pairing/lib $DEPINST/
|
cp -rv $DEPSRC/ate-pairing/lib $DEPINST/
|
||||||
|
|
||||||
|
# SUPERCOP library (optimized crypto implementations, used by ADSNARK)
|
||||||
|
cd $DEPSRC
|
||||||
|
[ ! -d libsnark-supercop ] && git clone git://github.com/mbbarbosa/libsnark-supercop.git
|
||||||
|
cd libsnark-supercop
|
||||||
|
sh "do"
|
||||||
|
cd ../..
|
||||||
mkdir -p $DEPINST/include/supercop
|
mkdir -p $DEPINST/include/supercop
|
||||||
cp -v $DEPSRC/libsnark-supercop/include/* $DEPINST/include/supercop
|
cp -v $DEPSRC/libsnark-supercop/include/* $DEPINST/include/supercop
|
||||||
cp -rv $DEPSRC/libsnark-supercop/lib $DEPINST/
|
cp -rv $DEPSRC/libsnark-supercop/lib $DEPINST/
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#define BN128_INIT_HPP_
|
#define BN128_INIT_HPP_
|
||||||
#include "algebra/curves/public_params.hpp"
|
#include "algebra/curves/public_params.hpp"
|
||||||
#include "algebra/fields/fp.hpp"
|
#include "algebra/fields/fp.hpp"
|
||||||
#include "bn.h"
|
#include "bn.h" // If you're missing this file, run libsnark's ./prepare-depends.sh
|
||||||
|
|
||||||
namespace libsnark {
|
namespace libsnark {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue