File: configure.ac

package info (click to toggle)
eztrace 1.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,848 kB
  • ctags: 4,054
  • sloc: ansic: 24,825; sh: 11,408; perl: 1,107; makefile: 872; f90: 295; python: 57; fortran: 38
file content (901 lines) | stat: -rw-r--r-- 24,637 bytes parent folder | download
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
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
# Copyright (C) CNRS, INRIA, Universite Bordeaux 1, Telecom SudParis
# See COPYING in top-level directory.
#
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.63])
AC_INIT([eztrace], [1.0.6], [eztrace-devel@lists.gforge.inria.fr])
AM_INIT_AUTOMAKE([1.10 tar-pax color-tests subdir-objects])

# Checks for programs.
AC_PROG_CC
AC_PROG_FC
AC_PROG_CXX
AC_LANG_CPLUSPLUS
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_LIBTOOL
AM_PROG_CC_C_O

AC_CONFIG_MACRO_DIR([m4])
F77=$(FC)
FFLAGS=$(FCFLAGS)

AC_PATH_PROG([MPICC], [mpicc])
AC_PATH_PROG(PERL,perl)
#AC_CHECK_PROG(PERL,perl,yes,missing -- the perl scripting language)

# crappy hack: of the macros AC_PROG_{CC,CXX,F77,FC}, only the
# first expanded one will check for object file extension etc,
# and fail if that doesn't work.
if test x$FC = x; then
AC_MSG_ERROR(A Fortran compiler is required)
fi

cxx_enable=yes
if test x$CXX = x; then
cxx_enable=no
fi


# Correct install paths
AS_IF([test x"$prefix" = x -o x"$prefix" = "xNONE"], [prefix="/usr/local"])
AS_IF([test x"$exec_prefix" = x -o x"$exec_prefix" = "xNONE"], [exec_prefix="\${prefix}"])
AS_IF([test "$docdir" = "\${datarootdir}/doc/\${PACKAGE_TARNAME}"],[docdir="\${datarootdir}/doc/eztrace"])
top_build_dir=`pwd`

# Checks for libraries.
AC_CHECK_LIB([dl], [dlsym])
AC_CHECK_LIB([m], [cos])
AC_CHECK_LIB([pthread], [pthread_create])
AC_CHECK_LIB([pthread], [pthread_spin_lock], have_full_pthread=yes, have_full_pthread=no)
AC_CHECK_LIB([z], [deflate])
AC_CHECK_LIB([iberty], [cplus_demangle])
LIBS="/usr/lib/libbfd.a -lz $LIBS"

# Check the OS type
os_type=`uname -s`

if [ test "x$os_type" = "xLinux" ]; then
# Linux
  AC_MSG_WARN([OS: Linux])
  CFLAGS="$CFLAGS -DHAVE_LINUX -Wno-unused-parameter -Wno-unused-value"
  DYNLIB_EXT=".so.0"
  LD_PRELOAD_NAME="LD_PRELOAD"
  LD_LIBRARY_PATH_NAME="LD_LIBRARY_PATH"
elif [ test "x$os_type" = "xDarwin" ]; then
# Mac OS
  AC_MSG_WARN([OS: Mac OS])
  CFLAGS="$CFLAGS -DHAVE_DARWIN"
  DYNLIB_EXT=".dylib"
  LD_PRELOAD_NAME="DYLD_INSERT_LIBRARIES"
  LD_LIBRARY_PATH_NAME="DYLD_LIBRARY_PATH"
else
# unknown OS, let's try Linux
  AC_MSG_WARN([unknown OS: falling back to Linux])
  CFLAGS="$CFLAGS -DHAVE_LINUX"
  DYNLIB_EXT=".so.0"
  LD_PRELOAD_NAME="LD_PRELOAD"
  LD_LIBRARY_PATH_NAME="LD_LIBRARY_PATH"
fi


# Check the architecture type
case "$host" in
	x86_64-*)
		AC_MSG_WARN([ARCH: X86_64])
		arch_str="X86_64"
		;;
	armv7|arm*-*gnueabihf)
		AC_MSG_WARN([ARCH: ARM])
		arch_str="ARM"
		CFLAGS="$CFLAGS -marm"
		;;
	*)
		AC_MSG_WARN([unknown architecture: falling back to x86_64])
		;;
esac


# Check for a library with a particular LDFLAGS
# this LDFLAGS is not set in the 'final' LDFLAGS
# This is usefull if only a small part of your program
# needs this library
#
# example:
#CHECK_LIB_LDFLAGS([gtg],
#		   [setTraceType],
#                  "$GTG_LDFLAGS",
#                   ,
#                   AC_MSG_ERROR([cannot find libgtg]))
AC_DEFUN([CHECK_LIB_LDFLAGS],
[save_LDFLAGS="$LDFLAGS"
save_LIBS="$LIBS"
LDFLAGS="$LDFLAGS $3"
AC_CHECK_LIB([$1], [$2], [$4], [$5])
LDFLAGS="$save_LDFLAGS"
LIBS="$save_LIBS"
])


