summaryrefslogtreecommitdiff
path: root/configure.in
blob: b9bd50f9ed8434b3b552eb22ff079391053593c2 (plain)
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
#!/bin/sh

AC_INIT(VERSION,, eda-dev@opencircuitdesign.com)
AC_PREREQ(2.60)
AC_CONFIG_SRCDIR([Makefile.in])

# Determine the host and build type.
# ===========================================================================
AC_CANONICAL_HOST
AC_CANONICAL_TARGET

PACKAGE=qrouter
VERSION=`cat ./VERSION | cut -d. -f1-2`
REVISION=`cat ./VERSION | cut -d. -f3`

AC_SUBST(VERSION)
AC_SUBST(REVISION)
AC_ARG_PROGRAM

# Required programs
# ===========================================================================
AC_PROG_CC
AC_PROG_CPP
AC_ISC_POSIX
if test "x$U" != "x"; then
  AC_MSG_ERROR(Compiler not ANSI compliant)
fi
AC_PROG_INSTALL
AC_PROG_RANLIB
AC_CHECK_PROG(AUTOCONF, autoconf, autoconf, :)
AC_CHECK_PROG(CP, cp, cp, :)
AC_CHECK_PROG(RM, rm, rm, :)

AC_LANG_C
AC_HEADER_STDC
AC_CHECK_FUNCS(setenv putenv)

# Linker
# =========================================

#------------------------------------------------------------
# AC_PROG_LD - find the path to the GNU or non-GNU linker
# (This stuff ripped from libtool)
#------------------------------------------------------------
AC_DEFUN([AC_PROG_LD],
[AC_ARG_WITH(gnu-ld,
[  --with-gnu-ld           assume the C compiler uses GNU ld [[default=no]]],
test "$withval" = no || with_gnu_ld=yes, with_gnu_ld=no)
AC_REQUIRE([AC_PROG_CC])dnl
AC_REQUIRE([AC_CANONICAL_HOST])dnl
dnl ###not for PostgreSQL### AC_REQUIRE([AC_CANONICAL_BUILD])dnl
ac_prog=ld
if test "$GCC" = yes; then
  # Check if gcc -print-prog-name=ld gives a path.
  AC_MSG_CHECKING([for ld used by GCC])
  case $host in
  *-*-mingw*)
    # gcc leaves a trailing carriage return which upsets mingw
    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
  *)
    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
  esac
  case "$ac_prog" in
    # Accept absolute paths.
changequote(,)dnl
    [\\/]* | [A-Za-z]:[\\/]*)
      re_direlt='/[^/][^/]*/\.\./'
changequote([,])dnl
      # Canonicalize the path of ld
      ac_prog=`echo $ac_prog| sed 's%\\\\%/%g'`
      while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
        ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"`
      done
      test -z "$LD" && LD="$ac_prog"
      ;;
  "")
    # If it fails, then pretend we aren't using GCC.
    ac_prog=ld
    ;;
  *)
    # If it is relative, then search for the first ld in PATH.
    with_gnu_ld=unknown
    ;;
  esac
elif test "$with_gnu_ld" = yes; then
  AC_MSG_CHECKING([for GNU ld])
else
  AC_MSG_CHECKING([for non-GNU ld])
fi
AC_CACHE_VAL(ac_cv_path_LD,
[if test -z "$LD"; then
  IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}${PATH_SEPARATOR-:}"
  for ac_dir in $PATH; do
    test -z "$ac_dir" && ac_dir=.
    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
      ac_cv_path_LD="$ac_dir/$ac_prog"
      # Check to see if the program is GNU ld.  I'd rather use --version,
      # but apparently some GNU ld's only accept -v.
      # Break only if it was the GNU/non-GNU ld that we prefer.
      if "$ac_cv_path_LD" -v 2>&1 < /dev/null | egrep '(GNU|with BFD)' > /dev/null; then
        test "$with_gnu_ld" != no && break
      else
        test "$with_gnu_ld" != yes && break
      fi
    fi
  done
  IFS="$ac_save_ifs"
else
  ac_cv_path_LD="$LD" # Let the user override the test with a path.
fi])
LD="$ac_cv_path_LD"
if test -n "$LD"; then
  AC_MSG_RESULT($LD)
