File: acinclude.m4

package info (click to toggle)
gmp-ecm 7.0.4+ds-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,728 kB
  • sloc: asm: 36,431; ansic: 34,057; xml: 885; python: 799; sh: 698; makefile: 348
file content (635 lines) | stat: -rw-r--r-- 20,757 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
dnl Various routines adapted from gmp-4.1.4

define(X86_PATTERN,
[[i?86*-*-* | k[5-8]*-*-* | pentium*-*-* | athlon-*-* | viac3*-*-*]])


dnl  GMP_INIT([M4-DEF-FILE])
dnl  -----------------------
dnl  Initializations for GMP config.m4 generation.
dnl
dnl  FIXME: The generated config.m4 doesn't get recreated by config.status.
dnl  Maybe the relevant "echo"s should go through AC_CONFIG_COMMANDS.

AC_DEFUN([GMP_INIT],
[ifelse([$1], , gmp_configm4=config.m4, gmp_configm4="[$1]")
gmp_tmpconfigm4=cnfm4.tmp
gmp_tmpconfigm4i=cnfm4i.tmp
gmp_tmpconfigm4p=cnfm4p.tmp
rm -f $gmp_tmpconfigm4 $gmp_tmpconfigm4i $gmp_tmpconfigm4p
])


dnl  GMP_FINISH
dnl  ----------
dnl  Create config.m4 from its accumulated parts.
dnl
dnl  __CONFIG_M4_INCLUDED__ is used so that a second or subsequent include
dnl  of config.m4 is harmless.
dnl
dnl  A separate ifdef on the angle bracket quoted part ensures the quoting
dnl  style there is respected.  The basic defines from gmp_tmpconfigm4 are
dnl  fully quoted but are still put under an ifdef in case any have been
dnl  redefined by one of the m4 include files.
dnl
dnl  Doing a big ifdef within asm-defs.m4 and/or other macro files wouldn't
dnl  work, since it'd interpret parentheses and quotes in dnl comments, and
dnl  having a whole file as a macro argument would overflow the string space
dnl  on BSD m4.

AC_DEFUN([GMP_FINISH],
[AC_REQUIRE([GMP_INIT])
echo "creating $gmp_configm4"
echo ["d""nl $gmp_configm4.  Generated automatically by configure."] > $gmp_configm4
if test -f $gmp_tmpconfigm4; then
  echo ["changequote(<,>)"] >> $gmp_configm4
  echo ["ifdef(<__CONFIG_M4_INCLUDED__>,,<"] >> $gmp_configm4
  cat $gmp_tmpconfigm4 >> $gmp_configm4
  echo [">)"] >> $gmp_configm4
  echo ["changequote(\`,')"] >> $gmp_configm4
  rm $gmp_tmpconfigm4
fi
echo ["ifdef(\`__CONFIG_M4_INCLUDED__',,\`"] >> $gmp_configm4
if test -f $gmp_tmpconfigm4i; then
  cat $gmp_tmpconfigm4i >> $gmp_configm4
  rm $gmp_tmpconfigm4i
fi
if test -f $gmp_tmpconfigm4p; then
  cat $gmp_tmpconfigm4p >> $gmp_configm4
  rm $gmp_tmpconfigm4p
fi
echo ["')"] >> $gmp_configm4
echo ["define(\`__CONFIG_M4_INCLUDED__')"] >> $gmp_configm4
])


dnl  GMP_PROG_M4
dnl  -----------
dnl  Find a working m4, either in $PATH or likely locations, and setup $M4
dnl  and an AC_SUBST accordingly.  If $M4 is already set then it's a user
dnl  choice and is accepted with no checks.  GMP_PROG_M4 is like
dnl  AC_PATH_PROG or AC_CHECK_PROG, but tests each m4 found to see if it's
dnl  good enough.
dnl 
dnl  See mpn/asm-defs.m4 for details on the known bad m4s.

