[go: up one dir, main page]

File: configure.in.in

package info (click to toggle)
tork 0.29.1-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 12,184 kB
  • ctags: 2,500
  • sloc: cpp: 21,687; ansic: 18,818; sh: 15,619; perl: 2,831; makefile: 289
file content (966 lines) | stat: -rw-r--r-- 29,892 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
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
#MIN_CONFIG(3.3.5)

AM_INIT_AUTOMAKE(tork, 0.1)
AC_C_BIGENDIAN
AC_CHECK_KDEMAXPATHLEN

# ---- Taken from KOffice ----------------------
# --- Check for KDE 3.2 or 3.3 or 3.4 or 3.5 ---

AC_MSG_CHECKING([for KDE version])

AC_LANG_SAVE
AC_LANG_CPLUSPLUS
kdeversion_save_CXXFLAGS="$CXXFLAGS"
kdeversion_safe_LIBS="$LIBS"
LIBS="$LIBS $X_EXTRA_LIBS"
CXXFLAGS="$CXXFLAGS $all_includes"

AC_COMPILE_IFELSE([
#include <kdeversion.h>
#if ! ( KDE_IS_VERSION( 3, 2, 90 ) )
#error KDE 3.2
#endif
],
        need_kde32_compat="no"
,
        need_kde32_compat="yes"
)

AC_COMPILE_IFELSE([
#include <kdeversion.h>
#if ! ( KDE_IS_VERSION( 3, 3, 90 ) )
#error KDE 3.3
#endif
],
        need_kde33_compat="no"
,
        need_kde33_compat="yes"
)

AC_COMPILE_IFELSE([
#include <kdeversion.h>
#if ! ( KDE_IS_VERSION( 3, 4, 90 ) )
#error KDE 3.4
#endif
],
        need_kde34_compat="no"
,
        need_kde34_compat="yes"
)

AC_COMPILE_IFELSE([
#include <kdeversion.h>
#if ! ( KDE_IS_VERSION( 3, 5, 2 ) )
#error KDE 3.5.x (x < 2)
#endif
],
        need_kde351_compat="no"
,
        need_kde351_compat="yes"
)
CXXFLAGS="$kdeversion_save_CXXFLAGS"
LIBS="$kdeversion_safe_LIBS"
AC_LANG_RESTORE

if test "$need_kde32_compat" = "yes"; then
        AC_MSG_ERROR([You have KDE 3.2.x. TorK needs KDE 3.5.1 or greater.])
else
        if test "$need_kde33_compat" = "yes"; then
                AC_MSG_ERROR([You have KDE 3.3.x TorK needs KDE 3.5.1 or greater.])
        else 
                if test "$need_kde34_compat" = "yes"; then
                        AC_MSG_ERROR([You have KDE 3.4.x TorK needs KDE 3.5.1 or greater.])
                else
                        if test "$need_kde351_compat" = "yes"; then
                                 AC_MSG_RESULT([KDE 3.5.x (x >=1) or SVN trunk])
                        else
                                AC_MSG_RESULT([KDE 3.5.x (x >=2) or SVN trunk])
                        fi
                fi
        fi
fi


# --- End KDE 3.2 check ---

# --- Begin libgnutls macro ---

dnl Autoconf macros for libgnutls
dnl $id$

# Modified for LIBGNUTLS -- nmav
# Configure paths for LIBGCRYPT
# Shamelessly stolen from the one of XDELTA by Owen Taylor
# Werner Koch   99-12-09

