~vanvugt/ubuntu/oneiric/mediatomb/fix-770964-784431

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
# ====================================================================
# ACX_PTHREAD
# ====================================================================
#
# This script has been downloaded from
# http://autoconf-archive.cryp.to/acx_pthread.html
#
# Copyright © 2006 Steven G. Johnson <stevenj@alum.mit.edu>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA.
#
# As a special exception, the respective Autoconf Macro's copyright
# owner gives unlimited permission to copy, distribute and modify the
# configure scripts that are the output of Autoconf when processing the
# Macro. You need not follow the terms of the GNU General Public
# License when using or distributing such scripts, even though portions
# of the text of the Macro appear in them. The GNU General Public
# License (GPL) does govern all other use of the material that
# constitutes the Autoconf Macro.
#
# This special exception to the GPL applies to versions of the
# Autoconf Macro released by the Autoconf Macro Archive. When you make
# and distribute a modified version of the Autoconf Macro, you may
# extend this special exception to the GPL to apply to your modified
# version as well.

AC_DEFUN([ACX_PTHREAD], [
AC_REQUIRE([AC_CANONICAL_HOST])
AC_LANG_SAVE
AC_LANG_C
acx_pthread_ok=no

# We used to check for pthread.h first, but this fails if pthread.h
# requires special compiler flags (e.g. on True64 or Sequent).
# It gets checked for in the link test anyway.

# First of all, check if the user has set any of the PTHREAD_LIBS,
# etcetera environment variables, and if threads linking works using
# them:
if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
        save_CFLAGS="$CFLAGS"
        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
        save_LIBS="$LIBS"
        LIBS="$PTHREAD_LIBS $LIBS"
        AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
        AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
        AC_MSG_RESULT($acx_pthread_ok)
        if test x"$acx_pthread_ok" = xno; then
                PTHREAD_LIBS=""
                PTHREAD_CFLAGS=""
        fi
        LIBS="$save_LIBS"
        CFLAGS="$save_CFLAGS"
fi

# We must check for the threads library under a number of different
# names; the ordering is very important because some systems
# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
# libraries is broken (non-POSIX).

# Create a list of thread flags to try.  Items starting with a "-" are
# C compiler flags, and other items are library names, except for "none"
# which indicates that we try without any flags at all, and "pthread-config"
# which is a program returning the flags for the Pth emulation library.

acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"

# The ordering *is* (sometimes) important.  Some notes on the
# individual items follow:

# pthreads: AIX (must check this before -lpthread)
# none: in case threads are in libc; should be tried before -Kthread and
#       other compiler flags to prevent continual compiler warnings
# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
# -pthreads: Solaris/gcc
# -mthreads: Mingw32/gcc, Lynx/gcc
# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
#      doesn't hurt to check since this sometimes defines pthreads too;
#      also defines -D_REENTRANT)
#      ... -mt is also the pthreads flag for HP/aCC
# pthread: Linux, etcetera
# --thread-safe: KAI C++
# pthread-config: use pthread-config program (for GNU Pth library)

case "${host_cpu}-${host_os}" in
        *solaris*)

        # On Solaris (at least, for some versions), libc contains stubbed
        # (non-functional) versions of the pthreads routines, so link-based
        # tests will erroneously succeed.  (We need to link with -pthreads/-mt/
        # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
        # a function called by this macro, so we could check for that, but
        # who knows whether they'll stub that too in a future libc.)  So,
        # we'll just look for -pthreads and -lpthread first:

        acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
        ;;
esac

if test x"$acx_pthread_ok" = xno; then
for flag in $acx_pthread_flags; do

        case $flag in
                none)
                AC_MSG_CHECKING([whether pthreads work without any flags])
                ;;

                -*)
                AC_MSG_CHECKING([whether pthreads work with $flag])
                PTHREAD_CFLAGS="$flag"
                ;;

                pthread-config)
                AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
                if test x"$acx_pthread_config" = xno; then continue; fi
                PTHREAD_CFLAGS="`pthread-config --cflags`"
                PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
                ;;

                *)
                AC_MSG_CHECKING([for the pthreads library -l$flag])
                PTHREAD_LIBS="-l$flag"
                ;;
        esac

        save_LIBS="$LIBS"
        save_CFLAGS="$CFLAGS"
        LIBS="$PTHREAD_LIBS $LIBS"
        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"

        # Check for various functions.  We must include pthread.h,
        # since some functions may be macros.  (On the Sequent, we
        # need a special flag -Kthread to make this header compile.)
        # We check for pthread_join because it is in -lpthread on IRIX
        # while pthread_create is in libc.  We check for pthread_attr_init
        # due to DEC craziness with -lpthreads.  We check for
        # pthread_cleanup_push because it is one of the few pthread
        # functions on Solaris that doesn't have a non-functional libc stub.
        # We try pthread_create on general principles.
        AC_TRY_LINK([#include <pthread.h>],
                    [pthread_t th; pthread_join(th, 0);
                     pthread_attr_init(0); pthread_cleanup_push(0, 0);
                     pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
                    [acx_pthread_ok=yes])

        LIBS="$save_LIBS"
        CFLAGS="$save_CFLAGS"

        AC_MSG_RESULT($acx_pthread_ok)
        if test "x$acx_pthread_ok" = xyes; then
                break;
        fi

        PTHREAD_LIBS=""
        PTHREAD_CFLAGS=""
done
fi

# Various other checks:
if test "x$acx_pthread_ok" = xyes; then
        save_LIBS="$LIBS"
        LIBS="$PTHREAD_LIBS $LIBS"
        save_CFLAGS="$CFLAGS"
        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"

        # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
        AC_MSG_CHECKING([for joinable pthread attribute])
        attr_name=unknown
        for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
            AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
                        [attr_name=$attr; break])
        done
        AC_MSG_RESULT($attr_name)
        if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
            AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
                               [Define to necessary symbol if this constant
                                uses a non-standard name on your system.])
        fi

        AC_MSG_CHECKING([if more special flags are required for pthreads])
        flag=no
        case "${host_cpu}-${host_os}" in
            *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
            *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
        esac
        AC_MSG_RESULT(${flag})
        if test "x$flag" != xno; then
            PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
        fi

        LIBS="$save_LIBS"
        CFLAGS="$save_CFLAGS"

        # More AIX lossage: must compile with xlc_r or cc_r
        if test x"$GCC" != xyes; then
          AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
        else
          PTHREAD_CC=$CC
        fi