else
  AC_MSG_RESULT(no)
fi
test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
AC_PROG_LD_GNU
])

AC_DEFUN([AC_PROG_LD_GNU],
[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], ac_cv_prog_gnu_ld,
[# I'd rather use --version here, but apparently some GNU ld's only accept -v.
if $LD -v 2>&1 </dev/null | egrep '(GNU|with BFD)' 1>&5; then
  ac_cv_prog_gnu_ld=yes
else
  ac_cv_prog_gnu_ld=no
fi])
with_gnu_ld=$ac_cv_prog_gnu_ld
])

AC_PROG_LD

dnl Check for va_copy
AC_CACHE_CHECK([for va_copy], ac_cv_c_va_copy,
 AC_TRY_LINK(
   [#include <stdarg.h>],
   [va_list ap1, ap2;
    va_copy(ap1,ap2);
   ],
   [ac_cv_c_va_copy="yes"],
   [ac_cv_c_va_copy="no"])
 )
if test "$ac_cv_c_va_copy" = "yes"
then
    AC_DEFINE(HAVE_VA_COPY, 1, [Define if we have va_copy])
fi
AC_CACHE_CHECK([for __va_copy], ac_cv_c___va_copy,
 AC_TRY_LINK(
   [#include <stdarg.h>],
   [va_list ap1, ap2;
    __va_copy(ap1,ap2);
   ],
   [ac_cv_c___va_copy="yes"],
   [ac_cv_c___va_copy="no"])
 )
if test "$ac_cv_c___va_copy" = "yes"
then
    AC_DEFINE(HAVE___VA_COPY, 1, [Define if we have __va_copy])
fi

# Options
# =========================================

QROUTER_LIB_DIR="share/qrouter"
AC_ARG_WITH(libdir,
[  --with-libdir=DIR           path to qrouter default config files], [
   QROUTER_LIB_DIR=$withval
], [])

# Force warnings to stop compilation.  Use
# this only for development cleanup.
# =========================================

# if test "$GCC" = "yes" ; then
#     CFLAGS="${CFLAGS} -Wall -Werror"
# fi

# Interpreter Options
# =========================================

qrouter_with_tcl="yes"
qrouter_with_tk="yes"
qrouter_with_tcl_includes=""
qrouter_with_tk_includes=""
qrouter_with_tcl_libraries=""
qrouter_with_tk_libraries=""

usingTcl=1
stub_defs=""

AC_ARG_WITH(tcl,
[ --with-tcl=DIR	Find tclConfig.sh in DIR], [
   qrouter_with_tcl=$withval
   if test "$withval" = "no" -o "$withval" = "NO"; then
      usingTcl=
   fi
], )

#-----------------------------------------------------
# SHDLIB_EXT needs to be defined outside of the
# Tcl/Tk environment, otherwise the Makefile
# target can't differentiate between qrouter and
# qrouter.so
#-----------------------------------------------------

case $target in
   *-hpux*)
      SHDLIB_EXT=".sl"
      SHDLIB_EXT_ALT=".sl"
      ;;
   *cygwin*)
      SHDLIB_EXT=".dll"
      SHDLIB_EXT_ALT=".dll.a"
      ;;
   *darwin*)
      SHDLIB_EXT=".dylib"
      SHDLIB_EXT_ALT=".dylib"
      ;;
   *)
      SHDLIB_EXT=".so"
      SHDLIB_EXT_ALT=".so"
      ;;
esac

dnl ----------------------------------------------------------------
dnl Do our best to find Tcl/Tk.  If we can't, then flag a warning
dnl and don't set the usingTcl variable.
dnl
dnl This has been broken up into a number of sections, each of which
dnl depends independently on the setting of usingTcl.
dnl ----------------------------------------------------------------

AC_ARG_WITH(tk,		[  --with-tk=DIR	   Find tkConfig.sh in DIR],
  qrouter_with_tk=$withval)
AC_ARG_WITH(tclincls,	[  --with-tclincls=DIR	   Find tcl.h in DIR],
  qrouter_with_tcl_includes=$withval)
AC_ARG_WITH(tkincls,	[  --with-tkincls=DIR	   Find tk.h in DIR],
  qrouter_with_tk_includes=$withval)