dnl AM_PATH_LIBGNUTLS([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
dnl Test for libgnutls, and define LIBGNUTLS_CFLAGS and LIBGNUTLS_LIBS
dnl
AC_DEFUN([AM_PATH_LIBGNUTLS],
[dnl
dnl Get the cflags and libraries from the libgnutls-config script
dnl
AC_ARG_WITH(libgnutls-prefix,
          [  --with-libgnutls-prefix=PFX   Prefix where libgnutls is installed (optional)],
          libgnutls_config_prefix="$withval", libgnutls_config_prefix="")

  if test x$libgnutls_config_prefix != x ; then
     if test x${LIBGNUTLS_CONFIG+set} != xset ; then
        LIBGNUTLS_CONFIG=$libgnutls_config_prefix/bin/libgnutls-config
     fi
  fi

  AC_PATH_PROG(LIBGNUTLS_CONFIG, libgnutls-config, no)
  min_libgnutls_version=ifelse([$1], ,0.1.0,$1)
  AC_MSG_CHECKING(for libgnutls - version >= $min_libgnutls_version)
  no_libgnutls=""
  if test "$LIBGNUTLS_CONFIG" = "no" ; then
    no_libgnutls=yes
  else
    LIBGNUTLS_CFLAGS=`$LIBGNUTLS_CONFIG $libgnutls_config_args --cflags`
    LIBGNUTLS_LIBS=`$LIBGNUTLS_CONFIG $libgnutls_config_args --libs`
    libgnutls_config_version=`$LIBGNUTLS_CONFIG $libgnutls_config_args --version`


      ac_save_CFLAGS="$CFLAGS"
      ac_save_LIBS="$LIBS"
      CFLAGS="$CFLAGS $LIBGNUTLS_CFLAGS"
      LIBS="$LIBS $LIBGNUTLS_LIBS"
dnl
dnl Now check if the installed libgnutls is sufficiently new. Also sanity
dnl checks the results of libgnutls-config to some extent
dnl
      rm -f conf.libgnutlstest
      AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gnutls/gnutls.h>

int
main ()
{
    system ("touch conf.libgnutlstest");

    if( strcmp( gnutls_check_version(NULL), "$libgnutls_config_version" ) )
    {
      printf("\n*** 'libgnutls-config --version' returned %s, but LIBGNUTLS (%s)\n",
             "$libgnutls_config_version", gnutls_check_version(NULL) );
      printf("*** was found! If libgnutls-config was correct, then it is best\n");
      printf("*** to remove the old version of LIBGNUTLS. You may also be able to fix the error\n");
      printf("*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n");
      printf("*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n");
      printf("*** required on your system.\n");
      printf("*** If libgnutls-config was wrong, set the environment variable LIBGNUTLS_CONFIG\n");
      printf("*** to point to the correct copy of libgnutls-config, and remove the file config.cache\n");
      printf("*** before re-running configure\n");
    }
    else if ( strcmp(gnutls_check_version(NULL), LIBGNUTLS_VERSION ) )
    {
      printf("\n*** LIBGNUTLS header file (version %s) does not match\n", LIBGNUTLS_VERSION);
      printf("*** library (version %s)\n", gnutls_check_version(NULL) );
    }
    else
    {
      if ( gnutls_check_version( "$min_libgnutls_version" ) )
      {
        return 0;
      }
     else
      {
        printf("no\n*** An old version of LIBGNUTLS (%s) was found.\n",
                gnutls_check_version(NULL) );
        printf("*** You need a version of LIBGNUTLS newer than %s. The latest version of\n",
               "$min_libgnutls_version" );
        printf("*** LIBGNUTLS is always available from ftp://gnutls.hellug.gr/pub/gnutls.\n");
        printf("*** \n");
        printf("*** If you have already installed a sufficiently new version, this error\n");
        printf("*** probably means that the wrong copy of the libgnutls-config shell script is\n");
        printf("*** being found. The easiest way to fix this is to remove the old version\n");
        printf("*** of LIBGNUTLS, but you can also set the LIBGNUTLS_CONFIG environment to point to the\n");
        printf("*** correct copy of libgnutls-config. (In this case, you will have to\n");
        printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
        printf("*** so that the correct libraries are found at run-time))\n");
      }
    }
  return 1;
}
],, no_libgnutls=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
       CFLAGS="$ac_save_CFLAGS"
       LIBS="$ac_save_LIBS"
  fi

  if test "x$no_libgnutls" = x ; then
     AC_MSG_RESULT(yes)
     ifelse([$2], , :, [$2])
  else
     if test -f conf.libgnutlstest ; then
        :
     else
        AC_MSG_RESULT(no)
     fi
     if test "$LIBGNUTLS_CONFIG" = "no" ; then
       echo "*** The libgnutls-config script installed by LIBGNUTLS could not be found"
       echo "*** If LIBGNUTLS was installed in PREFIX, make sure PREFIX/bin is in"
       echo "*** your path, or set the LIBGNUTLS_CONFIG environment variable to the"
       echo "*** full path to libgnutls-config."
     else
       if test -f conf.libgnutlstest ; then
        :
       else
          echo "*** Could not run libgnutls test program, checking why..."
          CFLAGS="$CFLAGS $LIBGNUTLS_CFLAGS"
          LIBS="$LIBS $LIBGNUTLS_LIBS"
          AC_TRY_LINK([
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gnutls/gnutls.h>
],      [ return !!gnutls_check_version(NULL); ],
        [ echo "*** The test program compiled, but did not run. This usually means"
          echo "*** that the run-time linker is not finding LIBGNUTLS or finding the wrong"
          echo "*** version of LIBGNUTLS. If it is not finding LIBGNUTLS, you'll need to set your"
          echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
          echo "*** to the installed location  Also, make sure you have run ldconfig if that"
          echo "*** is required on your system"
          echo "***"
          echo "*** If you have an old version installed, it is best to remove it, although"
          echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"
          echo "***" ],
        [ echo "*** The test program failed to compile or link. See the file config.log for the"
          echo "*** exact error that occured. This usually means LIBGNUTLS was incorrectly installed"
          echo "*** or that you have moved LIBGNUTLS since it was installed. In the latter case, you"
          echo "*** may want to edit the libgnutls-config script: $LIBGNUTLS_CONFIG" ])
          CFLAGS="$ac_save_CFLAGS"
          LIBS="$ac_save_LIBS"
       fi
     fi
     LIBGNUTLS_CFLAGS=""
     LIBGNUTLS_LIBS=""
     ifelse([$3], , :, [$3])
  fi
  rm -f conf.libgnutlstest
  AC_SUBST(LIBGNUTLS_CFLAGS)
  AC_SUBST(LIBGNUTLS_LIBS)
])

# --- End libgnutls macro ---


dnl Compile with GNUTLS
AC_ARG_ENABLE(gnutls,
     AS_HELP_STRING(--enable-gnutls, Compile with GnuTLS))

if test x$enable_gnutls = xyes; then

# gnu tls
AM_PATH_LIBGNUTLS(1.0.0, , [
       AC_DEFINE(USE_OPENSSL, 1, [use openssl for ssl session decryption instead of gnutls])
        AC_SUBST(USE_OPENSSL)
])

fi

# --- If no gnutls check for openssl ---

if test "x$LIBGNUTLS_LIBS" = "x"; then

AC_DEFINE(USE_OPENSSL, 1, [use openssl for ssl session decryption instead of gnutls])
AC_SUBST(USE_OPENSSL)

fi

# --- End of If no gnutls check for openssl ---

# Even if gnutls is required, we still need openssl for shallot.

dnl ------------------------------------------------------
dnl Where do you live, openssl?  And how do we call you?

AC_CACHE_CHECK([for OpenSSL directory], ac_cv_openssl_dir, [
  saved_LIBS="$LIBS"
  saved_LDFLAGS="$LDFLAGS"
  saved_CPPFLAGS="$CPPFLAGS"
  ssl_found=no
  for ssldir in $tryssldir "" $prefix /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/athena /usr/pkg /opt /opt/openssl ; do
    LDFLAGS="$saved_LDFLAGS"
    SSL_LIBS="-lssl -lcrypto"
    LIBS="$saved_LIBS $SSL_LIBS"

    # Skip the directory if it isn't there.
    if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
       continue;
    fi
    if test ! -z "$ssldir" ; then
      if test -d "$ssldir/lib" ; then
        LDFLAGS="-L$ssldir/lib $LDFLAGS"
      else
        LDFLAGS="-L$ssldir $LDFLAGS"
      fi
      if test -d "$ssldir/include" ; then
        CPPFLAGS="-I$ssldir/include $CPPFLAGS"
      else
        CPPFLAGS="-I$ssldir $CPPFLAGS"
      fi
    fi
    # Can I link it?
    AC_TRY_LINK([#include <openssl/rand.h>],
       [ RAND_add((void*)0,0,0); ],
       [ openssl_linked=yes ], [ openssl_linked=no ])
    if test $openssl_linked = yes; then
       if test ! -z "$ssldir" ; then
         ac_cv_openssl_dir=$ssldir
       else
         ac_cv_openssl_dir="(system)"
       fi
       ssl_found=yes
       break
    fi
  done
  LIBS="$saved_LIBS"
  LDFLAGS="$saved_LDFLAGS"
  CPPFLAGS="$saved_CPPFLAGS"
  if test $ssl_found = no ; then
    AC_MSG_ERROR([Could not find a linkable OpenSSL. You can specify an explicit path using --with-ssl-dir])
  fi
])

saved_LIBS="$LIBS"
SSL_LIBS="-lssl -lcrypto"
LIBS="$saved_LIBS $SSL_LIBS"

if test "$ac_cv_openssl_dir" != "(system)"; then
  if test -d "$ac_cv_openssl_dir/lib" ; then
    LDFLAGS="-L$ac_cv_openssl_dir/lib $LDFLAGS"
    ssl_libdir="$ac_cv_openssl_dir/lib"
  else
    LDFLAGS="-L$ac_cv_openssl_dir $LDFLAGS"
    ssl_libdir="$ac_cv_openssl_dir"
  fi
  if test -d "$ac_cv_openssl_dir/include" ; then
    CPPFLAGS="-I$ac_cv_openssl_dir/include $CPPFLAGS"
  else
    CPPFLAGS="-I$ac_cv_openssl_dir $CPPFLAGS"
  fi
fi

AC_CACHE_CHECK([whether we need extra options to link OpenSSL],
               ac_cv_openssl_linker_option, [
    saved_LDFLAGS="$LDFLAGS"
    ssl_runs=no
    linked_with=nothing
    for ssl_extra in "" "-Wl,-R$ssl_libdir" "-R$ssl_libdir" ; do
      LDFLAGS="$ssl_extra $saved_LDFLAGS"
      AC_TRY_RUN([
#include <string.h>
#include <openssl/rand.h>
int main(void)
{
        char a[2048];
        memset(a, 0, sizeof(a));
        RAND_add(a, sizeof(a), sizeof(a));
        return(RAND_status() <= 0);
}
                        ],
                openssl_runs=yes, openssl_runs=no)
      if test $openssl_runs = yes ; then
        if test "$linked_with" = nothing; then
           linked_with="$ssl_extra"
        fi
        AC_TRY_RUN([
#include <openssl/opensslv.h>
#include <openssl/crypto.h>
int main(void) {
return (OPENSSL_VERSION_NUMBER == SSLeay()) == 0;
}],
        right_version=yes, right_version=no)
        if test "$right_version" = yes; then
          if test -z "$ssl_extra" ; then
            ac_cv_openssl_linker_option='(none)'
          else
            ac_cv_openssl_linker_option=$ssl_extra
          fi
          ssl_runs=yes
          break
        fi
     fi
    done
    if test $ssl_runs = no ; then
      if test "$linked_with" = 'nothing' ; then
        AC_MSG_ERROR([Found linkable OpenSSL in $ac_cv_openssl_dir, but it doesn't run, even with -R.  Maybe specify another using --with-ssl-dir?])
      else
        if test -z "$linked_with" ; then
            ac_cv_openssl_linker_option='(none)'
        else
            ac_cv_openssl_linker_option=$linked_with
        fi
        AC_MSG_WARN([I managed to make OpenSSL link and run, but I couldn't make it link against the same version I found header files for.])
      fi
    fi
    LDFLAGS="$saved_LDFLAGS"
])

if test "$ac_cv_openssl_linker_option" != '(none)' ; then
   LDFLAGS="$ac_cv_openssl_linker_option $LDFLAGS"
fi

LIBS="$saved_LIBS"

# --- Decide which library to use for linking Tork ---
# --- SSL will be used for shallot ---

if test "x$LIBGNUTLS_LIBS" = "x"; then
    CRYPTO_LIBS=$SSL_LIBS
else
    CRYPTO_LIBS=$LIBGNUTLS_LIBS
fi
AC_SUBST(CRYPTO_LIBS)
AC_SUBST(SSL_LIBS)



dnl - GeoIP

AC_ARG_WITH(external-geoip,
	AC_HELP_STRING([--with-external-geoip], [Build against an external copy of GeoIP]))

if test "x$with_external_geoip" != "xyes"; then
   GEOVERSION=1.4.2
   dnl PACKAGE=GeoIP
   GEOIP_VERSION_INFO=`echo $GEOVERSION | awk -F. '{ printf "%d:%d:%d", $1+$2, $3, $2 }'`
   AC_SUBST(GEOIP_VERSION_INFO)

   AC_ARG_WITH(city,
   [  --with-city=\"no\"   Enable/disable support for GeoIP City Edition. (yes)])
   if test "$with_city" = "no" ; then
     echo Disabling GeoIP City Edition support
     WITH_CITY=1
   else
     echo Enabling GeoIP City Edition support
     WITH_CITY=0
   fi
   AC_SUBST(WITH_CITY)
else
   with_city=no

   AC_CHECK_HEADERS([GeoIP.h],,
     [AC_MSG_ERROR([External GeoIP requested but GeoIP not found.])])
   AC_CHECK_LIB([GeoIP], [GeoIP_new], [GEOIPLIB=-lGeoIP],
     [AC_MSG_ERROR([External GeoIP requested but GeoIP not found.])])
fi

AM_CONDITIONAL(WITH_CITY, test "$with_city" != "no")
AM_CONDITIONAL([EXTERNAL_GEOIP], [test "x$with_external_geoip" = "xyes"])

if test x$with_external_geoip = xyes; then
  AC_DEFINE(EXTERNAL_GEOIP, 1, "Using External GeoIP")
fi


dnl - tsocks

dnl Process this file with autoconf to produce a configure script.


dnl Our default prefix is /usr/ since most people will be using tsocks
dnl on Linux systems and that /usr/local/ stuff annoys them
dnl AC_PREFIX_DEFAULT(/usr)

dnl if libdir hasn't been set by the user default it to /lib since
dnl tsocks needs to be on the root partition if put in the
dnl /etc/ld.so.preload file
dnl test "$libdir" = "\${exec_prefix}/lib" && libdir="/lib"

dnl Arguments we allow
AC_ARG_ENABLE(socksdns,
[  --enable-socksdns       force dns lookups to use tcp ])
AC_ARG_ENABLE(tordns,
[  --disable-tordns         don't override name lookup calls to use SOCKS ])   
AC_ARG_ENABLE(debug,
[  --disable-debug         disable ALL error messages from tsocks ])
AC_ARG_ENABLE(oldmethod,
[  --enable-oldmethod      use the old method to override connect ])
AC_ARG_ENABLE(hostnames,
[  --enable-hostnames      enable hostname lookups for socks servers ])
AC_ARG_ENABLE(envconf,
[  --disable-envconf       do not allow TSOCKS_CONF_FILE to specify configuration file ])
AC_ARG_WITH(conf,
[  --with-conf=<file>      location of configuration file (/etc/tsocks.conf default)],[
if test "${withval}" = "yes" ; then
  AC_MSG_ERROR("--with-conf requires the location of the configuration file as an argument")
else
  AC_DEFINE_UNQUOTED([CONF_FILE], ["${withval}"],[Description])
fi
], [
  AC_DEFINE_UNQUOTED([CONF_FILE], ["/etc/tsocks.conf"],[Description])
])

AC_CHECK_HEADERS(sys/types.h sys/socket.h)
AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
        linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
[#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif])


failsafe_ok=0
if test x$linux_netfilter_ipv4 = x1 ; then
  failsafe_ok=1
fi
if test x$failsafe_ok = x1 ; then
  AC_DEFINE(USE_FAILSAFE, 1, "Define to enable failsafe support")
fi

dnl -----------------------------------
dnl Get hostname and other information.
dnl -----------------------------------
AC_CANONICAL_HOST

dnl Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S

dnl Check if the C compiler accepts -Wall
AC_MSG_CHECKING(if the C compiler accepts -Wall)
OLDCFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Wall"
AC_TRY_COMPILE(,,AC_MSG_RESULT(yes),[
   CFLAGS="$OLDCFLAGS"
   AC_MSG_RESULT(no)])

dnl Checks for standard header files.
AC_HEADER_STDC

dnl Check for the dynamic loader function header
AC_CHECK_HEADER(dlfcn.h,,AC_MSG_ERROR("dlfcn.h not found"))

dnl Check for the socket header
AC_CHECK_HEADER(sys/socket.h,,AC_MSG_ERROR("sys/socket.h not found"))

dnl Check for the arpa/inet.h header (inet_ntoa and inet_addr)
AC_CHECK_HEADER(arpa/inet.h,,AC_MSG_ERROR("arpa/inet.h not found"))

dnl Check for the fcntl header
AC_CHECK_HEADER(fcntl.h,,AC_MSG_ERROR("fcntl.h not found"))

dnl Check for the poll header
AC_CHECK_HEADER(sys/poll.h,,AC_MSG_ERROR("sys/poll.h not found"))

dnl Check for the mmap header
AC_CHECK_HEADER(sys/mman.h,,AC_MSG_ERROR("sys/mman.h not found"))

dnl Other headers we're interested in
AC_CHECK_HEADERS(unistd.h)

dnl Checks for library functions.
AC_CHECK_FUNCS(strcspn strdup strerror strspn strtol mmap strcasecmp \
   strncasecmp strtol,,[AC_MSG_ERROR("Required function not found")])

dnl Find which version of gethostbyname_r we should be using (actually this
dnl isn't used right now).
dnl AX_FUNC_WHICH_GETHOSTBYNAME_R

dnl First find the library that contains connect() (obviously
dnl the most important library for us). Once we've found it
dnl we chuck it on the end of LIBS, that lib may end up there
dnl more than once (since we do our search with an empty libs
dnl list) but that isn't a problem
OLDLIBS="${LIBS}"
LIBS=
CONNECTLIB=
for LIB in c socket; do
  AC_CHECK_LIB("${LIB}",connect,[
    CONNECTLIB="${LIB}"
    break
  ],)
done
LIBS="${OLDLIBS} -l${CONNECTLIB}"
if test "${CONNECTLIB}" = ""; then
  AC_MSG_ERROR('Could not find library containing connect()')
fi

dnl Check for socket
AC_CHECK_FUNC(socket,, [
  AC_CHECK_LIB(socket, socket,,AC_MSG_ERROR("socket function not found"))])

dnl Check for a function to convert an ascii ip address
dnl to a sin_addr. 
AC_CHECK_FUNC(inet_aton, AC_DEFINE([HAVE_INET_ATON],[],[Description]), [
  AC_CHECK_FUNC(inet_addr, AC_DEFINE([HAVE_INET_ADDR],[],[Description]), [
    AC_CHECK_LIB(nsl, inet_addr, [ AC_DEFINE([HAVE_INET_ADDR],[],[Description])
                                   LIBS="${LIBS} -lnsl" ], [
		AC_MSG_ERROR("Neither inet_aton or inet_addr present")])])])

dnl Look for gethostbyname (needed by tsocks and inspectsocks)
AC_CHECK_FUNC(gethostbyname, AC_DEFINE([HAVE_GETHOSTBYNAME],[],[Description]), [
  AC_CHECK_LIB(xnet, gethostbyname, AC_DEFINE([HAVE_GETHOSTBYNAME],[],[Description]), [
	       AC_MSG_ERROR(["gethostbyname not found, name lookups in " \
		      "tsocks and inspectsocks disabled"])])])

dnl The simple programs (saveme and inspectsocks) have no further 
dnl requirements, so save the libs needed here and use them in the
dnl Makefile
SIMPLELIBS=${LIBS}
LIBS=

dnl Checks for libraries.
dnl Replace `main' with a function in -ldl:

AC_CHECK_LIB(dl, dlsym, [ tempdso="yes" ],tempdso="no")
if test "$tempdso" = "no"; then
  AC_CHECK_LIB(c, dlsym,,AC_MSG_ERROR("dlsym() not found in libc or libdl." \
               "Check your system for libc.so and/or libdl.so."))
fi

dnl If we're using gcc here define _GNU_SOURCE
AC_MSG_CHECKING(for RTLD_NEXT from dlfcn.h)
AC_EGREP_CPP(yes,
[
 #include <dlfcn.h>
 #ifdef RTLD_NEXT
	yes
 #endif
], [
  AC_MSG_RESULT(yes)
], [
  AC_MSG_RESULT(no)
  AC_MSG_CHECKING(for RTLD_NEXT from dlfcn.h with _GNU_SOURCE)
  AC_EGREP_CPP(yes,
  [
   #define _GNU_SOURCE
   #include <dlfcn.h>
   #ifdef RTLD_NEXT
	yes
   #endif
  ], [
    AC_MSG_RESULT(yes)
    AC_DEFINE([USE_GNU_SOURCE],[],[Description])
  ], [
    AC_MSG_RESULT(no)
    AC_DEFINE([USE_OLD_DLSYM],[],[Description])
    oldmethod="yes"
  ])    
])

if test "${enable_socksdns}" = "yes"; then
  AC_DEFINE([USE_SOCKS_DNS],[],[Description])
fi

AC_MSG_CHECKING(whether to enable tordns)
if test "x${enable_tordns}" = "x"; then
  AC_DEFINE([USE_TOR_DNS],[],[Description])
  DEADPOOL_O="\${DEADPOOL}.o"
  AC_MSG_RESULT(yes)
else 
  DEADPOOL_O=""
  AC_MSG_RESULT(no)
fi
AC_SUBST(DEADPOOL_O)

if test "x${enable_envconf}" = "x"; then
  AC_DEFINE([ALLOW_ENV_CONFIG],[],[Description])
fi

if test "${enable_oldmethod}" = "yes"; then
  AC_DEFINE([USE_OLD_DLSYM],[],[Description])
  oldmethod="yes"
fi

if test "x${enable_debug}" = "x"; then
  AC_DEFINE([ALLOW_MSG_OUTPUT],[],[Description])
fi

AC_DEFINE([HOSTNAMES],[0],[Description])

if test "x${enable_hostnames}" = "xyes"; then
  AC_DEFINE([HOSTNAMES],[1],[Description])
fi

if test "${enable_socksdns}" = "yes" -a \
        "x${enable_hostnames}" = "xyes" ; then
  AC_MSG_ERROR("--enable-socksdns is not valid with --enable-hostnames")
fi

if test "x${enable_tordns}" = "x" -a \
        "x${enable_hostnames}" = "xyes" ; then
  AC_MSG_ERROR("--enable-tordns is not valid with --enable-hostnames")
fi

dnl If we have to use the old method of overriding connect (i.e no
dnl RTLD_NEXT) we need to know the location of the library that
dnl contains connect(), select(), poll() and close()
if test "${oldmethod}" = "yes"; then 
  dnl We need to find the path to the library, to do 
  dnl this we use find on the usual suspects, i.e /lib and
  dnl /usr/lib

  dnl Check that find is available, it should be somehere
  dnl in the path 
  AC_CHECK_PROG(FIND, find, find)
  if test "${FIND}" = ""; then
    AC_MSG_ERROR('find not found in path')
  fi

  dnl Find tail, it should always be somewhere in the path
  dnl but for safety's sake
  AC_CHECK_PROG(TAIL, tail, tail)
  if test "${TAIL}" = ""; then
    AC_MSG_ERROR('tail not found in path')
  fi

  dnl Now find the library we need
  AC_MSG_CHECKING(location of lib${CONNECTLIB}.so)
  LIBCONNECT=
  for DIR in '/lib' '/usr/lib'; do
    if test "${LIBCONNECT}" = ""; then
      LIBCONNECT=`$FIND $DIR -name "lib${CONNECTLIB}.so.?" 2>/dev/null | $TAIL -1`
    fi
  done
  AC_DEFINE_UNQUOTED([LIBCONNECT],["${LIBCONNECT}"],[Description])
  if test "${LIBCONNECT}" = ""; then
     AC_MSG_ERROR("not found!")
  fi

  AC_MSG_RESULT($LIBCONNECT)

  dnl close() should be in libc, find it
  AC_MSG_CHECKING(location of libc.so)
  LIBC=
  for DIR in '/lib' '/usr/lib'; do
    if test "${LIBC}" = ""; then
      LIBC=`$FIND $DIR -name "libc.so.?" 2>/dev/null | $TAIL -1`
    fi
  done

  AC_DEFINE_UNQUOTED([LIBC],["${LIBC}"],[Description])
  if test "${LIBC}" = ""; then
     AC_MSG_ERROR("not found!")
  fi

  AC_MSG_RESULT($LIBC)
fi

dnl Find the correct select prototype on this machine 
AC_MSG_CHECKING(for correct select prototype)
PROTO=
for testproto in 'int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout' 
do
  if test "${PROTO}" = ""; then
    AC_TRY_COMPILE([
      #include <sys/time.h>
      #include <sys/types.h>
      #include <unistd.h>
      int select($testproto);
    ],,[PROTO="$testproto";],)
  fi
done
if test "${PROTO}" = ""; then
  AC_MSG_ERROR("no match found!")
fi
AC_MSG_RESULT([select(${PROTO})])
AC_DEFINE_UNQUOTED([SELECT_SIGNATURE],[${PROTO}],[Description])

dnl Find the correct connect prototype on this machine 
AC_MSG_CHECKING(for correct connect prototype)
PROTO=
PROTO1='int __fd, const struct sockaddr * __addr, int len'
PROTO2='int __fd, const struct sockaddr_in * __addr, socklen_t __len'
PROTO3='int __fd, struct sockaddr * __addr, int __len'
PROTO4='int __fd, const struct sockaddr * __addr, socklen_t __len'
for testproto in "${PROTO1}" \
                 "${PROTO2}" \
                 "${PROTO3}" \
                 "${PROTO4}" 
do
  if test "${PROTO}" = ""; then
    AC_TRY_COMPILE([
      #include <sys/types.h>
      #include <sys/socket.h>
      int connect($testproto);
    ],,[PROTO="$testproto";],)
  fi
done
if test "${PROTO}" = ""; then
  AC_MSG_ERROR("no match found!")
fi
AC_MSG_RESULT([connect(${PROTO})])
AC_DEFINE_UNQUOTED([CONNECT_SIGNATURE],[${PROTO}],[Description])

dnl Pick which of the sockaddr type arguments we need for
dnl connect(), we need to cast one of ours to it later 
SOCKETARG="struct sockaddr *"
case "${PROTO}" in
   *sockaddr_in*)
      SOCKETARG="struct sockaddr_in *"
      ;;
esac
AC_DEFINE_UNQUOTED([CONNECT_SOCKARG],[${SOCKETARG}],[Description])

dnl Find the correct close prototype on this machine 
AC_MSG_CHECKING(for correct close prototype)
PROTO=
PROTO1='int fd'
for testproto in "${PROTO1}" 
do
  if test "${PROTO}" = ""; then
    AC_TRY_COMPILE([
      #include <stdlib.h>
      int close($testproto);
    ],,[PROTO="$testproto";],)
  fi
done
if test "${PROTO}" = ""; then
  AC_MSG_ERROR("no match found!")
fi
AC_MSG_RESULT([close(${PROTO})])
AC_DEFINE_UNQUOTED([CLOSE_SIGNATURE], [${PROTO}],[Description])

dnl Find the correct getpeername prototype on this machine
AC_MSG_CHECKING(for correct getpeername prototype)
PROTO=
PROTO1='int __fd, const struct sockaddr * __name, int *__namelen'
PROTO2='int __fd, const struct sockaddr_in * __name, socklen_t *__namelen'
PROTO3='int __fd, struct sockaddr * __name, socklen_t *__namelen'
PROTO4='int __fd, const struct sockaddr * __name, socklen_t *__namelen'
for testproto in "${PROTO1}" \
                 "${PROTO2}" \
                 "${PROTO3}" \
                 "${PROTO4}"
do
  if test "${PROTO}" = ""; then
    AC_TRY_COMPILE([
      #include <sys/socket.h>
      int getpeername($testproto);
    ],,[PROTO="$testproto";],)
  fi
done
if test "${PROTO}" = ""; then
  AC_MSG_ERROR("no match found!")
fi
AC_MSG_RESULT([getpeername(${PROTO})])
AC_DEFINE_UNQUOTED(GETPEERNAME_SIGNATURE, [${PROTO}],[Description])


dnl Find the correct poll prototype on this machine 
AC_MSG_CHECKING(for correct poll prototype)
PROTO=
for testproto in 'struct pollfd *ufds, unsigned long nfds, int timeout' \
                 'struct pollfd *ufds, nfds_t nfds, int timeout'
do
  if test "${PROTO}" = ""; then
    AC_TRY_COMPILE([
      #include <sys/poll.h>
      int poll($testproto);
    ],,[PROTO="$testproto";],)
  fi
done
if test "${PROTO}" = ""; then
  AC_MSG_ERROR("no match found!")
fi
AC_MSG_RESULT([poll(${PROTO})])
AC_DEFINE_UNQUOTED([POLL_SIGNATURE], [${PROTO}],[Description])

dnl Emit signature for gethostbyname
PROTO="const char *name"
AC_DEFINE_UNQUOTED([GETHOSTBYNAME_SIGNATURE], [${PROTO}],[Description])

dnl Emit signature for getaddrinfo
PROTO="const char *node, const char *service, void *hints, void *res"
AC_DEFINE_UNQUOTED([GETADDRINFO_SIGNATURE], [${PROTO}],[Description])

dnl Emit signature for getipnodebyname
PROTO="const char *name, int af, int flags, int *error_num"
AC_DEFINE_UNQUOTED([GETIPNODEBYNAME_SIGNATURE], [${PROTO}],[Description])

dnl Output the special librarys (libdl etc needed for tsocks)
SPECIALLIBS=${LIBS}
AC_SUBST(SPECIALLIBS)
LIBS=${SIMPLELIBS}


dnl - libwhich

which_cv_iberty=no
AC_ARG_ENABLE(iberty,
  [  --disable-iberty        do not try to find and use the iberty library],
  which_cv_iberty=$enableval)

dnl Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_LANG_C


AC_DEFUN([BASH_CHECK_GETPW_FUNCS],
[AC_MSG_CHECKING(whether programs are able to redeclare getpw functions)
AC_CACHE_VAL(bash_cv_can_redecl_getpw,
[AC_TRY_COMPILE([#include <sys/types.h>
#include <pwd.h>
extern struct passwd *getpwent();
extern struct passwd *getpwuid();
extern struct passwd *getpwnam();],
[struct passwd *z; z = getpwent(); z = getpwuid(0); z = getpwnam("root");],
  bash_cv_can_redecl_getpw=yes,bash_cv_can_redecl_getpw=no)])
AC_MSG_RESULT($bash_cv_can_redecl_getpw)
if test $bash_cv_can_redecl_getpw = no; then
AC_DEFINE([HAVE_GETPW_DECLS], 1, [Define this when you are able to redeclare getpw functions.])
fi
])


dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_FUNCS(strchr memcpy getopt_long)
AC_CHECK_HEADERS(unistd.h string.h libiberty.h)
AC_HEADER_STAT

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T

dnl Checks for library functions.
AC_TYPE_GETGROUPS
AC_CHECK_FUNCS(getcwd getwd)

AC_DEFINE([NEED_XMALLOC], 1, [Define if you need xmalloc().])

dnl Additional stuff needed for the tilde directory
AC_CHECK_PROG(AR, ar, ar, ar)
AC_PROG_RANLIB
AC_CHECK_HEADERS(stdlib.h)
BASH_CHECK_GETPW_FUNCS

if test "x$CONFDIR" = "x"; then
  CONFDIR=`eval echo $sysconfdir`
fi
AC_SUBST(CONFDIR)
AH_TEMPLATE([CONFDIR],[tork's configuration directory])
AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")


dnl Disable stuff that's not suitable for a Live CD
AC_ARG_ENABLE(live-cd,
     AS_HELP_STRING(--enable-live-cd, Disable Features Unsuitable for LiveCD))

if test x$enable_live_cd = xyes; then
  AC_DEFINE(LIVECD, 1, "Define to compile for a LiveCD")
fi

dnl Detect OS for Shallot compilation

case "$host" in 
  *-*-linux*) AC_DEFINE(LINUX_PORT, 1, "Shallot will compile for Linux") ;;
  *-*-freebsd*) AC_DEFINE(BSD, 1, "Shallot will compile for BSD") ;;
  *-*-netbsd*) AC_DEFINE(BSD, 1, "Shallot will compile for BSD") ;;
  *-*-openbsd*) AC_DEFINE(BSD, 1, "Shallot will compile for BSD") ;;
  *) AC_DEFINE(GENERIC, 1, "Shallot will compile for GENERIC") ;;
esac
#AC_DEFINE(_GNU_SOURCE, 1, "Shallot will compile with _GNU_SOURCE")
# USE_GNU_SOURCE above is used instead and _GNU_SOURCE defined in shallot.

AC_CONFIG_FILES([src/tsocks/torkify src/tsocks/torksocks src/menu/tork])