You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

configure 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/sh
  2. if test -f config.mk; then
  3. exit 0
  4. fi
  5. if test -z "$CC"; then
  6. CC=cc
  7. fi
  8. if test -z "$YASM"; then
  9. YASM=yasm
  10. fi
  11. # test yasm
  12. $YASM -f elf64 -o /tmp/secp256k1-$$.o - <<EOF
  13. BITS 64
  14. GLOBAL testyasm
  15. ALIGN 32
  16. testyasm:
  17. xor r9,r9
  18. EOF
  19. if [ "$?" = 0 ]; then
  20. $CC $CFLAGS -std=c99 -x c -c - -o /tmp/secp256k1-$$-2.o 2>/dev/null <<EOF
  21. void __attribute__ ((sysv_abi)) testyasm(void);
  22. int main() {
  23. testyasm();
  24. return 0;
  25. }
  26. EOF
  27. $CC $CFLAGS -std=c99 /tmp/secp256k1-$$-2.o /tmp/secp256k1-$$.o -o /dev/null 2>/dev/null
  28. if [ "$?" = 0 ]; then
  29. HAVE_YASM=1
  30. fi
  31. rm -rf /tmp/secp256k1-$$-2.o /tmp/secp256k1-$$.o
  32. fi
  33. # test openssl
  34. HAVE_OPENSSL=0
  35. $CC $CFLAGS -std=c99 -x c - -o /dev/null -lcrypto 2>/dev/null <<EOF
  36. #include <openssl/bn.h>
  37. int main() {
  38. BN_CTX *ctx = BN_CTX_new();
  39. BN_CTX_free(ctx);
  40. return 0;
  41. }
  42. EOF
  43. if [ "$?" = 0 ]; then
  44. HAVE_OPENSSL=1
  45. fi
  46. # test gmp
  47. HAVE_GMP=0
  48. $CC $CFLAGS -std=c99 -x c - -o /dev/null -lgmp 2>/dev/null <<EOF
  49. #include <gmp.h>
  50. int main() {
  51. mpz_t n;
  52. mpz_init(n);
  53. mpz_clear(n);
  54. return 0;
  55. }
  56. EOF
  57. if [ "$?" = 0 ]; then
  58. HAVE_GMP=1
  59. fi
  60. # test __int128
  61. HAVE_INT128=0
  62. $CC $CFLAGS -std=c99 -x c - -o /dev/null 2>/dev/null <<EOF
  63. #include <stdint.h>
  64. int main() {
  65. __int128 x = 0;
  66. return 0;
  67. }
  68. EOF
  69. if [ "$?" = 0 ]; then
  70. HAVE_INT128=1
  71. fi
  72. for arg in "$@"; do
  73. case "$arg" in
  74. --no-yasm)
  75. HAVE_YASM=0
  76. ;;
  77. --no-gmp)
  78. HAVE_GMP=0
  79. ;;
  80. --no-openssl)
  81. HAVE_OPENSSL=0
  82. ;;
  83. esac
  84. done
  85. LINK_OPENSSL=0
  86. LINK_GMP=0
  87. USE_ASM=0
  88. # select field implementation
  89. if [ "$HAVE_YASM" = "1" ]; then
  90. CFLAGS_FIELD="-DUSE_FIELD_5X52 -DUSE_FIELD_5X52_ASM"
  91. USE_ASM=1
  92. elif [ "$HAVE_INT128" = "1" ]; then
  93. CFLAGS_FIELD="-DUSE_FIELD_5X52 -DUSE_FIELD_5X52_INT128"
  94. elif [ "$HAVE_GMP" = "1" ]; then
  95. CFLAGS_FIELD="-DUSE_FIELD_GMP"
  96. LINK_GMP=1
  97. else
  98. CFLAGS_FIELD="-DUSE_FIELD_10X26"
  99. fi
  100. # select num implementation
  101. if [ "$HAVE_GMP" = "1" ]; then
  102. CFLAGS_NUM="-DUSE_NUM_GMP -DUSE_FIELD_INV_NUM"
  103. LINK_GMP=1
  104. elif [ "$HAVE_OPENSSL" = "1" ]; then
  105. CFLAGS_NUM="-DUSE_NUM_OPENSSL -DUSE_FIELD_INV_BUILTIN"
  106. LINK_OPENSSL=1
  107. else
  108. echo "No usable num implementation found" >&2
  109. exit 1
  110. fi
  111. CFLAGS_EXTRA="$CFLAGS_FIELD $CFLAGS_NUM"
  112. LDFLAGS_EXTRA=""
  113. if [ "$LINK_GMP" = "1" ]; then
  114. LDFLAGS_EXTRA="-lgmp"
  115. fi
  116. if [ "$LINK_OPENSSL" = "1" ]; then
  117. LDFLAGS_EXTRA="-lcrypto"
  118. fi
  119. echo "CC=$CC" > config.mk
  120. echo "YASM=$YASM" >>config.mk
  121. echo "CFLAGS_EXTRA=$CFLAGS_EXTRA" >> config.mk
  122. echo "LDFLAGS_EXTRA=$LDFLAGS_EXTRA" >> config.mk
  123. echo "USE_ASM=$USE_ASM" >>config.mk