else
        PTHREAD_CC="$CC"
fi

AC_SUBST(PTHREAD_LIBS)
AC_SUBST(PTHREAD_CFLAGS)
AC_SUBST(PTHREAD_CC)

# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
if test x"$acx_pthread_ok" = xyes; then
        ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
        :
else
        acx_pthread_ok=no
        $2
fi
AC_LANG_RESTORE
])dnl ACX_PTHREAD

# sets the search path which is used by MT_HAVE_PACKAGE
AC_DEFUN([MT_SET_SEARCHPATH],
[
    AC_REQUIRE([AC_CANONICAL_HOST])

    MT_SEARCHPATH="/usr/local"
    case $host in
        *-*-darwin*)
            MT_SEARCHPATH="/opt/local"
        ;;
    esac

    AC_ARG_WITH(search,
        AC_HELP_STRING([--with-search=DIR], [Additionally search for packages in DIR]),
        [
            MT_SEARCHPATH=$withval
            AC_MSG_NOTICE([Will also search for packages in ${MT_SEARCHPATH}])
        ]
    )

    MT_SEARCHPATH_HEADERS="${MT_SEARCHPATH}/include"
    MT_SEARCHPATH_LIBS="${MT_SEARCHPATH}/lib"
    MT_SEARCHPATH_PROGS="${MT_SEARCHPATH}/bin"

    AC_SUBST(MT_SEARCHPATH)
    AC_SUBST(MT_SEARCHPATH_HEADERS)
    AC_SUBST(MT_SEARCHPATH_LIBS)
    AC_SUBST(MT_SEARCHPATH_PROGS)
])


