herumi / mcl

a portable and fast pairing-based cryptography library
BSD 3-Clause "New" or "Revised" License
458 stars 157 forks source link

Add support for building on OpenBSD #83

Closed alexandervdm closed 4 years ago

alexandervdm commented 4 years ago

This PR allows mcl to be built on OpenBSD using the Makefile. Modern releases of OpenBSD include both clang and gcc in the base system. Building mcl on the included version of gcc however is problematic since it is ancient (v4.2.1) and results in a cascade of missing instruction (mulxq) errors. The changes in this PR configure the Makefile to use the clang compiler instead on OpenBSD.

Build log: https://pastebin.com/raw/48zfguVL

Also included is a patch that moves some build flags that are specific to gcc to an underlying conditional block to prevent them from being used for clang.

Test results on my OpenBSD-current system:

alexander@proofofbsd ~/Desktop/alexander-mcl $ gmake bin/bn_c384_256_test.exe && bin/bn_c384_256_test.exe
clang++ -I/usr/local/include -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -m64 -I include -I test -O3  -DMCL_DONT_USE_OPENSSL -fPIC -DMCL_USE_LLVM=1 -c test/bn_c384_256_test.cpp -o obj/bn_c384_256_test.o -MMD -MP -MF obj/bn_c384_256_test.d
clang++ obj/bn_c384_256_test.o -o bin/bn_c384_256_test.exe lib/libmclbn384_256.a lib/libmcl.a -L/usr/local/lib -lgmp -lgmpxx  -m64 
ctest:module=init
.. omitted ..
ctest:name=bn_c384_256_test, module=29, total=727, ok=727, ng=0, exception=0
alexander@proofofbsd ~/Desktop/alexander-mcl $ gmake bin/bls12_test.exe && bin/bls12_test.exe             
clang++ -I/usr/local/include -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -m64 -I include -I test -O3  -DMCL_DONT_USE_OPENSSL -fPIC -DMCL_USE_LLVM=1 -c test/bls12_test.cpp -o obj/bls12_test.o -MMD -MP -MF obj/bls12_test.d
clang++ obj/bls12_test.o -o bin/bls12_test.exe lib/libmcl.a -L/usr/local/lib -lgmp -lgmpxx  -m64 
JIT 0
.. omitted ..
ctest:name=bls12_test, module=9, total=3727, ok=3727, ng=0, exception=0

If you are interested in this PR, I'd be happy to improve upon it - such as adding support to the CMake build system.

herumi commented 4 years ago

Thank you for the patch.

About https://github.com/herumi/mcl/pull/83/commits/16874a19f650c6c6a7a7a39a456a69e4cbe30512 , I think that -DNDEBUG should be defined on a release mode and clang supports the other options.

herumi commented 4 years ago

I merged https://github.com/herumi/mcl/pull/83/commits/b575c9c18821704e1fa84f7517bff3cd578340ba .

alexandervdm commented 4 years ago

You are correct, thanks for accepting b575c9c18821704e1fa84f7517bff3cd578340ba