AC_ARG_WITH(tcllibs,	[  --with-tcllibs=DIR	   Find Tcl library in DIR],
  qrouter_with_tcl_libraries=$withval)
AC_ARG_WITH(tklibs,	[  --with-tklibs=DIR	   Find Tk library in DIR],
  qrouter_with_tk_libraries=$withval)

# -----------------------------------------------------------------------
# Find the Tcl build configuration file "tclConfig.sh"
# -----------------------------------------------------------------------

if test $usingTcl ; then
  TCL_INC_DIR="."
  TK_INC_DIR="."

  AC_MSG_CHECKING([for tclConfig.sh])
  tcl_config_sh=""

  if test "$qrouter_with_tcl" = "no" ; then
    qrouter_with_tcl=""
  elif test "$qrouter_with_tcl" != "yes" ; then
    #
    # Verify that a tclConfig.sh file exists in the directory specified
    # by --with-tcl.
    #
    for dir in \
     $qrouter_with_tcl
    do
      if test -r "$dir/tclConfig.sh" ; then
        tcl_config_sh="$dir/tclConfig.sh"
        break
      elif test -r "$dir/lib/tclConfig.sh" ; then
        tcl_config_sh="$dir/lib/tclConfig.sh"
        break
      elif test -r "$dir/unix/tclConfig.sh" ; then
        tcl_config_sh="$dir/unix/tclConfig.sh"
        break
      fi
    done
  else
    #
    # Otherwise, search for Tcl configuration file.
    #

    #  1. Search previously named locations.

    for dir in \
     $ac_default_prefix \
     $exec_prefix
    do
      if test -r "$dir/tclConfig.sh" ; then
        tcl_config_sh="$dir/tclConfig.sh"
        break
      elif test -r "$dir/lib/tclConfig.sh" ; then
        tcl_config_sh="$dir/lib/tclConfig.sh"
        break
      elif test -r "$dir/unix/tclConfig.sh" ; then
        tcl_config_sh="$dir/unix/tclConfig.sh"
        break
      fi
    done

    #  2. Search standard locations.

    if test "x$tcl_config_sh" = "x" ; then
      for dir in \
       `ls -dr /usr/local/tcl/tcl[[7-9]].[[0-9]]* 2>/dev/null` \
       /usr/local/tcl \
       /usr/local/lib \
       /usr/local \
       `ls -dr /usr/lib/tcl[[7-9]].[[0-9]]* 2>/dev/null` \
       `ls -dr /usr/share/tcltk/tcl[[7-9]].[[0-9]]* 2>/dev/null` \
       /sw/lib \
       /usr/lib \
       /usr/lib64 \
       /usr
      do
        if test -r "$dir/tclConfig.sh" ; then
          tcl_config_sh="$dir/tclConfig.sh"
          break
        elif test -r "$dir/lib/tclConfig.sh" ; then
          tcl_config_sh="$dir/lib/tclConfig.sh"
          break
        fi
      done
    fi
  fi

  AC_MSG_RESULT([${tcl_config_sh}])

  if test "x$tcl_config_sh" = "x" ; then
    echo "Can't find Tcl configuration script \"tclConfig.sh\""
    echo "Reverting to non-Tcl compilation"
    usingTcl=
  fi
fi

# -----------------------------------------------------------------------
# Find the Tk build configuration file "tkConfig.sh"
# -----------------------------------------------------------------------