AC_DEFUN([GMP_PROG_M4],
[AC_ARG_VAR(M4,[m4 macro processor])
AC_CACHE_CHECK([for suitable m4],
                gmp_cv_prog_m4,
[if test -n "$M4"; then
  gmp_cv_prog_m4="$M4"
else
  cat >conftest.m4 <<\EOF
dnl  Must protect this against being expanded during autoconf m4!
dnl  Dont put "dnl"s in this as autoconf will flag an error for unexpanded
dnl  macros.
[define(dollarhash,``$][#'')ifelse(dollarhash(x),1,`define(t1,Y)',
``bad: $][# not supported (SunOS /usr/bin/m4)
'')ifelse(eval(89),89,`define(t2,Y)',
`bad: eval() doesnt support 8 or 9 in a constant (OpenBSD 2.6 m4)
')ifelse(t1`'t2,YY,`good
')]
EOF
dnl ' <- balance the quotes for emacs sh-mode
  echo "trying m4" >&AC_FD_CC
  gmp_tmp_val=`(m4 conftest.m4) 2>&AC_FD_CC`
  echo "$gmp_tmp_val" >&AC_FD_CC
  if test "$gmp_tmp_val" = good; then
    gmp_cv_prog_m4="m4"
  else
    IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
dnl $ac_dummy forces splitting on constant user-supplied paths.
dnl POSIX.2 word splitting is done only on the output of word expansions,
dnl not every word.  This closes a longstanding sh security hole.
    ac_dummy="$PATH:/usr/5bin"
    for ac_dir in $ac_dummy; do
      test -z "$ac_dir" && ac_dir=.
      echo "trying $ac_dir/m4" >&AC_FD_CC
      gmp_tmp_val=`($ac_dir/m4 conftest.m4) 2>&AC_FD_CC`
      echo "$gmp_tmp_val" >&AC_FD_CC
      if test "$gmp_tmp_val" = good; then
        gmp_cv_prog_m4="$ac_dir/m4"
        break
      fi
    done
    IFS="$ac_save_ifs"
    if test -z "$gmp_cv_prog_m4"; then
      AC_MSG_ERROR([No usable m4 in \$PATH or /usr/5bin (see config.log for reasons).])
    fi
  fi
  rm -f conftest.m4
fi])
M4="$gmp_cv_prog_m4"
AC_SUBST(M4)
])


dnl  GMP_DEFINE(MACRO, DEFINITION [, LOCATION])
dnl  ------------------------------------------
dnl  Define M4 macro MACRO as DEFINITION in temporary file.
dnl
dnl  If LOCATION is `POST', the definition will appear after any include()
dnl  directives inserted by GMP_INCLUDE.  Mind the quoting!  No shell
dnl  variables will get expanded.  Don't forget to invoke GMP_FINISH to
dnl  create file config.m4.  config.m4 uses `<' and '>' as quote characters
dnl  for all defines.

AC_DEFUN([GMP_DEFINE],
[AC_REQUIRE([GMP_INIT])
echo ['define(<$1>, <$2>)'] >>ifelse([$3], [POST],
                              $gmp_tmpconfigm4p, $gmp_tmpconfigm4)
])


dnl  GMP_TRY_ASSEMBLE(asm-code,[action-success][,action-fail])
dnl  ----------------------------------------------------------
dnl  Attempt to assemble the given code.
dnl  Do "action-success" if this succeeds, "action-fail" if not.
dnl
dnl  conftest.o and conftest.out are available for inspection in
dnl  "action-success".  If either action does a "break" out of a loop then
dnl  an explicit "rm -f conftest*" will be necessary.
dnl
dnl  This is not unlike AC_TRY_COMPILE, but there's no default includes or
dnl  anything in "asm-code", everything wanted must be given explicitly.

AC_DEFUN([GMP_TRY_ASSEMBLE],
[cat >conftest.s <<EOF
[$1]
EOF
gmp_assemble="$CCAS $CCASFLAGS -c conftest.s >conftest.out 2>&1"
if AC_TRY_EVAL(gmp_assemble); then
  cat conftest.out >&AC_FD_CC
  ifelse([$2],,:,[$2])
else
  cat conftest.out >&AC_FD_CC
  echo "configure: failed program was:" >&AC_FD_CC
  cat conftest.s >&AC_FD_CC
  ifelse([$3],,:,[$3])
fi
rm -f conftest*
])


dnl  GMP_ASM_TYPE
dnl  ------------
dnl  Can we say ".type", and how?
dnl
dnl  For i386 GNU/Linux ELF systems, and very likely other ELF systems,
dnl  .type and .size are important on functions in shared libraries.  If
dnl  .type is omitted and the mainline program references that function then
dnl  the code will be copied down to the mainline at load time like a piece
dnl  of data.  If .size is wrong or missing (it defaults to 4 bytes or some
dnl  such) then incorrect bytes will be copied and a segv is the most likely
dnl  result.  In any case such copying is not what's wanted, a .type
dnl  directive will ensure a PLT entry is used.
dnl
dnl  In GMP the assembler functions are normally only used from within the
dnl  library (since most programs are not interested in the low level
dnl  routines), and in those circumstances a missing .type isn't fatal,
dnl  letting the problem go unnoticed.  tests/mpn/t-asmtype.c aims to check
dnl  for it.

AC_DEFUN([GMP_ASM_TYPE],
[AC_CACHE_CHECK([for assembler .type directive],
                gmp_cv_asm_type,
[gmp_cv_asm_type=
for gmp_tmp_prefix in @ \# %; do
  GMP_TRY_ASSEMBLE([	.type	sym,${gmp_tmp_prefix}function],
    [if grep "\.type pseudo-op used outside of \.def/\.endef ignored" conftest.out >/dev/null; then : ;
    else
      gmp_cv_asm_type=".type	\$][1,${gmp_tmp_prefix}\$][2"
      break
    fi])
done
rm -f conftest*
])
echo ["define(<TYPE>, <$gmp_cv_asm_type>)"] >> $gmp_tmpconfigm4
])


dnl  GMP_ASM_GLOBL
dnl  -------------
dnl  Can we say `.global'?

AC_DEFUN([GMP_ASM_GLOBL],
[AC_CACHE_CHECK([how to export a symbol],
                gmp_cv_asm_globl,
[case $host in
  *-*-hpux*) gmp_cv_asm_globl=".export" ;;
  *)         gmp_cv_asm_globl=".globl" ;;
esac
])
echo ["define(<GLOBL>, <$gmp_cv_asm_globl>)"] >> $gmp_tmpconfigm4
])


dnl  GMP_ASM_TEXT
dnl  ------------

AC_DEFUN([GMP_ASM_TEXT],
[AC_CACHE_CHECK([how to switch to text section],
                gmp_cv_asm_text,
[case $host in
  *-*-aix*)  gmp_cv_asm_text=[".csect .text[PR]"] ;;
  *-*-hpux*) gmp_cv_asm_text=".code" ;;
  *)         gmp_cv_asm_text=".text" ;;
esac
])
echo ["define(<TEXT>, <$gmp_cv_asm_text>)"] >> $gmp_tmpconfigm4
])


dnl  GMP_ASM_LABEL_SUFFIX
dnl  --------------------
dnl  Should a label have a colon or not?

AC_DEFUN([GMP_ASM_LABEL_SUFFIX],
[AC_CACHE_CHECK([what assembly label suffix to use],
                gmp_cv_asm_label_suffix,
[case $host in 
  # Empty is only for the HP-UX hppa assembler; hppa gas requires a colon.
  *-*-hpux*) gmp_cv_asm_label_suffix=  ;;
  *)         gmp_cv_asm_label_suffix=: ;;
esac
])
echo ["define(<LABEL_SUFFIX>, <\$][1$gmp_cv_asm_label_suffix>)"] >> $gmp_tmpconfigm4
])