# Check for a library with a particular LDFLAGS
# this LDFLAGS is not set in the 'final' LDFLAGS
# This is usefull if only a small part of your program
# needs this library
#
# example:
#CHECK_LIB_TRYLINK("$GTG_LDFLAGS",
#                  [#include "GTG.h"],
#		   [gtg_container_t c;],
#                  [enable_gtg=yes],
#                   AC_MSG_ERROR([cannot find libgtg]))
AC_DEFUN([CHECK_LIB_TRYLINK],
[save_LDFLAGS="$LDFLAGS"
save_LIBS="$LIBS"
LDFLAGS="$LDFLAGS $1"
AC_TRY_LINK([$2], [$3], [$4], [$5])
LDFLAGS="$save_LDFLAGS"
LIBS="$save_LIBS"
])


# Check for a header with a particular CPPFLAGS
# this CPPFLAGS is not set in the 'final' CPPFLAGS
# This is usefull if only a small part of your program
# needs this header
#
# example:
# CHECK_HEADER_CPPFLAGS([GTGBasic1.h],
#                       ,
#                       "$GTG_CPPFLAGS",
#                        AC_MSG_ERROR([cannot find headers for gtg]))
AC_DEFUN([CHECK_HEADER_CPPFLAGS],
[save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $3"
AC_CHECK_HEADERS([$1], [$2], [$4], [$5])
CPPFLAGS="$save_CPPFLAGS"
])


# Checks for programs
AC_CHECK_PROG(HAVE_ENV, [env], yes, no)

if test x$HAVE_ENV = xno ; then
   AC_MSG_ERROR([Cannot find env])
fi

# Checks for header files.