if test $usingTcl ; then

  AC_MSG_CHECKING([for tkConfig.sh])
  tk_config_sh=""
  if test "$qrouter_with_tk" != "yes"; then
    #
    # Verify that a tkConfig.sh file exists in the directory specified
    # by --with-tcl or --with-tk.
    #
    for dir in \
     $qrouter_with_tk \
     $qrouter_with_tcl
    do
      if test -r "$dir/tkConfig.sh" ; then
        tk_config_sh="$dir/tkConfig.sh"
        break
      elif test -r "$dir/lib/tkConfig.sh" ; then
        tk_config_sh="$dir/lib/tkConfig.sh"
        break
      elif test -r "$dir/unix/tkConfig.sh" ; then
        tk_config_sh="$dir/unix/tkConfig.sh"
        break
      fi
    done
  else
    #
    # Search for Tk configuration file.
    #

    #
    #  1. Search previously named locations.
    #
    for dir in \
     $ac_default_prefix \
     $exec_prefix
    do
      if test -r "$dir/tkConfig.sh" ; then
        tk_config_sh="$dir/tkConfig.sh"
        break
      elif test -r "$dir/lib/tkConfig.sh" ; then
        tk_config_sh="$dir/lib/tkConfig.sh"
        break
      elif test -r "$dir/unix/tkConfig.sh" ; then
        tk_config_sh="$dir/unix/tkConfig.sh"
        break
      fi
    done
    #
    #  2. Search standard locations.
    #
    if test "x$tk_config_sh" = "x" ; then
      for dir in \
       `ls -dr /usr/local/tcl/tcl[[7-9]].[[0-9]]* 2>/dev/null` \
       `ls -dr /usr/local/tk/tk[[7-9]].[[0-9]]* 2>/dev/null` \
       /usr/local/tcl \
       /usr/local/lib \
       /sw/lib \
       /usr/local \
       `ls -dr /usr/share/tcltk/tk[[7-9]].[[0-9]]* 2>/dev/null` \
       `ls -dr /usr/lib/tcl[[7-9]].[[0-9]]* 2>/dev/null` \
       `ls -dr /usr/lib/tk[[7-9]].[[0-9]]* 2>/dev/null` \
       ${x_libraries} \
       /usr/lib \
       /usr/lib64 \
       /usr
      do
        if test -r "$dir/tkConfig.sh" ; then
          tk_config_sh="$dir/tkConfig.sh"
          break
        elif test -r "$dir/lib/tkConfig.sh" ; then
          tk_config_sh="$dir/lib/tkConfig.sh"
          break
        fi
      done
    fi
  fi
  AC_MSG_RESULT([${tk_config_sh}])

  if test "x$tk_config_sh" = "x" ; then
    echo "can't find Tk configuration script \"tkConfig.sh\""
    echo "Reverting to non-Tcl compilation"
    usingTcl=
  fi
fi

# -----------------------------------------------------------------------
# Source in the Tcl/Tk configuration scripts.
# -----------------------------------------------------------------------