dnl  ECM_INCLUDE(FILE)
dnl  ---------------------
dnl  Add an include_mpn() to config.m4.  FILE should be a path
dnl  relative to the main source directory, for example
dnl
dnl      ECM_INCLUDE(`powerpc64/defs.m4')
dnl

AC_DEFUN([ECM_INCLUDE],
[AC_REQUIRE([GMP_INIT])
echo ["include($1)"] >> $gmp_tmpconfigm4
])


dnl  GMP_ASM_UNDERSCORE
dnl  ------------------
dnl  Determine whether global symbols need to be prefixed with an underscore.
dnl  A test program is linked to an assembler module with or without an
dnl  underscore to see which works.
dnl
dnl  This method should be more reliable than grepping a .o file or using
dnl  nm, since it corresponds to what a real program is going to do.  Note
dnl  in particular that grepping doesn't work with SunOS 4 native grep since
dnl  that grep seems to have trouble with '\0's in files.

AC_DEFUN([GMP_ASM_UNDERSCORE],
[AC_REQUIRE([GMP_ASM_TEXT])
AC_REQUIRE([GMP_ASM_GLOBL])
AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
AC_CACHE_CHECK([if globals are prefixed by underscore], 
               gmp_cv_asm_underscore,
[cat >conftes1.c <<EOF
#ifdef __cplusplus
extern "C" { void underscore_test(); }
#endif
main () { underscore_test(); }
EOF
for tmp_underscore in "" "_"; do
  cat >conftes2.s <<EOF
      	$gmp_cv_asm_text
	$gmp_cv_asm_globl ${tmp_underscore}underscore_test
${tmp_underscore}underscore_test$gmp_cv_asm_label_suffix
EOF
  case $host in
  *-*-aix*)
    cat >>conftes2.s <<EOF
	$gmp_cv_asm_globl .${tmp_underscore}underscore_test
.${tmp_underscore}underscore_test$gmp_cv_asm_label_suffix
EOF
    ;;
  esac
  gmp_compile="$CC $CFLAGS $CPPFLAGS -c conftes1.c >&AC_FD_CC && $CCAS $CCASFLAGS -c conftes2.s >&AC_FD_CC && $CC $CFLAGS $LDFLAGS conftes1.$OBJEXT conftes2.$OBJEXT >&AC_FD_CC"
  if AC_TRY_EVAL(gmp_compile); then
    eval tmp_result$tmp_underscore=yes
  else
    eval tmp_result$tmp_underscore=no
  fi
done

if test $tmp_result_ = yes; then
  if test $tmp_result = yes; then
    AC_MSG_ERROR([Test program unexpectedly links both with and without underscore.])
  else
    gmp_cv_asm_underscore=yes
  fi
else
  if test $tmp_result = yes; then
    gmp_cv_asm_underscore=no
  else
    AC_MSG_ERROR([Test program links neither with nor without underscore.])
  fi
fi
rm -f conftes1* conftes2* a.out
])
if test "$gmp_cv_asm_underscore" = "yes"; then
  GMP_DEFINE(GSYM_PREFIX, [_])
else
  GMP_DEFINE(GSYM_PREFIX, [])
fi    
])

# If we are not cross-compiling, do AC_RUN_IFELSE. If we are cross-compiling,
# do AC_COMPILE_IFELSE
AC_DEFUN([ECM_RUN_IFELSE], dnl
  [AC_RUN_IFELSE]([[$1]], [[$2]], [[$3]], dnl ok
    [[AC_COMPILE_IFELSE]]([[[$1]]], [[[$2]]], [[[$3]]]) dnl
  ) dnl
)

# A test program to check whether the compiler can compile SSE2 instructions 
# as inline assembly. If HAVE_SSE2 is defined, the code also includes
# emmintrin.h, which may need -sse2 to function
AC_DEFUN([ECM_C_INLINESSE2_PROG], dnl
[AC_LANG_PROGRAM([[#include <emmintrin.h>]], dnl
[[int v4[4] = {5,6,7,8};

  asm volatile (
    "movdqu %0, %%xmm0\n\t"
    "pmuludq %%xmm0, %%xmm0\n\t"
    "movdqu %%xmm0, %0\n\t"
    : "+m" (v4)
    : "r"(0)
    : "%xmm0"
  );
  if (v4[0] != 25 || v4[1] != 0 || v4[2] != 49 || v4[3] != 0) {
    return 1;
  }
]])])

dnl  CU_CHECK_CUDA
dnl  Check if a GPU version is asked, for which GPU and where CUDA is install.
dnl  Includes are put in CUDA_INC_FLAGS
dnl  Libraries are put in CUDA_LIB_FLAGS
dnl  Path to nvcc is put in NVCC
dnl  the GPU architecture for which it is compiled is in GPU_ARCH

AC_DEFUN([CU_CHECK_CUDA],
[
# Is the GPU version is requested?
AC_ARG_ENABLE(gpu,
  AS_HELP_STRING([--enable-gpu=GPU_ARCH],
                 [Enable the cuda version [default=no]]),
  [ AS_IF([test "x$enableval" = "xno"], [ enable_gpu="no" ],
                                        [ enable_gpu="yes" ]) ] )

AC_ARG_WITH(cuda,
  AS_HELP_STRING([--with-cuda=DIR],
                 [CUDA install directory [default=guessed]]),
  [ cuda_include=$withval/include
    # If $build_cpu contains "_64", append "lib64", else append "lib"
    AS_IF([echo $build_cpu | grep -q "_64"], 
      [cuda_lib=$withval/lib64],
      [cuda_lib=$withval/lib])
    cuda_bin=$withval/bin ])

AC_ARG_WITH(cuda_include,
  AS_HELP_STRING([--with-cuda-include=DIR],
                 [CUDA include directory [default=guessed]]),
  [ cuda_include=$withval ])

AC_ARG_WITH(cuda_lib,
  AS_HELP_STRING([--with-cuda-lib=DIR],
                 [CUDA lib directory [default=guessed]]),
  [ cuda_lib=$withval ])

AC_ARG_WITH(cuda_bin,
  AS_HELP_STRING([--with-cuda-bin=DIR],
                 [CUDA bin directory for nvcc [default=guessed]]),
  [ cuda_bin=$withval ])

AC_ARG_WITH(cuda_compiler, 
  AS_HELP_STRING([--with-cuda-compiler=DIR], 
            [a directory that contains a C and C++ compiler compatible with the CUDA compiler nvcc. If given, the value is used as '--compiler-bindir' argument for nvcc ]),
  [ cuda_compiler=$withval ])

AS_IF([test "x$enable_gpu" = "xyes" ],
  [
    AS_IF([test "x$cuda_include" != "x"],
      [
        AC_MSG_NOTICE([Using cuda.h from $cuda_include])
        AS_IF([test -d "$cuda_include"],
          [], 
          [ 
            AC_MSG_ERROR([Specified CUDA include directory "$cuda_include" does not exist])
          ])
        CFLAGS="-I$cuda_include $CFLAGS"
        CPPFLAGS="-I$cuda_include $CPPFLAGS"
        NVCCFLAGS="-I$cuda_include $NVCCFLAGS"
      ])
    AC_CHECK_HEADERS([cuda.h], [], AC_MSG_ERROR([required header file missing]))
    AC_MSG_CHECKING([that CUDA Toolkit version is at least 3.0])
    AC_RUN_IFELSE([AC_LANG_PROGRAM([
      [
        #include <stdio.h>
        #include <string.h>
        #include <cuda.h>
      ]],[[
        printf("(%d.%d) ", CUDA_VERSION/1000, (CUDA_VERSION/10) % 10);
        if (CUDA_VERSION < 3000)
          return 1;
        else
          return 0;
      ]])],
      [AC_MSG_RESULT([yes])],
      [
        AC_MSG_RESULT([no])
        AC_MSG_ERROR([a newer version of the CUDA Toolkit is needed])
      ],
      [
        AC_MSG_RESULT([cross-compiling: cannot test])
      ])

    CUDALIB="-lcudart -lstdc++"
    LIBS_BACKUP="$LIBS"
    LDFLAGS_BACKUP="$LDFLAGS"
    CUDARPATH=""
    AS_IF([test "x$cuda_lib" != "x"],
      [
        AC_MSG_NOTICE([Using CUDA dynamic library from $cuda_lib])
        AS_IF([test -d "$cuda_lib"],
          [], 
          [ 
            AC_MSG_ERROR([Specified CUDA lib directory "$cuda_lib" does not exist])
          ])
        CUDALDFLAGS="-L$cuda_lib"
        LDFLAGS="-L$cuda_lib $LDFLAGS"
        AS_CASE(["$host_os"], [*"linux"*], [ LDFLAGS="-Wl,-rpath,$cuda_lib $LDFLAGS" ])
        CUDARPATH="-R $cuda_lib"
      ])
    AC_CHECK_LIB([cuda], [cuInit], [], [AC_MSG_ERROR([Couldn't find CUDA lib])])
    LIBS="$CUDALIB $LIBS"
    AC_MSG_CHECKING([that CUDA Toolkit version and runtime version are the same])
    AC_RUN_IFELSE([AC_LANG_PROGRAM([
      [
        #include <stdio.h>
        #include <string.h>
        #include <cuda.h>
        #include <cuda_runtime.h>
      ]],[[
        int libversion;
        cudaError_t err;
        err = cudaRuntimeGetVersion (&libversion);
        if (err != cudaSuccess)
        {
          printf ("Could not get runtime version\n");
          printf ("Error msg: %s\n", cudaGetErrorString(err));
          return -1;
        }
        printf("(%d.%d/", CUDA_VERSION/1000, (CUDA_VERSION/10) % 10);
        printf("%d.%d) ", libversion/1000, (libversion/10) % 10);
        if (CUDA_VERSION == libversion)
          return 0;
        else
          return 1;
      ]])],
      [AC_MSG_RESULT([yes])],
      [
        AC_MSG_RESULT([no])
        AC_MSG_ERROR(['cuda.h' and 'cudart' library have different versions, you have to reinstall CUDA properly, or use the --with-cuda parameter to tell configure the path to the CUDA library and header you want to use])
      ],
      [
        AC_MSG_RESULT([cross-compiling: cannot test])
      ])

    AS_IF([test "x$cuda_bin" != "x"],
      [
        AC_MSG_NOTICE([Using nvcc compiler from from $cuda_bin])
        AS_IF([test -f "$cuda_bin/nvcc"],
          [
            NVCC="$cuda_bin/nvcc"
          ], 
          [ 
            AC_MSG_ERROR([Could not find nvcc in specified CUDA bin directory "$cuda_bin"])
          ])
      ],
      [
        AC_PATH_PROG(NVCC, nvcc, "no")
        AS_IF([test "x$NVCC" = "xno" ], [ AC_MSG_ERROR(nvcc not found) ])
      ])

    AS_IF([test "x$cuda_compiler" != "x" ], 
          [NVCCFLAGS=" --compiler-bindir $cuda_compiler NVCCFLAGS"])
 
    dnl check that gcc version is compatible with nvcc version
    touch conftest.cu
    AC_MSG_CHECKING([for compatibility between gcc and nvcc])
    $NVCC -c conftest.cu -o conftest.o $NVCCFLAGS > /dev/null 2>&1
    AS_IF([test "$?" -eq "0"], 
      [
        AC_MSG_RESULT([yes])
      ], [
        AC_MSG_RESULT([no])
        AC_MSG_ERROR(gcc version is not compatible with nvcc)
      ])
      
    dnl Check which GPU architecture nvcc know
    NVCCTEST="$NVCC -c conftest.cu -o conftest.o $NVCCFLAGS --dryrun"
    GPU_ARCH=""
    m4_foreach_w([compute_compatibility], [20 21 30 32 35 37 50 52 53],
      [
        testcc=compute_compatibility
        AC_MSG_CHECKING([that nvcc know compute capability $testcc])
        AS_IF([test "$testcc" -eq "21"],
          [
            NEW="--generate-code arch=compute_20,code=sm_21"
          ],
          [
            NEW="--generate-code arch=compute_$testcc,code=sm_$testcc"
          ])
        $NVCCTEST $NEW > /dev/null 2>&1
        AS_IF([test "$?" -eq "0"], 
          [
            AC_MSG_RESULT([yes])
            GPU_ARCH="$GPU_ARCH $NEW"
          ], [
            AC_MSG_RESULT([no])
          ])
      ] )
    # Use JIT compilation of GPU code for forward compatibility
    GPU_ARCH="--generate-code arch=compute_20,code=compute_20 $GPU_ARCH"

    dnl check that nvcc know ptx instruction madc
    echo "__global__ void test (int *a, int b) { 
          asm(\"mad.lo.cc.u32 %0, %0, %1, %1;\": 
          \"+r\"(*a) : \"r\"(b));} " > conftest.cu
    AC_MSG_CHECKING([if nvcc know ptx instruction madc])
    $NVCC -c conftest.cu -o conftest.o $NVCCFLAGS --generate-code arch=compute_20,code=compute_20 > /dev/null 2>&1
    AS_IF([test "$?" -eq "0"], 
      [
        AC_MSG_RESULT([yes])
      ], [
        AC_MSG_RESULT([no])
        AC_MSG_ERROR([nvcc does not recognize ptx instruction madc, you should upgrade it])
      ])

    LIBS="$LIBS_BACKUP"
    LDFLAGS="$LDFLAGS_BACKUP"
    
    NVCCFLAGS="$NVCCFLAGS -DWITH_GPU $GPU_ARCH"
    CFLAGS="$CFLAGS -DWITH_GPU"
    CPPFLAGS="$CPPFLAGS -DWITH_GPU"

    NVCCFLAGS="$NVCCFLAGS --ptxas-options=-v"
    NVCCFLAGS="$NVCCFLAGS --compiler-options -fno-strict-aliasing"
    # If debug flag is set apply debugging compilation flags, 
    # otherwise build compilation flags
    AS_IF([test "x$DEBUG" = "xtrue"],
      [
        #NVCCFLAGS="$NVCCFLAGS -keep -keep-dir gputmp"
        NVCCFLAGS="$NVCCFLAGS -g"
      ],
      [
        NVCCFLAGS="$NVCCFLAGS -O2"
      ])

  ])
#Set this conditional if cuda is wanted
AM_CONDITIONAL([WANT_GPU], [test "x$enable_gpu" = "xyes" ])

AC_SUBST(NVCC)
AC_SUBST(NVCCFLAGS)
AC_SUBST(CUDALIB)
AC_SUBST(CUDALDFLAGS)
AC_SUBST(CUDARPATH)

])

dnl Checks whether the stack can be marked nonexecutable by passing an option
dnl to the C-compiler when acting on .s files. Appends that option to ASMFLAGS.
dnl This macro is adapted from one found in GMP 6.1.1.
dnl FIXME: This test looks broken. It tests that a file with .note.GNU-stack...
dnl can be compiled/assembled with -Wa,--noexecstack.  It does not determine
dnl if that command-line option has any effect on general asm code.
AC_DEFUN([CL_AS_NOEXECSTACK],[
dnl AC_REQUIRE([AC_PROG_CC]) GMP uses something else
AC_CACHE_CHECK([whether assembler supports --noexecstack option],
cl_cv_as_noexecstack, [dnl
  cat > conftest.c <<EOF
void foo() {}
EOF
  if AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS
                     -S -o conftest.s conftest.c >/dev/null]) \
     && grep .note.GNU-stack conftest.s >/dev/null \
     && AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS -Wa,--noexecstack
                       -c -o conftest.o conftest.s >/dev/null])
  then
    cl_cv_as_noexecstack=yes
  else
    cl_cv_as_noexecstack=no
  fi
  rm -f conftest*])
  if test "$cl_cv_as_noexecstack" = yes; then
    LIBECM_LDFLAGS="$LIBECM_LDFLAGS -Wl,-znoexecstack"
  fi
])