# this is needed because demangle.h and string.h have confliting versions of the basename function
AC_CHECK_DECLS([basename], [], [], [[#include <libgen.h>]])

AC_CHECK_HEADERS([fcntl.h limits.h malloc.h stdint.h stdlib.h string.h sys/time.h unistd.h sys/syscall.h])
have_demangle=yes
AC_CHECK_HEADER([demangle.h], , have_demangle=no)
AC_CHECK_LIB([iberty], [cplus_demangle], , have_demangle=no)
AM_CONDITIONAL([HAVE_DEMANGLE], [test "x$have_demangle" = xyes])
LIBS="/usr/lib/libbfd.a -lz $LIBS"

# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
AC_TYPE_UINT64_T

# Checks for library functions.
AC_FUNC_MALLOC
AC_CHECK_FUNCS([atexit])

build_doc=no
AC_ARG_WITH(doc, [AS_HELP_STRING([--with-doc], [Generate documentation])],
                 [if test x$withval != xno ; then
                    build_doc=yes
                 fi],
                 [ build_doc=no ])

if test "x$build_doc" = "xyes" ; then
  AC_MSG_RESULT(Documentation will be generated)
else
  AC_MSG_RESULT(Documentation will not be generated)
fi


# pptrace stuff
use_pptrace=yes

pptrace_lib_found=yes#no
pptrace_binary_type=1
LIBS="/usr/lib/libbfd.a -lz $LIBS"
# check if the arch/OS is supported by pptrace
    if [ test "x$arch_str" = "xX86_64" ] || [ test "x$arch_str" = "xARM" ] ; then
	if [ test "x$os_type" = "xLinux" ]; then
	   use_pptrace=yes
	else
	    use_pptrace=no
	    AC_MSG_WARN([The target OS is not supported by pptrace. The instrumentation will be limited to shared libraries])
	fi
    else
	AC_MSG_WARN([The target architecture is not supported by pptrace. The instrumentation will be limited to shared libraries])
	use_pptrace=no
    fi


LIBS="/usr/lib/libopcodes.a $LIBS"

AM_CONDITIONAL([HAVE_LIBOPCODE], [test "$libopcode_found" = yes])
AM_CONDITIONAL([USE_PPTRACE], [test "$use_pptrace" = yes])
AC_SUBST(PPTRACE_BINARY_TYPE, 1)

AC_CHECK_HEADER([sys/prctl.h],
		[
		AC_CHECK_FUNC(prctl,
			      [have_prctl_h=1],
			      [have_prctl_h=0])
		],
		[have_prctl_h=0])
AC_SUBST(HAVE_PRCTL_H, [$have_prctl_h])

# -m32 & -m64 flags for tests
AC_MSG_CHECKING([whether $CC supports -m32 and -m64])
_save_cflags="$CFLAGS"
_save_ldflags="$LDFLAGS"
CFLAGS="$CFLAGS -m32"
LDFLAGS="$LDFLAGS -m32"
AC_LINK_IFELSE([AC_LANG_SOURCE([#include <stdio.h>
	int main(void) { printf("Hello, World!\n"); return 0;}])],
	[m32_flag=yes], [m32_flag=no]);
CFLAGS="$_save_cflags -m64"
LDFLAGS="$_save_ldflags -m64"
AC_LINK_IFELSE([AC_LANG_SOURCE([#include <stdio.h>
	int main(void) { printf("Hello, World!\n"); return 0;}])],
	[m64_flag=yes], [m64_flag=no]);
CFLAGS="$_save_cflags"
LDFLAGS="$_save_ldflags"
if test "x$m64_flag" = "xyes"; then
	if test "x$m32_flag" = "xyes"; then
		available_target_bits="32 64"
		supported_mXX_flags="-m32 -m64"
	else
		available_target_bits="64"
		supported_mXX_flags="-m64"
	fi
else if test "x$m32_flag" = "xyes"; then
		available_target_bits="32"
		supported_mXX_flags="-m32"
	else
		available_target_bits=""
		supported_mXX_flags=""
	fi
fi
AC_MSG_RESULT([supports $supported_mXX_flags])
AC_SUBST(TARGET_BITS, $available_target_bits)

use_litl=yes
use_extern_litl=no
LITL_PRINT=${top_build_dir}/extlib/litl/utils/litl_print

AC_ARG_WITH(litl, [AS_HELP_STRING([--with-litl[=<ARG> or =<DIR>]], [generate LiTL traces [ARG=yes]])],
    [
	if test x$withval != xno; then
	    use_litl=yes
	    if test x$withval = xyes; then
		AC_MSG_RESULT(yes)
	    else
		# use specified path
		use_extern_litl=yes
		litldir=$withval
		AC_MSG_RESULT(yes using $litldir)
		AC_SUBST(LITL_ROOT, $litldir)
		LITL_PRINT=$litldir/bin/litl_print
	    fi
	else
	    use_litl=no
	    AC_MSG_ERROR("LiTL is required for eztrace")
	fi
    ])

# --> LiTL
if test x$use_extern_litl = xyes; then
# use an external installation of LiTL
    extern_litl_found=yes
    use_intern_litl=no
    use_extern_litl=yes
    TL_CPPFLAGS="${TL_CPPFLAGS} -I${litldir}/include"
    TL_LDFLAGS="${TL_LDFLAGS} -L${litldir}/lib"
    TL_LIB="-llitl"

    if test "$litldir" != /usr
    then
	TL_LDFLAGS="$TL_LDFLAGS -Wl,-rpath,${litldir}/lib"
    fi

    TL_EXT_CPPFLAGS="$TL_CPPFLAGS"
    TL_EXT_LDFLAGS="$TL_LDFLAGS"
    TL_EXT_LIB="$TL_LIB"
else
# use the LiTL version shipped with eztrace
    extern_litl_found=no
    use_intern_litl=yes
    use_extern_litl=no
    dnl configure litl from extlib
    litl_parent_dir=`pwd`
    litl_dir="extlib/litl"
    AC_MSG_NOTICE([configuring in litl_dir ($litl_parent_dir/$litl_dir)])
    AS_IF([test "$srcdir" != "."],
	[
	    test -d "$litl_dir" ||
	    mkdir -p "$litl_dir" ||
	    AC_MSG_ERROR([cannot create $litl_dir])
	])

    case $srcdir in
	.)
	    litl_srcdir="$srcdir"
	    ;;
	/*)
	    litl_srcdir="$srcdir/$litl_dir"
	    ;;
	*)
	    litl_srcdir="../../$srcdir/$litl_dir"
	    ;;
    esac

    litl_conf_cmd="$litl_srcdir/configure"
    litl_conf_args="$litl_conf_args --prefix=\"$prefix\" --exec-prefix=\"$exec_prefix\" --bindir=\"$bindir\" --libdir=\"$libdir\" --includedir=\"$includedir\" --docdir=\"$docdir/litl\" $TLFLAGS --cache-file=\"/dev/null\" --srcdir=\"$litl_srcdir\""
    if test "x$build_doc" = "xyes" ; then
        litl_conf_args="$litl_conf_args --with-doc=\"$build_doc\""
    fi

    AC_MSG_NOTICE([running $SHELL $litl_conf_cmd $litl_conf_args])

    cd $litl_dir
    eval "$SHELL '$litl_conf_cmd' $litl_conf_args"
    AS_IF([test $? != "0"], [AC_MSG_ERROR([$litl_conf_cmd failed for $litl_dir])])
    cd $litl_parent_dir

    AS_IF([test x"$TLLIB" = x], [TLLIB="-llitl"])

    TL_CPPFLAGS="$TL_CPPFLAGS -I${prefix}/include/litl -I${top_build_dir}/${srcdir}/extlib/litl/src -I${top_build_dir}/extlib/litl/src"
	TL_LDFLAGS="${top_build_dir}/extlib/litl/src/liblitl.la"
	TL_LIB=""

	TL_EXT_CPPFLAGS="-I${prefix}/include/"
	TL_EXT_LDFLAGS="-L${prefix}/lib/"
	TL_EXT_LIB="-llitl"
fi
#TL_LIB="-llitl"

if test x$extern_litl_found = xyes ; then
    CPPFLAGS="${CPPFLAGS} ${TL_CPPFLAGS}"
    LDFLAGS="${LDFLAGS} ${TL_LDFLAGS}"
    AC_CHECK_HEADER([litl_types.h],,AC_MSG_ERROR([cannot find headers for LiTL]))
    AC_CHECK_HEADER([litl_write.h],,AC_MSG_ERROR([cannot find headers for LiTL]))
    AC_CHECK_HEADER([litl_read.h],,AC_MSG_ERROR([cannot find headers for LiTL]))
fi
# <-- LiTL

L_CPPFLAGS="${TL_CPPFLAGS} -DUSE_LITL -DRECORD_PACKED_EVENTS"
L_EXT_CPPFLAGS="${TL_EXT_CPPFLAGS} -DUSE_LITL -DRECORD_PACKED_EVENTS"

# by default tid recording is enabled LiTL
TID_RECORDING_ENABLED=yes
if test "x$TID_RECORDING_ENABLED" = xyes ; then
    CFLAGS="$CFLAGS -DTID_RECORDING_ENABLED"
    TL_CPPFLAGS="${TL_CPPFLAGS} -DTID_RECORDING_ENABLED"
    TL_EXT_CPPFLAGS="${TL_EXT_CPPFLAGS} -DTID_RECORDING_ENABLED"
fi


# check for openmp
CHECK_HEADER_CPPFLAGS([omp.h], [openmp_found=yes], "-fopenmp", AC_MSG_WARN([cannot find omp.h]))


use_papi=yes
AC_ARG_WITH(papi, [AS_HELP_STRING([--with-papi[=<dir>]], [PAPI])],
	[
		if test x$withval != xno; then
			use_papi=yes
			if test x$withval = xyes; then
				AC_MSG_RESULT(yes)
				use_papi_from_system=yes
			else
				# use specified path
				use_papi_from_system=no
				papidir=$withval
				AC_MSG_RESULT(yes using $papidir)
				AC_SUBST(PAPIDIR, $papidir)
			fi
		else
			use_papi=no
			AC_MSG_RESULT(no)
		fi
	])

AC_SUBST(USE_PAPIDIR_FROM_USER,$use_papi_from_system)
if test x$use_papi_from_system = xno; then
   PAPI_LIBDIR=$papidir/lib
   PAPI_CPPFLAGS="-I$papidir/include/"
   PAPI_LDFLAGS="-L${PAPI_LIBDIR}"
   if test "$papidir" != /usr
   then
	PAPI_LDFLAGS="$PAPI_LDFLAGS  -Wl,-rpath,${PAPI_LIBDIR}"
   fi
elif test x$use_papi = xyes ; then
     if test -d "/usr/include/papi" ; then
	PAPI_CPPFLAGS="-I/usr/include/papi/"
     fi

     if test -d "/usr/lib/PAPI" ; then
	PAPI_LIBDIR=/usr/lib/papi
	PAPI_LDFLAGS="-L/usr/lib/papi"
     fi
fi

enable_papi=no

if test x$use_papi = xyes ; then
   save_CPPFLAGS="$CPPFLAGS"
   CPPFLAGS="$CPPFLAGS $PAPI_CPPFLAGS"
   CHECK_LIB_TRYLINK([$PAPI_LDFLAGS -lpapi],
	       [#include <papi.h>],
	       [PAPI_event_info_t plop;],
	       [enable_papi=yes],
	       AC_MSG_WARN([cannot find PAPI lib]))
   CPPFLAGS="$save_CPPFLAGS"

   if test x$enable_papi = xyes; then
      enable_papi=no
      CHECK_HEADER_CPPFLAGS([papi.h], [enable_papi=yes], "$PAPI_CPPFLAGS", AC_MSG_WARN([cannot find headers for PAPI]))
   fi

   if test x$enable_papi = xyes; then
      CFLAGS="$CFLAGS -DUSE_PAPI"
   fi

fi


# MPI stuff
MPI_ROOT=
MPI_INC=
use_mpi=yes
use_mpi3=no
use_mpi_from_system=yes
AC_ARG_WITH(mpi, [AS_HELP_STRING([--with-mpi[=<dir>]], [Use a specific MPI installation])],
	[
		if test x$withval != xno; then
			if test x$withval = xyes; then
				AC_MSG_RESULT(yes)
				use_mpi_from_system=yes
			else
				# use specified path
				use_mpi_from_system=no
				mpidir=$withval
				AC_MSG_RESULT(Using MPI installation: $mpidir)
				MPI_ROOT=$mpidir
				AC_SUBST(MPI_ROOT, $mpidir)
			fi
		else
			# either --without-mpi or --with-mpi=no is set
			use_mpi=no
		fi
	])

AC_ARG_WITH(mpi-include, [AS_HELP_STRING([--with-mpi-include[=<dir>]], [Use a specific MPI header])],
	[
		if test x$withval != xno; then
			if test x$withval = xyes; then
				AC_MSG_RESULT(yes)
				use_mpi_from_system=yes
			else
				# use specified path
				use_mpi_from_system=no
				mpidir=$withval
				AC_MSG_RESULT(MPI include directory: $mpidir)
				MPI_INC=$mpidir
				AC_SUBST(MPI_INC, $mpidir)
			fi
		fi
	])


if test x$MPI_INC != x; then
# use the value supplied by --with-mpi-include
	CPPFLAGS="${CPPFLAGS} -I$MPI_INC/"
	FCFLAGS="${FCFLAGS} -I$MPI_INC/"
elif test x$MPI_ROOT != x; then
# use the value supplied by --with-mpi
	CPPFLAGS="${CPPFLAGS} -I$MPI_ROOT/include/ "
	FCFLAGS="${FCFLAGS} -I$MPI_ROOT/include/ "
fi



mpi_ldflags=
AC_ARG_WITH(mpi-ldflags, [AS_HELP_STRING([--with-mpi-ldflags[=<ldflags>]], [Use a specific LDFLAGS when compiling MPI files])],
	[if test "x$withval" != "xno"; then
		# use specified path
		mpi_ldflags=$withval
		AC_MSG_RESULT(MPI LDFLAGS: $mpi_ldflags)
		AC_SUBST(MPI_LDFLAGS, mpi_ldflags)
	fi])

MPI_LDFLAGS="-lmpi"
if test "x$mpi_ldflags" != "x"; then
# use the value supplied by --with-mpi-include
  MPI_LDFLAGS="$mpi_ldflags"
elif test x$MPI_ROOT != x; then
# use the value supplied by --with-mpi
  MPI_LDFLAGS="-L$MPI_ROOT/lib -lmpi"
  if test "$MPI_ROOT" != /usr
  then
	MPI_LDFLAGS="$MPI_LDFLAGS -Wl,-rpath,${MPI_ROOT}/lib"
  fi
fi

if test $use_mpi = yes ; then
   AC_SUBST(USE_MPIDIR_FROM_USER,$use_mpi_from_system)
   # MPI header
   AC_CHECK_HEADER([mpi.h],[enable_mpi=yes],AC_MSG_WARN([cannot find headers for MPI]))

   if test $enable_mpi = yes ; then
      AC_CHECK_DECLS(MPI_Ibarrier, [use_mpi3=yes], [use_mpi3=no], [[#include <mpi.h>]])
   fi
else
  enable_mpi=no
fi

mpi_module_name=mpi
AC_ARG_WITH(mpi-module-name, [AS_HELP_STRING([--with-mpi-module-name=<dir>], [Change the name of the MPI module])],
	[
		if test x$withval != x; then
		    mpi_module_name=$withval
		    AC_MSG_RESULT([Changing the name of the MPI module to $mpi_module_name])
		else
		    # either --without-mpi or --with-mpi=no is set
		    AC_MSG_RESULT([Please provide a name to the --with-mpi-module-name option])
		fi
	])

mpi_event_id=4
AC_ARG_WITH(mpi-event-id, [AS_HELP_STRING([--with-mpi-event-id=id>], [Change the ID of the MPI events])],
	[
		if test x$withval != x; then
		    mpi_event_id=$withval
		    AC_MSG_RESULT([Changing the ID of MPI events $mpi_event_id])
		else
		    # either --without-mpi or --with-mpi=no is set
		    AC_MSG_RESULT([Please provide an ID to the --with-mpi-event-id option])
		fi
	])

AC_SUBST(MPI_LDFLAGS, $MPI_LDFLAGS)
AC_SUBST(MPI_MODULE_NAME, $mpi_module_name)
AC_SUBST(MPI_EVENT_ID, $mpi_event_id)


# GTG stuff
use_extern_gtg=no
AC_ARG_WITH(gtg, [AS_HELP_STRING([--with-gtg[=<dir>]], [path to libgtg])],
	[
		if test x$withval != xno; then
			if test x$withval = xyes; then
				AC_MSG_RESULT(yes)
			else
				# use specified path
				use_extern_gtg=yes
				gtgdir=$withval
				AC_MSG_RESULT(yes using gtgdir)
				AC_SUBST(GTGDIR, $gtgdir)
			fi
		else
			AC_MSG_RESULT(no)
			AC_MSG_ERROR([Cannot find GTG])
		fi
	])


if test x$use_extern_gtg = xyes; then
    GTG_CPPFLAGS="${CPPFLAGS} -I$gtgdir/include/"
    GTG_LDFLAGS="${LDFLAGS} -L$gtgdir/lib/"
    if test "$gtgdir" != /usr
    then
	GTG_LDFLAGS="$GTG_LDFLAGS -Wl,-rpath,${gtgdir}/lib"
    fi
    GTG_DEPENDENCIES=""
    GTG_LIB="-lgtg"

    GTG_EXT_CPPFLAGS="${GTG_CPPFLAGS}"
    GTG_EXT_LDFLAGS="$GTGLDFLAGS"
    GTG_EXT_LIB="-lgtg"

    CHECK_LIB_LDFLAGS([gtg], [setTraceType],"$GTG_LDFLAGS", , AC_MSG_ERROR([cannot find libgtg]))
    CHECK_LIB_LDFLAGS([gtg], [gtg_record],"$GTG_LDFLAGS", GTG_OUT_OF_ORDER=1, GTG_OUT_OF_ORDER=0)
    CHECK_HEADER_CPPFLAGS([GTG.h],, "$GTG_CPPFLAGS", AC_MSG_ERROR([cannot find headers for gtg]))
else

    GTG_OUT_OF_ORDER=1
    dnl configure gtg from extlib
    gtg_parent_dir=`pwd`
    gtg_dir="extlib/gtg"
    AC_MSG_NOTICE([configuring in gtg_dir ($gtg_parent_dir/$gtg_dir)])
    AS_IF([test "$srcdir" != "."],
		[
			test -d "$gtg_dir" ||
			mkdir -p "$gtg_dir" ||
			AC_MSG_ERROR([cannot create $gtg_dir])
		])

		case $srcdir in
			.)
				gtg_srcdir="$srcdir"
				;;
			/*)
				gtg_srcdir="$srcdir/$gtg_dir"
				;;
			*)
				gtg_srcdir="../../$srcdir/$gtg_dir"
				;;
		esac

		gtg_conf_cmd="$gtg_srcdir/configure"
		gtg_conf_args="$gtg_conf_args --prefix=\"$prefix\" --exec-prefix=\"$exec_prefix\" --bindir=\"$bindir\" --libdir=\"$libdir\" --includedir=\"$includedir\" --docdir=\"$docdir/gtg\" $GTGFLAGS --cache-file=\"/dev/null\" --srcdir=\"$gtg_srcdir\" --with-mpi=no"
		if test "x$build_doc" = "xyes" ; then
    		    gtg_conf_args="$gtg_conf_args --with-doc=\"$build_doc\""
    		fi

		AC_MSG_NOTICE([running $SHELL $gtg_conf_cmd $gtg_conf_args])
		cd $gtg_dir
		eval "$SHELL '$gtg_conf_cmd' $gtg_conf_args"
		AS_IF([test $? != "0"], [AC_MSG_ERROR([$gtg_conf_cmd failed for $gtg_dir])])
		cd $gtg_parent_dir

		GTG_CPPFLAGS="$GTG_CPPFLAGS -I${top_build_dir}/${srcdir}/${gtg_dir}/inc"
		GTG_LDFLAGS="${top_build_dir}/${gtg_dir}/src/libgtg.la"
		GTG_DEPENDENCIES="$GTG_LDFLAGS"
		GTG_LIB=""

		GTG_EXT_CPPFLAGS="-I${prefix}/include"
		GTG_EXT_LDFLAGS="-L${prefix}/lib"
		GTG_EXT_LIB="-lgtg"
fi

if [ test "$GTG_OUT_OF_ORDER" = "1" ] ; then
  GTG_CPPFLAGS="${GTG_CPPFLAGS} -DGTG_OUT_OF_ORDER"
  GTG_EXT_CPPFLAGS="${GTG_EXT_CPPFLAGS} -DGTG_OUT_OF_ORDER"
fi


# Check for presence of pdfLaTeX
AC_CHECK_PROG(PDFLATEX, pdflatex, pdflatex)
if test -z "$PDFLATEX"; then
  AC_MSG_WARN([Unable to create PDF version of the user manual -- pdflatex is missing!])
fi
AM_CONDITIONAL([HAVE_PDFLATEX], test -n "$PDFLATEX")

# Check for presence of latexmk
AC_CHECK_PROG(LATEXMK, latexmk, latexmk)
if test -z "$LATEXMK"; then
  AC_MSG_WARN([Unable to create PDF version of the user manual -- latemk is missing!])
fi
AM_CONDITIONAL([HAVE_LATEXMK], test -n "$LATEXMK")


# CUDA stuff
CUDA_ROOT=/usr/local/cuda
use_cuda=yes
use_cuda_from_system=yes

AC_ARG_WITH(cuda, [AS_HELP_STRING([--with-cuda[=<dir>]], [Use a specific CUDA installation])],
	[
		if test x$withval != xno; then
			if test x$withval = xyes; then
				AC_MSG_RESULT(yes)
				use_cuda_from_system=yes
			else
				# use specified path
				use_cuda_from_system=no
				cudadir=$withval
				AC_MSG_RESULT(yes using $cudadir)
				CUDA_ROOT=$cudadir
				AC_SUBST(CUDA_ROOT, $cudadir)
			fi
		else
			# either --without-cuda or --with-cuda=no is set
			use_cuda=no
		fi
	])

CUPTI_ROOT="${CUDA_ROOT}/extras/CUPTI"
AC_ARG_WITH(cupti, [AS_HELP_STRING([--with-cupti=<dir>], [Use a specific CUPTI installation])],
	[ CUPTI_ROOT=$withval ])

enable_cuda=yes
if test $use_cuda = yes ; then

  CUDA_INC=${CUDA_ROOT}/include
  CUDA_CFLAGS="-I${CUDA_INC}"
  CUDA_LIBS="-lcudart"
  CUDA_LDFLAGS="-L${CUDA_ROOT}/lib"

  CUPTI_INC=${CUPTI_ROOT}/include
  CUPTI_CFLAGS="-I${CUPTI_INC}"
  CUPTI_LIBS="-lcupti"
  CUPTI_LDFLAGS="-L${CUPTI_ROOT}/lib"

# 64-bits systems
  CUDA_LDFLAGS="${CUDA_LDFLAGS} -L${CUDA_ROOT}/lib64"
  CUPTI_LDFLAGS="${CUPTI_LDFLAGS} -L${CUPTI_ROOT}/lib64 ${CUDA_LDFLAGS}"

  if test "$CUDA_ROOT" != /usr
  then
	CUDA_LDFLAGS="$CUDA_LDFLAGS -Wl,-rpath,${CUDA_ROOT}/lib -Wl,-rpath,${CUDA_ROOT}/lib64"
  fi

  if test "$CUPTI_ROOT" != /usr
  then
	CUPTI_LDFLAGS="$CUPTI_LDFLAGS -Wl,-rpath,${CUPTI_ROOT}/lib -Wl,-rpath,${CUPTI_ROOT}/lib64"
  fi

  NVCC="${CUDA_ROOT}/bin/nvcc"

  AC_SUBST(USE_CUDADIR_FROM_USER,$use_cuda_from_system)
  # CUDA compiler
  AC_MSG_CHECKING([for CUDA compiler in $CUDA_ROOT/bin])
  if test -x "${NVCC}" ; then
     AC_MSG_RESULT([yes])
  else
     AC_MSG_RESULT([nvcc not found])
     enable_cuda=no
  fi
fi

if test $enable_cuda = yes ; then
  # CUDA header
  AC_MSG_CHECKING([for CUDA header in $CUDA_INC])
  if test -f "${CUDA_INC}/cuda.h" ; then
     AC_MSG_RESULT([yes])
  else
     AC_MSG_RESULT([cuda.h not found])
     enable_cuda=no
  fi
fi

if test $enable_cuda = yes ; then
  AC_MSG_CHECKING([for CUPTI header in $CUPTI_INC])
  if test -f "${CUPTI_INC}/cupti.h" ; then
     AC_MSG_RESULT([yes])
  else
     AC_MSG_RESULT([cupti.h not found])
     enable_cuda=no
  fi

fi

if test $enable_cuda = yes ; then
  CHECK_LIB_LDFLAGS([cudart], [cudaMalloc], "$CUDA_LDFLAGS", , AC_MSG_ERROR([cannot find libcudart]))
  CHECK_LIB_LDFLAGS([cupti], [cuptiSubscribe], "$CUPTI_LDFLAGS", , AC_MSG_ERROR([cannot find libcupti]))
else
  use_cuda=no
  enable_cuda=no
fi

if test x$enable_cuda != xyes ; then
  CUDA_INC=
  CUDA_CFLAGS=
  CUDA_LDFLAGS=
  CUDA_LIBS=

  CUPTI_INC=
  CUPTI_CFLAGS=
  CUPTI_LDFLAGS=
  CUPTI_LIBS=

  NVCC=
  NVCCFLAGS=
fi

AC_SUBST(CUDA_CFLAGS)
AC_SUBST(CUDA_LDFLAGS)
AC_SUBST(CUDA_LIBS)
AC_SUBST(CUPTI_CFLAGS)
AC_SUBST(CUPTI_LDFLAGS)
AC_SUBST(CUPTI_LIBS)
AC_SUBST(NVCC)
AC_SUBST(NVCCFLAGS)


AC_ARG_ENABLE([gettid],
	AC_HELP_STRING([--enable-gettid],
		[Use syscall(SYS_gettid) to get the thread ID instead of pthread_self(). This however costs a system call for each trace entry]))
if test "x$enable_gettid" = xyes; then
    AC_DEFINE([USE_GETTID], [1], [Use gettid])
fi

AC_SUBST(libdir)
AC_SUBST(exec_prefix)
AC_SUBST(prefix)
AC_SUBST(includedir)
AC_SUBST(bindir)
AC_SUBST(datadir)

AC_SUBST(FCFLAGS)

# cppflags for compiling eztrace
AC_SUBST(TL_CPPFLAGS)
AC_SUBST(TL_LDFLAGS)
AC_SUBST(TL_LIB)

# cppflags for compiling an application that uses eztrace
AC_SUBST(TL_EXT_CPPFLAGS)
AC_SUBST(TL_EXT_LDFLAGS)
AC_SUBST(TL_EXT_LIB)

# cppflags for compiling eztrace
AC_SUBST(GTG_CPPFLAGS)
AC_SUBST(GTG_LDFLAGS)
AC_SUBST(GTG_LIB)
AC_SUBST(GTG_DEPENDENCIES)

# cppflags for compiling an application that uses eztrace
AC_SUBST(GTG_EXT_CPPFLAGS)
AC_SUBST(GTG_EXT_LDFLAGS)
AC_SUBST(GTG_EXT_LIB)

AC_SUBST(GTG_OUT_OF_ORDER)
AM_CONDITIONAL([GTG_OUT_OF_ORDER], [test "$GTG_OUT_OF_ORDER" = "1"] )

AM_CONDITIONAL([OPENMP_FOUND], [test "x$openmp_found" = xyes])

AC_SUBST(LITL_PRINT)

AC_SUBST(PAPI_CPPFLAGS)
AC_SUBST(PAPI_LDFLAGS)
AC_SUBST(PAPI_LIBDIR)

PAPI_ENABLED="$enable_api"
AC_SUBST(PAPI_ENABLED)
AM_CONDITIONAL([USE_PAPI], [test "$enable_papi" = yes])

AC_SUBST(DYNLIB_EXT)
AC_SUBST(LD_PRELOAD_NAME)
AC_SUBST(LD_LIBRARY_PATH_NAME)
AM_CONDITIONAL([USE_CUDA], [test "$enable_cuda" = yes])
AM_CONDITIONAL([USE_MPI], [test "$enable_mpi" = yes])
AM_CONDITIONAL([USE_MPI3], [test "$use_mpi3" = yes])
AM_CONDITIONAL([USE_PTHREAD], [test "$have_full_pthread" = yes])

AM_CONDITIONAL([USE_LITL], [test "x$use_litl" = xyes])
AM_CONDITIONAL([AMEXTERNLITL], [test "x$use_extern_litl" = xyes])
AM_CONDITIONAL([AMEXTERNGTG], [test "x$use_extern_gtg" = xyes])

AM_CONDITIONAL([X86_64], [test "x$arch_str" = "xX86_64"])
AM_CONDITIONAL([ARM], [test "x$arch_str" = "xARM"])

AM_CONDITIONAL([WITHDOC], [test "$build_doc" = "yes"])

AC_OUTPUT([Makefile eztrace.pc \
		    src/core/Makefile \
		    src/modules/omp/Makefile \
		    src/modules/mpi/Makefile \
		    src/modules/cuda/Makefile \
		    src/modules/pthread/Makefile \
		    src/modules/stdio/Makefile \
		    src/modules/memory/Makefile \
		    src/modules/papi/Makefile \
		    src/core/eztrace_create_plugin \
		    src/core/eztrace_plugin_generator \
		    src/core/input/Makefile.template \
		    src/modules/omp/eztrace_cc \
		    test/mpi/Makefile \
		    test/openmp/Makefile \
		    src/core/eztrace.c \
		    src/core/eztrace.preload \
		    src/core/config.h \
		    test/static/Makefile \
		    test/stdio/Makefile \
		    test/memory/Makefile \
		    test/pthread/Makefile \
		    test/automake/Makefile \
		    test/automake/testcommon.h \
		    test/pptrace/automatic/Makefile \
		    doc/Makefile])