if test $usingTcl ; then
  . $tcl_config_sh
  . $tk_config_sh

  # Should probably trust the config file contents, but this configure
  # file checks the Tcl and Tk include and lib directories.  Since
  # the config file doesn't separate out the libraries from the strings
  # passed to the compiler/linker, do it manually here.
  #
  # Extract TCL_LIB_DIR from TCL_LIB_SPEC
  # Extract TK_LIB_DIR from TK_LIB_SPEC
  # Extract TCL_INC_DIR from TCL_INCLUDE_SPEC
  # Extract TK_INC_DIR from TK_INCLUDE_SPEC
  #
  # These will be the defaults unless overridden by configure command line

  tmpstr=${TCL_LIB_SPEC#*-L}
  TCL_LIB_DIR=${tmpstr% -l*}
  tmpstr=${TK_LIB_SPEC#*-L}
  TK_LIB_DIR=${tmpstr% -l*}
  TCL_INC_DIR=${TCL_INCLUDE_SPEC#*-I}
  TK_INC_DIR=${TK_INCLUDE_SPEC#*-I}

  if test "$TCL_VERSION" = "7.6" -a "$TK_VERSION" = "4.2" ; then
    :
  elif test "$TCL_VERSION" = "7.5" -a "$TK_VERSION" = "4.1" ; then
    :
  elif test "$TCL_VERSION" = "$TK_VERSION" ; then
    :
  else
    echo "Mismatched Tcl/Tk versions ($TCL_VERSION != $TK_VERSION)"
    echo "Reverting to non-Tcl compile"
    usingTcl=
  fi
fi

if test $usingTcl ; then
  if test "x${qrouter_with_tcl_includes}" != "x" ; then
    if test -r "${qrouter_with_tcl_includes}/tcl.h" ; then
      TCL_INC_DIR=${qrouter_with_tcl_includes}
    else
      echo "Can't find tcl.h in \"${qrouter_with_tcl_includes}\""
      echo "Reverting to non-Tcl compile"
      usingTcl=
    fi
  else
    for dir in \
     ${TCL_PREFIX}/include/tcl${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION} \
     ${TCL_PREFIX}/include \
     ${TCL_SRC_DIR}/generic \
     ${TCL_INC_DIR}
    do
      if test -r "$dir/tcl.h" ; then
        TCL_INC_DIR=$dir
        break
      fi
    done
    if test "x${TCL_INC_DIR}" = "x" ; then
      echo "Can't find tcl.h header file"
      echo "Reverting to non-Tcl compile"
      usingTcl=
    fi
  fi
fi

if test $usingTcl ; then
  if test "x${qrouter_with_tk_includes}" != "x" ; then
    if test -r "${qrouter_with_tk_includes}/tk.h" ; then
      TK_INC_DIR=${qrouter_with_tk_includes}
    else
      echo "Can't find tk.h in \"${qrouter_with_tk_includes}\""
      echo "Reverting to non-Tcl compile"
      usingTcl=
    fi
  else
    for dir in \
     ${TK_PREFIX}/include/tk${TK_MAJOR_VERSION}.${TK_MINOR_VERSION} \
     ${TK_PREFIX}/include \
     ${TK_SRC_DIR}/generic \
     ${TK_INC_DIR} \
     ${TCL_INC_DIR}
    do
      if test -r "$dir/tk.h" ; then
        TK_INC_DIR=$dir
        break
      fi
    done
    if test "x${TK_INC_DIR}" = "x" ; then
      echo "Can't find tk.h header file"
      echo "Reverting to non-Tcl compile"
      usingTcl=
    fi
  fi
fi

if test $usingTcl ; then
  case $target in
    *-sunos4*|*-*-netbsd|NetBSD-*|FreeBSD-*|OpenBSD-*)
      TCL_LIB_NAME="tcl${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}"
      TK_LIB_NAME="tk${TK_MAJOR_VERSION}${TK_MINOR_VERSION}"
      ;;
    *)
      TCL_LIB_NAME="tcl${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION}"
      TK_LIB_NAME="tk${TK_MAJOR_VERSION}.${TK_MINOR_VERSION}"
      ;;
  esac

  loclib=`echo ${TCL_LIB_SPEC} | sed -e 's/.*-L//' -e 's/ .*//'`

  if test "x${TCL_LIB_SPEC}" = "x" ; then
     TCL_LIB_SPEC="-l${TCL_LIB_NAME}"
  fi
  if test "x${TK_LIB_SPEC}" = "x" ; then
     TK_LIB_SPEC="-l${TK_LIB_NAME}"
  fi


# Find the version of "wish" that corresponds to TCL_EXEC_PREFIX
# We really ought to run "ldd" to confirm that the linked libraries match.

  AC_MSG_CHECKING([for wish executable])
  for dir in \
   ${TK_EXEC_PREFIX}/bin \
   ${TK_EXEC_PREFIX}
  do
    for wishexe in \
      wish \
      wish${TK_VERSION} \
      wish.exe \
      wish${TK_VERSION}.exe
    do
      if test -r "$dir/$wishexe" ; then
        WISH_EXE=$dir/$wishexe
        break
      fi
    done
    if test "x${WISH_EXE}" != "x" ; then
      break
    fi
  done
  if test "x${WISH_EXE}" = "x" ; then
    echo "Warning: Can't find executable for \"wish\".  You may have to"
    echo "manually set the value for WISH_EXE in the netgen startup script."
    AC_MSG_RESULT(no)
  else
    AC_MSG_RESULT([${WISH_EXE}])
  fi

  if test "x${qrouter_with_tcl_libraries}" != "x" ; then
    for libname in \
     "${qrouter_with_tcl_libraries}/lib${TCL_LIB_NAME}${SHDLIB_EXT}" \
     "${qrouter_with_tcl_libraries}/lib${TCL_LIB_NAME}${SHDLIB_EXT_ALT}"
    do
      if test -r "$libname" ; then
        TCL_LIB_DIR="${qrouter_with_tcl_libraries}"
        break
      fi
    done

    if test "x${TCL_LIB_DIR}" = "x" ; then
      echo "Can't find tcl library in \"${qrouter_with_tcl_libraries}\""
      echo "Reverting to non-Tcl compile"
      usingTcl=
    fi
  else
    for libpfix in "lib64" "lib"
    do
      libname1="${TCL_EXEC_PREFIX}/${libpfix}/${DEB_HOST_MULTIARCH}/lib${TCL_LIB_NAME}${SHDLIB_EXT}"
      libname2="${TCL_EXEC_PREFIX}/${libpfix}/${DEB_HOST_MULTIARCH}/lib${TCL_LIB_NAME}${SHDLIB_EXT_ALT}"
      if test -r "$libname1" -o -r "$libname2" ; then
        TCL_LIB_DIR="${TCL_EXEC_PREFIX}/${libpfix}"
        break
      fi
    done
    if test "x${TCL_LIB_DIR}" = "x" ; then
      echo "Can't find tcl library"
      echo "Reverting to non-Tcl compile"
      usingTcl=
    fi
  fi
fi

if test $usingTcl ; then
  if test "x${qrouter_with_tk_libraries}" != "x" ; then
    for libname in \
     "${qrouter_with_tk_libraries}/lib${TK_LIB_NAME}${SHDLIB_EXT}" \
     "${qrouter_with_tk_libraries}/lib${TK_LIB_NAME}${SHDLIB_EXT_ALT}"
    do
      if test -r "$libname" ; then
        TK_LIB_DIR="${qrouter_with_tk_libraries}"
        break
      fi
    done
    if test "x${TK_LIB_DIR}" = "x" ; then
      echo "Can't find tk library in \"${qrouter_with_tk_libraries}\""
      echo "Reverting to non-Tcl compile"
      usingTcl=
    fi
  else
    for libpfix in "lib64" "lib"
    do
      libname1="${TK_EXEC_PREFIX}/${libpfix}/${DEB_HOST_MULTIARCH}/lib${TK_LIB_NAME}${SHDLIB_EXT}"
      libname2="${TK_EXEC_PREFIX}/${libpfix}/${DEB_HOST_MULTIARCH}/lib${TK_LIB_NAME}${SHDLIB_EXT_ALT}"
      if test -r "$libname1" -o -r "$libname2" ; then
        TK_LIB_DIR="${TK_EXEC_PREFIX}/${libpfix}"
        break
      fi
    done
    if test "x${TK_LIB_DIR}" = "x" ; then
      echo "Can't find tk library"
      echo "Reverting to non-Tcl compile"
      usingTcl=
    fi
  fi
fi

dnl ----------------------------------------------------
dnl End of Tcl/Tk search
dnl ----------------------------------------------------

AC_ARG_ENABLE(memdebug,
[  --enable-memdebug            enable memory debugging], [
   if test "x$qrouter_with_tcl" = "x" ; then  
      LIBS="${LIBS} -lefence"
   else
      AC_DEFINE(TCL_MEM_DEBUG)
   fi
],)

dnl Check for X enabled/disabled

AC_PATH_XTRA
if test "x$no_x" = "x"; then
  usingX11=1
else
  echo Cannot find X11---will compile anyway.
  echo Graphics will be disabled
  if test $usingTcl ; then
    echo "Cannot compile TCL version without X11, disabling."
    usingTcl=
  fi
fi

AC_CHECK_LIB(Xt, XtToolkitInitialize,,[
AC_CHECK_LIB(Xt, XtDisplayInitialize,,,-lSM -lICE -lXpm -lX11)])
AC_CHECK_HEADERS(sys/mman.h)

dnl ----------------------------------------------------------------
dnl Once we're sure what, if any, interpreter is being compiled,
dnl set all the appropriate definitions.  For Tcl/Tk, override
dnl the default install targets: allows compiling tcl version with
dnl "make" instead of requiring "make tcl"
dnl ----------------------------------------------------------------

if test $usingTcl ; then
  ALL_TARGET="tcl"
  INSTALL_TARGET="install-tcl"
  AC_DEFINE(TCL_QROUTER)
  stub_defs="$stub_defs -DUSE_TCL_STUBS -DUSE_TK_STUBS"
else
  ALL_TARGET="nointerp"
  INSTALL_TARGET="install-nointerp"
  programs="$programs qrouter"
fi

dnl ----------------------------------------------------------------
dnl Define system-specific settings
dnl ----------------------------------------------------------------

case $target in
  *-linux*)
    AC_DEFINE(LINUX)
    AC_DEFINE(SYSV)
    dnl 64-bit support
    case $target in
        *x86_64*)
	    CPPFLAGS="$CPPFLAGS -m64 -fPIC"
            ;;
    esac
    ;;
  *solaris*)
    AC_DEFINE(SYSV)
    ;;
  *irix*)
    AC_DEFINE(SYSV)
    AC_DEFINE(IRIX)
    AC_DEFINE(_BSD_SIGNALS)
    ;;
  *sysv*)
    AC_DEFINE(SYSV)
    ;;
  *cygwin*)
    AC_DEFINE(CYGWIN)
    AC_DEFINE(i386)
    ;; 
  *darwin*)
    if test "$CPP" = "cc -E" ; then
       CPPFLAGS="$CPPFLAGS -no-cpp-precomp"
    fi
    ;;