# $1 with parameter/package name
# $2 library name
# $3 function name
# $4 "pass" if requested option failed
# 
# returns:
#   mt_$1_library_status
#   mt_$1_libs
#   mt_$1_ldflags

AC_DEFUN([MT_CHECK_LIBRARY_INTERNAL],
[
    mt_$1_arg_default=yes
    mt_$1_library_status=yes

    LIBS_SAVE=$LIBS
    LDFLAGS_SAVE=$LDFLAGS
    CFLAGS_SAVE=$CFLAGS
    CXXFLAGS_SAVE=$CXXFLAGS
    CPPFLAGS_SAVE=$CPPFLAGS

    AC_ARG_WITH($1-libs,
        AC_HELP_STRING([--with-$1-libs=DIR], [search for $1 libraries in DIR]),
        [
            mt_$1_search_libs="$withval"
            AC_MSG_NOTICE([Will search for $1 libs in $withval])
        ]
    )

    if test "$mt_$1_search_libs" ; then
        unset ac_cv_lib_$2_$3
        LDFLAGS="$LDFLAGS -L$mt_$1_search_libs"
        AC_CHECK_LIB($2, $3,
            [
                mt_$1_libs="-l$2"
                mt_$1_ldflags="-L$mt_$1_search_libs"
            ],
            [
                mt_$1_library_status=missing
                if test "$4" = "pass"; then
                    AC_MSG_NOTICE([$1 library not found in requested location $mt_$1_search_libs])
                else
                    AC_MSG_ERROR([$1 library not found in requested location $mt_$1_search_libs])
                fi
            ]
        )
    else
        unset ac_cv_lib_$2_$3
        AC_CHECK_LIB($2, $3,
            [
                mt_$1_libs="-l$2"
            ],
            [
                LDFLAGS="$LDFLAGS -L$MT_SEARCHPATH_LIBS"
                unset ac_cv_lib_$2_$3
                AC_CHECK_LIB($2, $3,
                    [
                        mt_$1_libs="-l$2"
                        mt_$1_ldflags="-L$MT_SEARCHPATH_LIBS" 
                    ],
                    [
                        mt_$1_library_status=missing
                    ]
                )
            ]
        )
    fi

    if test "x$mt_$1_library_status" != xyes; then
        mt_$1_libs=""
        mt_$1_ldflags=""
    fi

    LIBS=$LIBS_SAVE
    LDFLAGS=$LDFLAGS_SAVE
    CFLAGS=$CFLAGS_SAVE
    CXXFLAGS=$CXXFLAGS_SAVE
    CPPFLAGS=$CPPFLAGS_SAVE
])

# $1 with parameter / library name
# $2 header without .h extension
# $3 fail / pass
#
# returns:
#   mt_$1_header_status
#   mt_$1_cxxflags

