mlucas.in 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/sh
  2. #
  3. # mlucas - shell wrapper for Mlucas
  4. # Copyright (C) 2015, 2017 Alex Vong
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software Foundation,
  18. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. # Use error
  20. set -e
  21. # Obtain PKGLIBEXECDIR from substitution
  22. PKGLIBEXECDIR='@pkglibexecdir@/'
  23. # Obtain DIRNAME by tranforming `foo/bar' to `foo/'
  24. # Otherwise, set it to $PKGLIBEXECDIR
  25. case "$0" in
  26. */*)
  27. DIRNAME=`printf '%s' "$0" | sed -e 's/\/[^\/]*$/\//g'`
  28. ;;
  29. *)
  30. DIRNAME="$PKGLIBEXECDIR"
  31. ;;
  32. esac
  33. # Find out where are the mlucas executables
  34. # Print error messages if fail to find mlucas executables
  35. if test -x "$DIRNAME"avx2/mlucas && \
  36. test -x "$DIRNAME"avx/mlucas && \
  37. test -x "$DIRNAME"sse2/mlucas
  38. then
  39. # Try invoking different flavours of mlucas using relative path
  40. # Normally,the sse2 version should work for all amd64 computers
  41. # The `else' clause must not be changed to `elif'
  42. # Otherwise, user will be left hopelessly without any error messages
  43. # if something goes wrong (e.g. MLUCAS_PATH without a trailing `/')
  44. if "$DIRNAME"avx2/mlucas \
  45. -fftlen 192 -iters 100 -radset 0 -nthread 2 \
  46. > /dev/null 2>&1
  47. then
  48. exec "$DIRNAME"avx2/mlucas "$@"
  49. elif "$DIRNAME"avx/mlucas \
  50. -fftlen 192 -iters 100 -radset 0 -nthread 2 \
  51. > /dev/null 2>&1
  52. then
  53. exec "$DIRNAME"avx/mlucas "$@"
  54. else
  55. exec "$DIRNAME"sse2/mlucas "$@"
  56. fi
  57. elif test -x "$PKGLIBEXECDIR"avx2/mlucas && \
  58. test -x "$PKGLIBEXECDIR"avx/mlucas && \
  59. test -x "$PKGLIBEXECDIR"sse2/mlucas
  60. then
  61. # Try invoking different flavours of mlucas using absolute path
  62. # Normally,the sse2 version should work for all amd64 computers
  63. # The `else' clause must not be changed to `elif'
  64. # Otherwise, user will be left hopelessly without any error messages
  65. # if something goes wrong (e.g. MLUCAS_PATH without a trailing `/')
  66. if "$PKGLIBEXECDIR"avx2/mlucas \
  67. -fftlen 192 -iters 100 -radset 0 -nthread 2 \
  68. > /dev/null 2>&1
  69. then
  70. exec "$PKGLIBEXECDIR"avx2/mlucas "$@"
  71. elif "$PKGLIBEXECDIR"avx/mlucas \
  72. -fftlen 192 -iters 100 -radset 0 -nthread 2 \
  73. > /dev/null 2>&1
  74. then
  75. exec "$PKGLIBEXECDIR"avx/mlucas "$@"
  76. else
  77. exec "$PKGLIBEXECDIR"sse2/mlucas "$@"
  78. fi
  79. else
  80. printf '%s\n%s\n%s\n' \
  81. 'cannot find any mlucas executables' \
  82. 'see BUGS section in mlucas(1)' \
  83. 'on how to report bugs about installation problems' \
  84. >&2
  85. fi