esac
# -----------------------------------------------------------------------
# Tcl/Tk configuration
# -----------------------------------------------------------------------

if test $usingTcl ; then
   LIB_SPECS_NOSTUB="${LIB_SPECS}"

# -----------------------------------------------------------------------
#
# Tk libraries and header files
#
# -----------------------------------------------------------------------
  if test "${TK_INC_DIR}" != "/usr/include" ; then
    INC_SPECS="${INC_SPECS} -I${TK_INC_DIR}"
  fi
  if test "${TK_LIB_DIR}" = "/usr/lib" -o \
        "${TK_LIB_DIR}" = "/usr/lib64" ; then
    LIB_SPECS_NOSTUB="${LIB_SPECS_NOSTUB} ${TK_LIB_SPEC}"
    LIB_SPECS="${LIB_SPECS} ${TK_STUB_LIB_SPEC}"
  else
    LIB_SPECS_NOSTUB="${LIB_SPECS_NOSTUB} -L${TK_LIB_DIR} ${TK_LIB_SPEC}"
    LIB_SPECS="${LIB_SPECS} -L${TK_LIB_DIR} ${TK_STUB_LIB_SPEC}"
    if test "x${loader_run_path}" = "x" ; then
      loader_run_path="${TK_LIB_DIR}"
    else
      loader_run_path="${TK_LIB_DIR}:${loader_run_path}"
    fi
  fi