AC_DEFUN([MT_CHECK_HEADER_INTERNAL],
[
    LIBS_SAVE=$LIBS
    LDFLAGS_SAVE=$LDFLAGS
    CFLAGS_SAVE=$CFLAGS
    CXXFLAGS_SAVE=$CXXFLAGS
    CPPFLAGS_SAVE=$CPPFLAGS

    mt_$1_header_status=yes

    AC_ARG_WITH($1-h,
        AC_HELP_STRING([--with-$1-h=DIR], [search for $1 headers in DIR]),
        [
            mt_$1_search_headers="$withval"
            AC_MSG_NOTICE([Will search for $1 headers in $withval])
        ]
    )

    if test "$mt_$1_search_headers" ; then
        unset translit(ac_cv_header_$2_h, `/.-', `___')
        CFLAGS="$CFLAGS -I${mt_$1_search_headers}"
        CXXFLAGS="$CXXFLAGS -I${mt_$1_search_headers}"
        CPPFLAGS="$CPPFLAGS -I${mt_$1_search_headers}"
        AC_CHECK_HEADER($mt_$1_search_headers/$2.h,
            [
                mt_$1_cxxflags="-I${mt_$1_search_headers}"
            ],
            [
                mt_$1_header_status=missing
                if test "$3" = "pass"; then
                    AC_MSG_NOTICE([$1 headers not found in requested location $mt_$1_search_headers])
                else
                    AC_MSG_ERROR([$1 headers not found in requested location $mt_$1_search_headers])
                fi
            ]
        )
    else
        unset translit(ac_cv_header_$2_h, `/.-', `___')
        AC_CHECK_HEADER($2.h,
            [],
            [
                CFLAGS="$CFLAGS -I$MT_SEARCHPATH_HEADERS"
                CXXFLAGS="$CXXFLAGS -I$MT_SEARCHPATH_HEADERS"
                CPPFLAGS="$CPPFLAGS -I$MT_SEARCHPATH_HEADERS"
                unset translit(ac_cv_header_$2_h, `/.-', `___')
                AC_CHECK_HEADER($MT_SEARCHPATH_HEADERS/$2.h,
                    [
                        mt_$1_cxxflags="-I${MT_SEARCHPATH_HEADERS}"
                    ],
                    [
                        mt_$1_header_status=missing
                    ]
                )
            ]
        )
    fi

    if test "x$mt_$1_header_status" != xyes; then
        mt_$1_cxxflags=""
    fi

    LIBS=$LIBS_SAVE
    LDFLAGS=$LDFLAGS_SAVE
    CFLAGS=$CFLAGS_SAVE
    CXXFLAGS=$CXXFLAGS_SAVE
    CPPFLAGS=$CPPFLAGS_SAVE
])


# $1 package name
# $2 header name (without .h extension)
# $3 library name
# $4 function name
# $5 "pass" if requestd options failed
#
# returns:
#   mt_$1_package_status
#   $1_CFLAGS
#   $1_LIBS
#   $1_LDFLAGS
   
AC_DEFUN([MT_CHECK_PACKAGE_INTERNAL],
[
    MT_CHECK_HEADER_INTERNAL([$1], [$2], [$5])
    mt_$1_package_status=${mt_$1_header_status}
  
    if test "x$mt_$1_package_status" = xyes; then 
        MT_CHECK_LIBRARY_INTERNAL([$1], [$3], [$4], [$5])
        mt_$1_package_status=${mt_$1_library_status}
    fi
    
    if test "x$mt_$1_package_status" = xyes; then
        translit($1, `a-z/.-', `A-Z___')_CFLAGS=${mt_$1_cxxflags}
        translit($1, `a-z/.-', `A-Z___')_LIBS=${mt_$1_libs}
        translit($1, `a-z/.-', `A-Z___')_LDFLAGS=${mt_$1_ldflags}
    fi 
])

# $1 option name
# $2 enable/disable
# $3 help text
# $4 action if enabled
# $5 action if disabled
#
# returns:
#   $1_OPTION_ENABLED
#   $1_OPTION_REQUESTED

AC_DEFUN([MT_OPTION],
[

    translit(mt_$1_option_enabled, `/.-', `___')=
    translit(mt_$1_option_requested, `/.-', `___')=no
    if test "x$2" = xdisable; then
        translit(mt_$1_option_enabled, `/.-', `___')=yes
    else
        translit(mt_$1_option_enabled, `/.-', `___')=no
    fi

    AC_ARG_ENABLE([$1],
        AC_HELP_STRING([--$2-$1], [$3]),
        [
            translit(mt_$1_option_enabled, `/.-', `___')=$enableval
            translit(mt_$1_option_requested, `/.-', `___')=yes
        ]
    )

    translit($1, `a-z/.-', `A-Z___')_OPTION_ENABLED=${translit(mt_$1_option_enabled,`/.-', `___')}
    translit($1, `a-z/.-', `A-Z___')_OPTION_REQUESTED=${translit(mt_$1_option_requested, `/.-', `___')}

    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_OPTION_ENABLED)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_OPTION_REQUESTED)

    AS_IF([test "x${translit(mt_$1_option_enabled,`/.-', `___')}" = xyes], [$4], [$5])[]dnl
])

# $1 package name
# $2 enable/disable
# $3 enable/disable help string
# $4 header name (without .h)
# $5 library name
# $6 function name
# $7 "pass" on requested options
# returns substed:
#   $1_STATUS
#   $1_LDFLAGS
#   $1_LIBS
#   $1_CFLAGS

AC_DEFUN([MT_CHECK_OPTIONAL_PACKAGE], 
[
    mt_$1_status=yes

    MT_OPTION([$1], [$2], [$3],[],[])

    if test "x${translit($1, `a-z/.-', `A-Z___')_OPTION_ENABLED}" = xyes; then
        MT_CHECK_PACKAGE_INTERNAL([$1], [$4], [$5], [$6], [$7])
        mt_$1_status=${mt_$1_package_status}
    else
        mt_$1_status=disabled
    fi
    
    if ((test "x${translit($1, `a-z/.-', `A-Z___')_OPTION_ENABLED}" = xyes) &&
        (test "x${translit($1, `a-z/.-', `A-Z___')_OPTION_REQUESTED}" = xyes) &&
        (test "x$mt_$1_status" != xyes) && (test "$7" != "pass")); then
        AC_MSG_ERROR([unable to configure $1 support])
    fi

    if test "x$mt_$1_status" = xyes; then
        AC_DEFINE(translit(HAVE_$1, `a-z/.-', `A-Z___'), [1], [$1 library presence])
    fi
    
    translit($1, `a-z/.-', `A-Z___')_STATUS=${mt_$1_status}

    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_LIBS)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_LDFLAGS)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_CFLAGS)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_STATUS)
])

# $1 package name
# $2 header name (without .h)
# $3 library name
# $4 function name
#
# returns substed:
#   $1_STATUS
#   $1_LDFLAGS
#   $1_LIBS
#   $1_CFLAGS


AC_DEFUN([MT_CHECK_REQUIRED_PACKAGE],
[
    MT_CHECK_PACKAGE_INTERNAL($1, $2, $3, $4)
    if test "x$mt_$1_package_status" != xyes; then
        AC_MSG_ERROR([unable to configure required package $1])
    fi

    AC_DEFINE(translit(HAVE_$1, `a-z/.-', `A-Z___'), [1], [$1 library presence])
    
    translit($1, `a-z/.-', `A-Z___')_STATUS=${mt_$1_package_status}

    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_CFLAGS)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_LIBS)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_LDFLAGS)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_STATUS)
])

# $1 with parameter name
# $2 library name
# $3 function to check
AC_DEFUN([MT_CHECK_LIBRARY],
[
    MT_CHECK_LIBRARY_INTERNAL([$1], [$2], [$3])

    translit($1, `a-z/.-', `A-Z___')_LIBS=${mt_$1_libs}
    translit($1, `a-z/.-', `A-Z___')_LDFLAGS=${mt_$1_ldflags}
    translit($1, `a-z/.-', `A-Z___')_STATUS=${mt_$1_library_status}
    
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_LIBS)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_LDFLAGS)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_STATUS)
])

# $1 with parameter name
# $2 header to check
# $3 fail or pass in case a path parameter was specified and the header missing
#    empty: fail
AC_DEFUN([MT_CHECK_HEADER],
[
    MT_CHECK_HEADER_INTERNAL($1, $2, $3)
    
    translit($1, `a-z/.-', `A-Z___')_CFLAGS=${mt_$1_cxxflags}
    translit($1, `a-z/.-', `A-Z___')_STATUS=${mt_$1_header_status}

    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_CFLAGS)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_STATUS)
])

# $1 package name
# $2 config file name
# $3 headers
# $4 library name
# $5 function name
# $6 optional library command
#
#  returns substed:
#    $mt_$1_package_status
#    $1_LDFLAGS
#    $1_LIBS
#    $1_CFLAGS

AC_DEFUN([MT_CHECK_BINCONFIG_INTERNAL],
[
    LIBS_SAVE=$LIBS
    LDFLAGS_SAVE=$LDFLAGS
    CFLAGS_SAVE=$CFLAGS
    CXXFLAGS_SAVE=$CXXFLAGS
    CPPFLAGS_SAVE=$CPPFLAGS


    mt_$1_config=none
    mt_$1_package_status=yes

    AC_ARG_WITH($1-cfg,
        AC_HELP_STRING([--with-$1-cfg=$2], [absolute path/name of $2]),
        [
            mt_$1_search_config="$withval"
            AC_MSG_NOTICE([Will search for $1 config in $withval])
        ]
    )

    if test -n "$mt_$1_search_config"; then
        AC_MSG_NOTICE([You specified ${mt_$1_search_config} for $2])
        if test -f "$mt_$1_search_config"; then
            mt_$1_config=${mt_$1_search_config}
        else
            AC_MSG_ERROR([${mt_$1_search_config} not found])
        fi

        mt_$1_version=`${mt_$1_config} --version 2>/dev/null`
        if test -z "$mt_$1_version"; then
            AC_MSG_ERROR([${mt_$1_search_config} could not be executed or returned invalid values])
        fi
    else
        AC_PATH_PROG(mt_$1_config, $2, none)
        if test "x$mt_$1_config" = xnone; then
            unset ac_cv_path_mt_$1_config
            AC_PATH_PROG(mt_$1_config, $2, none, $MT_SEARCHPATH_PROGS)
            if test "x$mt_$1_config" = xnone; then
                mt_$1_package_status=missing
                AC_MSG_RESULT([$2 not found, please install the $1 devel package])
            fi
        fi
       
        mt_$1_version=`${mt_$1_config} --version 2>/dev/null`
        if test -z "$mt_$1_version"; then
            AC_MSG_NOTICE([${mt_$1_config} could not be executed or returned invalid values])
            mt_$1_package_status=missing
        fi
    fi
    if test "x$mt_$1_package_status" = xyes; then
        AC_MSG_CHECKING([$1 cflags])
        mt_$1_cxxflags=`${mt_$1_config} --cflags`
        AC_MSG_RESULT([$mt_$1_cxxflags])
        mt_$1_libs=
        AC_MSG_CHECKING([$1 libs])
        if test -z "$6";  then
            mt_$1_libs=`${mt_$1_config} --libs`
        else
            mt_$1_libs=`${mt_$1_config} $6`
        fi
        AC_MSG_RESULT([$mt_$1_libs])
    fi

    if test "x$mt_$1_package_status" = xyes; then
        CPPFLAGS="$CPPFLAGS $mt_$1_cxxflags"
        CXXFLAGS="$CXXFLAGS $mt_$1_cxxflags"
        CFLAGS="$CFLAGS $mt_$1_cxxflags"
        for mt_u_header in translit($3, `/.-', `___'); do
            unset ac_cv_header_${mt_u_header}
        done
        AC_CHECK_HEADERS($3, [], [mt_$1_package_status=missing])
    fi

    if test "x$mt_$1_package_status" = xyes; then
        LIBS="$mt_$1_libs $LIBS"
        if test -z "$4"; then
            unset ac_cv_func_$5
            AC_CHECK_FUNCS($5, [], [mt_$1_package_status=missing])
        else
            unset ac_cv_lib_$4_$5
            AC_CHECK_LIB($4, $5, [], [mt_$1_package_status=missing])
        fi
    fi

    if test "x$mt_$1_package_status" = xyes; then
        translit($1, `a-z/.-', `A-Z___')_CFLAGS=${mt_$1_cxxflags}
        translit($1, `a-z/.-', `A-Z___')_LIBS=${mt_$1_libs}
        translit($1, `a-z/.-', `A-Z___')_VERSION=${mt_$1_version}
    fi 


    LIBS=$LIBS_SAVE
    LDFLAGS=$LDFLAGS_SAVE
    CFLAGS=$CFLAGS_SAVE
    CXXFLAGS=$CXXFLAGS_SAVE
    CPPFLAGS=$CPPFLAGS_SAVE
])

# $1 package name
# $2 enable/disable
# $3 enable/disable help string
# $4 config file name
# $5 headers
# $6 library name
# $7 function name
# $8 custom lib parameter
#
# returns:
#   mt_$1_package_status
#   $1_CFLAGS
#   $1_LIBS
#   $1_VERSION

AC_DEFUN([MT_CHECK_OPTIONAL_PACKAGE_CFG],
[
    mt_$1_status=yes
    mt_$1_requested=no

    MT_OPTION([$1], [$2], [$3],[],[])

    if test "x${translit($1, `a-z/.-', `A-Z___')_OPTION_ENABLED}" = xyes; then
        MT_CHECK_BINCONFIG_INTERNAL($1, $4, $5, $6, $7, $8)
        mt_$1_status=${mt_$1_package_status}
    else
        mt_$1_status=disabled
    fi
 
    if ((test "x${translit($1, `a-z/.-', `A-Z___')_OPTION_ENABLED}" = xyes) &&
        (test "x${translit($1, `a-z/.-', `A-Z___')_OPTION_REQUESTED}" = xyes) &&
        (test "x$mt_$1_status" != xyes)); then
        AC_MSG_ERROR([unable to configure $1 support])
    fi
   
    if test "x$mt_$1_status" = xyes; then
        AC_DEFINE(translit(HAVE_$1, `a-z/.-', `A-Z___'), [1], [$1 library presence])
    fi

    translit($1, `a-z/.-', `A-Z___')_STATUS=${mt_$1_status}

    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_CFLAGS)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_LIBS)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_VERSION)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_STATUS)


#    AS_IF([test x"$mt_$1_status" = xyes], [$8], [$9])[]dnl
])

# $1 package name
# $2 config file name
# $3 headers
# $4 library name
# $5 function name
#
#  returns substed:
#    $mt_$1_package_status
#    $1_LDFLAGS
#    $1_LIBS
#    $1_CFLAGS

AC_DEFUN([MT_CHECK_REQUIRED_PACKAGE_CFG],
[
    MT_CHECK_BINCONFIG_INTERNAL($1, $2, $3, $4, $5)
    if test "x$mt_$1_package_status" != xyes; then
        AC_MSG_ERROR([unable to configure required package $1])
    fi
    
    translit($1, `a-z/.-', `A-Z___')_STATUS=${mt_$1_package_status}
        
    AC_DEFINE(translit(HAVE_$1, `a-z/.-', `A-Z___'), [1], [$1 library presence])

    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_CFLAGS)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_LIBS)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_VERSION)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_STATUS)
])

# $1 package name
# $2 config file name
# $3 headers
# $4 library name
# $5 function name
#
#  returns substed:
#    $mt_$1_package_status
#    $1_LDFLAGS
#    $1_LIBS
#    $1_CFLAGS


AC_DEFUN([MT_CHECK_PACKAGE_CFG],
[
    mt_$1_status=yes

    if test "x$mt_$1_status" = xyes; then
        MT_CHECK_BINCONFIG_INTERNAL($1, $2, $3, $4, $5)
        mt_$1_status=${mt_$1_package_status}
    fi
    
    if test "x$mt_$1_status" = xyes; then
        AC_DEFINE(translit(HAVE_$1, `a-z/.-', `A-Z___'), [1], [$1 library presence])
    fi

    translit($1, `a-z/.-', `A-Z___')_STATUS=${mt_$1_status}

    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_CFLAGS)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_LIBS)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_VERSION)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_STATUS)
])

# $1 package name
# $2 headers
# $3 library name
# $4 function name
#
#  returns substed:
#    $mt_$1_package_status
#    $1_LDFLAGS
#    $1_LIBS
#    $1_CFLAGS


AC_DEFUN([MT_CHECK_PACKAGE],
[
    mt_$1_status=yes

    if test "x$mt_$1_status" = xyes; then
        MT_CHECK_PACKAGE_INTERNAL($1, $2, $3, $4)
        mt_$1_status=${mt_$1_package_status}
    fi

    if test "x$mt_$1_status" = xyes; then
        AC_DEFINE(translit(HAVE_$1, `a-z/.-', `A-Z___'), [1], [$1 library presence])
    fi

    translit($1, `a-z/.-', `A-Z___')_STATUS=${mt_$1_status}

    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_CFLAGS)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_LIBS)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_VERSION)
    AC_SUBST(translit($1, `a-z/.-', `A-Z___')_STATUS)
])