# -----------------------------------------------------------------------
#
# Tcl libraries and header files
#
# Add a header file directory specification only if the Tcl headers reside
# in a different directory from Tk's.
#
## -----------------------------------------------------------------------
  if test "${TCL_INC_DIR}" != "/usr/include" -a \
        "${TCL_INC_DIR}" != "${TK_INC_DIR}" ; then
    INC_SPECS="${INC_SPECS} -I${TCL_INC_DIR}"
  fi

  if test "${TCL_LIB_DIR}" = "/usr/lib" -o \
        "${TCL_LIB_DIR}" = "/usr/lib64" -o \ 
        "${TCL_LIB_DIR}" = "${TK_LIB_DIR}" ; then
    LIB_SPECS_NOSTUB="${LIB_SPECS_NOSTUB} ${TCL_LIB_SPEC}"
    LIB_SPECS="${LIB_SPECS} ${TCL_STUB_LIB_SPEC}"
  else
    LIB_SPECS_NOSTUB="${LIB_SPECS_NOSTUB} -L${TCL_LIB_DIR} ${TCL_LIB_SPEC}"
    LIB_SPECS="${LIB_SPECS} -L${TCL_LIB_DIR} ${TCL_STUB_LIB_SPEC}"
    if test "x${loader_run_path}" = "x" ; then
      loader_run_path="${TCL_LIB_DIR}"
    else
      loader_run_path="${TCL_LIB_DIR}:${loader_run_path}"
    fi
  fi

#--------------------------------------------------------------------
#
# Check if we can generate shared libraries on this system.  Set flags
# to generate shared libraries for systems that we know about.  Start
# with the values found in tclConfig.sh, make changes as we know about
# the different systems.
#
#--------------------------------------------------------------------

# Initialize shared library build variables

  SHLIB_LD=""
  LDDL_FLAGS="-shared"
  SHDLIB_EXT=".so"
  EXTRA_LIB_SPECS=""

  build_shared="yes"

  case $target in
    *-bsdi2*|*-bsdi3*)
      LD="shlicc"
      LDDL_FLAGS="-r"
      EXTRA_LIB_SPECS="-ldl"
      ;;

    *darwin*)
      SHDLIB_EXT=".dylib"
      LDDL_FLAGS="-dynamiclib -flat_namespace -undefined suppress -noprebind"
      LDFLAGS="${LDFLAGS} ${LIB_SPECS}"
      CFLAGS="${CFLAGS} ${X_CFLAGS} ${INC_SPECS} -I/sw/include -fno-common"
      ;;

    *cygwin*)
      SHDLIB_EXT=".dll"
      AC_DEFINE(USE_DL_IMPORT)
      LDDL_FLAGS='-shared -Wl,--enable-auto-image-base'
      if test "x${loader_run_path}" != "x" ; then
        LD_RUN_PATH="${LD_RUN_PATH} -Wl,-rpath,${loader_run_path}"
      fi
      ld_extra_libs=${LIB_SPECS}
      sub_extra_libs='-L${QROUTERDIR}/qrouter -ltclqrouter'
      ;;

    *-bsdi4*)
      SHLIB_CFLAGS="-export-dynamic -fPIC"
      LDDL_FLAGS='-shared -Wl,-E -Wl,-soname,$@'
      ;;

    *-linux*)
      LDDL_FLAGS='-shared -Wl,-soname,$@'
      if test "x${loader_run_path}" != "x" ; then
        LD_RUN_PATH="${LD_RUN_PATH} -Wl,-rpath,${loader_run_path}"
      fi
      LDFLAGS=""
      EXTRA_LIB_SPECS="-ldl"
      ;;

    *-freebsd*)
      # Not available on all versions:  check for include file.
      SHLIB_CFLAGS="-fpic"
      LDDL_FLAGS="-shared ${LIB_SPECS}"
      CFLAGS="${CFLAGS} -l/usr/X11R6/include"
      ;;

    *-netbsd*|*-openbsd*)
      # Not available on all versions:  check for include file.
      AC_CHECK_HEADER(dlfcn.h, test_ok=yes, test_ok=no)
      if test "$test_ok" = yes; then
        SHLIB_CFLAGS="-fpic"
        LDDL_FLAGS="-Bshareable -x ${LIB_SPEC}"
      fi
      ;;

  esac

# If we're running gcc, then set SHLIB_CFLAGS flags for compiling
# shared libraries for gcc, instead of those of the vendor's compiler.

  if test "$GCC" = "yes" ; then
    case $target in
      *cygwin*)
        ;;
      *)
        SHLIB_CFLAGS="-fPIC"
        ;;
    esac
  fi
  if test "$with_gnu_ld" = "yes" ; then
    LDDL_FLAGS="${LDDL_FLAGS} -Wl,--version-script=symbol.map"
  fi

  AC_SUBST(SHDLIB_EXT)
  AC_SUBST(SHLIB_LD)
  AC_SUBST(LD)
  AC_SUBST(LDDL_FLAGS)
  AC_SUBST(SHLIB_LIB_SPECS)
  AC_SUBST(stub_defs)

  AC_SUBST(EXTRA_LIB_SPECS)
  AC_SUBST(LDFLAGS)
  AC_SUBST(INC_SPECS)
  AC_SUBST(LIB_SPECS)
  AC_SUBST(LIB_SPECS_NOSTUB)
  AC_SUBST(TCL_LIB_DIR)
  AC_SUBST(TK_LIB_DIR)
  AC_SUBST(WISH_EXE)

  AC_SUBST(X_LIBS)
  AC_SUBST(X_EXTRA_LIBS)
  AC_SUBST(X_PRE_LIBS)
  AC_SUBST(X_CFLAGS)
  AC_SUBST(SHLIB_CFLAGS)
  AC_SUBST(LD_RUN_PATH)

fi

dnl Substitute all variables

AC_SUBST(CPPFLAGS)
AC_SUBST(CFLAGS)
AC_SUBST(STDLIBS)

AC_SUBST(ALL_TARGET)
AC_SUBST(INSTALL_TARGET)

AC_SUBST(QROUTER_LIB_DIR)

AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
AC_DEFINE_UNQUOTED(REVISION, "$REVISION")

AC_OUTPUT(Makefile)