summaryrefslogtreecommitdiff
path: root/configure.in
blob: a11d81755c03dfa39407beb57be1ae6df2a44c45 (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
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
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
dnl Process this file with autoconf to produce a configure script.

AC_INIT(xcircuit.c,, xcircuit-dev@lists.sourceforge.net)
AC_PREREQ(2.52)
AC_CONFIG_SRCDIR(xcircuit.c)

AC_CANONICAL_SYSTEM

dnl this call will define PACKAGE and VERSION
dnl please use this as the primary reference for the version number
PACKAGE=xcircuit

VERSION=`cat ./VERSION | cut -d. -f1-2`
AM_INIT_AUTOMAKE(${PACKAGE}, ${VERSION})

dnl Initialize some variables
SUBDIRS=
SUBLIB=
STDLIBS=
XCIRCUIT_TARGET=
ALL_TARGET="undefined-target"
INSTALL_TARGET="undefined-install-target"
REVISION=`cat ./VERSION | cut -d. -f3`
INTERPRETER=NOINTERP
HAVE_LGF=NOFORMATS

LIB_SPECS=""
WISH_EXE=""
SHLIB_CFLAGS=""

dnl Default is to use Tcl; if it can't be found, then flag a warning
dnl and revert to the non-Tcl version.

dnl pass the version string on the the makefiles
AC_SUBST(PACKAGE)
AC_SUBST(VERSION)
AC_SUBST(REVISION)

dnl Setup for automake in subdirectories
AC_PROG_MAKE_SET

dnl Checks for programs.
AC_PROG_CC
AC_ISC_POSIX
dnl AM_C_PROTOTYPES
if test "x$U" != "x"; then
  AC_MSG_ERROR(Compiler not ANSI compliant)
fi
AC_PROG_INSTALL
AC_PROG_RANLIB

dnl GNU M4 is preferred due to some of the option switches.
AC_PATH_PROGS([M4], [gm4 gnum4 m4],)

case "$target_os" in
	*cygwin*)
		;;
	*)
		AC_CHECK_LIB(m, sin)
		;;		
esac    

dnl check size of pointer for correct behavior on 64-bit systems
AC_CHECK_SIZEOF([void *], 4)
AC_CHECK_SIZEOF([unsigned int], 4)
AC_CHECK_SIZEOF([unsigned long], 8)
AC_CHECK_SIZEOF([unsigned long long], 16)

dnl check for X libraries and include files
AC_PATH_XTRA
CPPFLAGS="${CPPFLAGS} ${X_CFLAGS}"
LDFLAGS="${LDFLAGS} ${X_LIBS}"
LIBS="${X_PRE_LIBS} ${LIBS} -lX11"
AC_CHECK_LIB(Xt, XtToolkitInitialize,,[
AC_CHECK_LIB(Xt, XtDisplayInitialize,,,-lSM -lICE -lXpm -lX11)])

dnl Check for required header files
AC_HEADER_STDC

dnl Need either setenv or putenv
AC_CHECK_FUNCS(setenv putenv)

dnl Check for vfork
AC_CHECK_FUNC(vfork)

dnl Check for <dirent.h>
AC_CHECK_HEADERS(dirent.h)

dnl Check for lib64.  This is a quick hack for Fedora Core on the
dnl AMD Opteron;  don't know if it works with others.
case $target in
  x86_64-*)
    AC_MSG_CHECKING([for 64-bit X11 libraries])
    AC_CHECK_FILE([/usr/X11R6/lib64], [
	LDFLAGS="-L/usr/X11R6/lib64 ${LDFLAGS}"
    ], )
  ;;
esac

dnl Check for valid cflag "-Wno-pointer-sign"
AC_MSG_CHECKING(if -Wno-pointer-sign accepted in CFLAGS)
ac_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Wno-pointer-sign"
AC_TRY_COMPILE(,[
int foo;
foo = 0],[
  AC_MSG_RESULT(yes)],[
  CFLAGS="$ac_save_CFLAGS"
  AC_MSG_RESULT(no)])

dnl Check for Flate compression routines
AC_CHECK_LIB(z, deflate,,,-lz)

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

AC_MSG_CHECKING(if u_char defined)
AC_TRY_COMPILE([#include <sys/types.h>],[
u_char foo;
foo = 0],[
  AC_DEFINE(HAVE_U_CHAR)
  AC_MSG_RESULT(yes)],
  AC_MSG_RESULT(no))

dnl Enable compile-time Optimization?  Disable by default for debugging
AC_ARG_ENABLE(optimize,
[  --enable-optimize enable compile-time optimizer flag -O2], , [
   CFLAGS=`echo $CFLAGS | sed -e "s/ -O2//"`
])

dnl check for Xpm library
AC_ARG_WITH(xpm,
[  --with-xpm=DIR          use Xpm include/library files in DIR], [
  if test "$withval" != "no" -a "$withval" != "yes"; then
    CPPFLAGS="${CPPFLAGS} -I$withval/include"
    LDFLAGS="${LDFLAGS} -L$withval/lib"
  fi
])

AC_CHECK_HEADERS(X11/xpm.h,
  AC_CHECK_LIB(Xpm, XpmCreateImageFromData, [
    LIBS="${LIBS} -lXpm"
    AC_DEFINE(HAVE_XPM)], [
    AC_MSG_WARN(Xpm library not found)], -lX11),
  AC_MSG_WARN(Xpm header not found))

dnl Check for GNU ld.  This needs to be qualified for Solaris, which
dnl may use gcc for the C compiler but not for the linker.

dnl check if the linker is a GNU 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 || xc_with_gnu_ld=yes, xc_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.
    xc_with_gnu_ld=unknown
    ;;
  esac
elif test "$xc_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 "$xc_with_gnu_ld" != no && break
      else
        test "$xc_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])
xc_with_gnu_ld=$ac_cv_prog_gnu_ld
])

AC_PROG_LD

dnl --- Enable TCL by default

xc_with_tcl="yes"
xc_with_tk="yes"
xc_with_tcl_includes=""
xc_with_tk_includes=""
xc_with_tcl_libraries=""
xc_with_tk_libraries=""
xc_with_cairo="yes"

dnl -----------------------------------------------------------------------
dnl --- Cairo library
dnl -----------------------------------------------------------------------

AC_ARG_WITH([cairo],
  [AS_HELP_STRING([--with-cairo],
    [Use cairo graphics library @<:@default=yes@:>@])],
  [
    xc_with_cairo=$withval
    if test "$withval" == "no" -o "$withval" == "NO"; then
        xc_with_cairo=""
    fi
  ], ) 

if test "x$xc_with_cairo" != "x" ; then
  AC_DEFINE([HAVE_CAIRO])
  PKG_CHECK_MODULES([cairo], [cairo])
  PKG_CHECK_MODULES([fontconfig], [fontconfig])
  AC_CHECK_HEADERS([ghostscript/gdevdsp.h],
    [
	GS_LIBS=-lgs
	AC_DEFINE([HAVE_GS])
    ],
    [
        AC_MSG_WARN([Building xcircuit without ghostscript rendering])
	AC_MSG_WARN([Install the ghostscript-devel package to solve this])
    ]
  )
fi

dnl -----------------------------------------------------------------------
dnl --- Tcl/Tk support
dnl -----------------------------------------------------------------------
          
AC_ARG_WITH(tcl,
[  --with-tcl=DIR          Find tclConfig.sh in DIR], [
  xc_with_tcl=$withval
  if test "$withval" == "no" -o "$withval" == "NO"; then
      xc_with_tcl=""
  fi
], ) 

dnl -----------------------------------------------------------------------
dnl If TCL is not disabled, do our best to find it
dnl -----------------------------------------------------------------------

AC_ARG_WITH(tk,		[  --with-tk=DIR           Find tkConfig.sh in DIR],
  xc_with_tk=$withval)
AC_ARG_WITH(tclincls,   [  --with-tclincls=DIR     Find tcl.h in DIR],
  xc_with_tcl_includes=$withval)
AC_ARG_WITH(tkincls,	[  --with-tkincls=DIR      Find tk.h in DIR],
  xc_with_tk_includes=$withval)
AC_ARG_WITH(tcllibs,	[  --with-tcllibs=DIR      Find Tcl library in DIR],
  xc_with_tcl_libraries=$withval)
AC_ARG_WITH(tklibs,	[  --with-tklibs=DIR       Find Tk library in DIR],
  xc_with_tk_libraries=$withval)

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

if test "x$xc_with_tcl" != "x" ; then

  TCL_INC_DIR="."
  TK_INC_DIR="."

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

  if test "$xc_with_tcl" = "no" ; then
    xc_with_tcl=""
  elif test "$xc_with_tcl" != "yes" ; then
    #
    # Verify that a tclConfig.sh file exists in the directory specified 
    # by --with-tcl. 
    #
    for dir in \
     $xc_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
      fi
    done
  else 
    #
    # Otherwise, search for Tcl configuration file.  
    #

    #  1. Search previously named locations.

    for dir in \
     $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
      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/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"
    xc_with_tcl=""
  fi
fi

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

if test "x$xc_with_tcl" != "x" ; then
  AC_MSG_CHECKING([for tkConfig.sh])
  tk_config_sh=""
  if test "$xc_with_tk" != "yes"; then
    #
    # Verify that a tkConfig.sh file exists in the directory specified 
    # by --with-tcl or --with-tk. 
    #
    for dir in \
     $xc_with_tk \
     $xc_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
      fi
    done
  else 
    #
    # Search for Tk configuration file.  
    #

    #
    #  1. Search previously named locations.
    # 
    for dir in \
     $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
      fi
    done
    #
    #  2. Search standard locations.
    # 
    if test "x$tk_config_sh" = "x" ; then
      for dir in \
       /usr/local \
       /usr \
       `ls -dr /usr/local/lib/tk[[7-9]].[[0-9]]* 2>/dev/null` \
       `ls -dr /usr/lib/tk[[7-9]].[[0-9]]* 2>/dev/null` \
       `ls -dr /usr/local/tk/tk[[7-9]].[[0-9]]* 2>/dev/null` \
       `ls -dr /usr/local/tk[[7-9]].[[0-9]]* 2>/dev/null` \
       /usr/local/tk \
       `ls -dr /usr/local/lib/tcl[[7-9]].[[0-9]]* 2>/dev/null` \
       `ls -dr /usr/lib/tcl/tk[[7-9]].[[0-9]]* 2>/dev/null` \
       `ls -dr /usr/local/tcl/tcl[[7-9]].[[0-9]]* 2>/dev/null` \
       `ls -dr /usr/share/tcltk/tk[[7-9]].[[0-9]]* 2>/dev/null` \
       /sw/lib \
       /usr/lib \
       /usr/lib64 \
       ${x_libraries}
      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"
    xc_with_tcl=""
  fi
fi

# -----------------------------------------------------------------------
#
#	Source in the Tcl/Tk configuration scripts.  
#
#	This didn't work so well in the pre-8.5 days, but
#	seems to be okay now.
#
# -----------------------------------------------------------------------

if test "x$xc_with_tcl" != "x" ; 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}

  LIBS="${TCL_LIBS} ${LIBS}"

  if test "$TCL_VERSION" = "$TK_VERSION" ; then
    :
  else
    echo "Mismatched Tcl/Tk versions ($TCL_VERSION != $TK_VERSION)"
    echo "Reverting to non-Tcl compilation"
    xc_with_tcl=""
  fi
fi

# -----------------------------------------------------------------------
# Rely on TCL_INCLUDE_SPEC from tclConfig.sh unless "--with-tclincls"
# overrides.  With TCL_INCLUDE_SPEC, pull out TCL_INC_DIR
# -----------------------------------------------------------------------

if test "x$xc_with_tcl" != "x" ; then
  if test "x${xc_with_tcl_includes}" != "x" ; then
    if test -r "${xc_with_tcl_includes}/tcl.h" ; then
      TCL_INC_DIR=${xc_with_tcl_includes}
    elif test "x${TCL_INCLUDE_SPEC}" == "x" ; then
      echo "Can't find tcl.h in \"${xc_with_tcl_includes}\""
      echo "Reverting to non-Tcl compilation"
      xc_with_tcl=""
    fi
  elif test "x${TCL_INCLUDE_SPEC}" == "x" ; then
    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
        TCL_INCLUDE_SPEC="-I${TCL_INC_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 compilation"
      xc_with_tcl=""
    fi
  else
    TCL_INC_DIR=`echo ${TCL_INCLUDE_SPEC} | sed -e '/-I/s/-I//'`
  fi
fi

# -----------------------------------------------------------------------
# Rely on TK_INCLUDE_SPEC from tkConfig.sh unless "--with-tkincls"
# overrides.  With TK_INCLUDE_SPEC, pull out TK_INC_DIR
# -----------------------------------------------------------------------

if test "x$xc_with_tcl" != "x" ; then
  if test "x${xc_with_tk_includes}" != "x" ; then
    if test -r "${xc_with_tk_includes}/tk.h" ; then
      TK_INC_DIR=${xc_with_tk_includes}
    elif test "x${TK_INCLUDE_SPEC}" == "x" ; then
      echo "Can't find tk.h in \"${xc_with_tk_includes}\""
      echo "Reverting to non-Tcl compilation"
      xc_with_tcl=""
    fi
  elif test "x${TK_INCLUDE_SPEC}" == "x" ; then
    for dir in \
     ${TK_PREFIX}/include/tcl${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION} \
     ${TK_PREFIX}/include/tk${TK_MAJOR_VERSION}.${TK_MINOR_VERSION} \
     ${TK_PREFIX}/include \
     ${TK_SRC_DIR}/generic \
     ${TK_INC_DIR}
    do
      if test -r "$dir/tk.h" ; then
        TK_INC_DIR=$dir
        TK_INCLUDE_SPEC="-I${TK_INC_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 compilation"
      xc_with_tcl=""
    fi
  else
    TK_INC_DIR=`echo ${TK_INCLUDE_SPEC} | sed -e '/-I/s/-I//'`
  fi
fi

# --------------------------------------------------------------
# Rely on TCL_LIB_SPEC from tclConfig.sh unless "--with-tcllibs"
# overrides.  With TCL_LIB_SPEC, pull out TCL_LIB_DIR
# --------------------------------------------------------------

if test "x$xc_with_tcl" != "x" ; then
  if test "x${xc_with_tcl_libraries}" != "x" ; then
    TCL_LIB_SPEC=""
    for libname in \
     "${xc_with_tcl_libraries}/${TCL_LIB_FILE}" \
     "${xc_with_tcl_libraries}/lib${TCL_LIB_NAME}${SHDLIB_EXT}"
    do
      if test -r "$libname" ; then
        TCL_LIB_DIR="${xc_with_tcl_libraries}"
        break
      fi
    done
    if test "x${TCL_LIB_DIR}" == "x" ; then
      echo "Can't find tcl library in \"${xc_with_tcl_libraries}\""
      echo "Reverting to non-Tcl compile"
      xc_with_tcl=""
    fi
  elif test "x${TCL_LIB_SPEC}" == "x" ; then
    for libpfix in "lib64" "lib"
    do
      libname="${TCL_EXEC_PREFIX}/${libpfix}/lib${TCL_LIB_NAME}${SHDLIB_EXT}"
      if test -r "$libname" ; 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"
      xc_with_tcl=""
    fi
  else
    TCL_LIB_DIR=`echo ${TCL_LIB_SPEC} | sed -e '/-L/s/-L//' -e '/-l/s/-l.*//'`
  fi
fi

# --------------------------------------------------------------
# Rely on TK_LIB_SPEC from tkConfig.sh unless "--with-tklibs"
# overrides.  With TK_LIB_SPEC, pull out TK_LIB_DIR
# --------------------------------------------------------------

if test "x$xc_with_tcl" != "x" ; then
  if test "x${xc_with_tk_libraries}" != "x" ; then
    TK_LIB_SPEC=""
    for libname in \
     "${xc_with_tk_libraries}/${TK_LIB_FILE}" \
     "${xc_with_tk_libraries}/lib${TK_LIB_NAME}${SHDLIB_EXT}"
    do
      if test -r "$libname" ; then
        TK_LIB_DIR="${xc_with_tk_libraries}"
        break
      fi
    done
    if test "x${TK_LIB_DIR}" == "x" ; then
      echo "Can't find tk library in \"${xc_with_tk_libraries}\""
      echo "Reverting to non-Tcl compile"
      xc_with_tcl=""
    fi
  elif test "x${TK_LIB_SPEC}" == "x" ; then
    for libpfix in "lib64" "lib"
    do
      libname="${TK_EXEC_PREFIX}/${libpfix}/lib${TK_LIB_NAME}${SHDLIB_EXT}"
      if test -r "$libname" ; 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"
      xc_with_tcl=""
    fi
  else
    TK_LIB_DIR=`echo ${TCL_LIB_SPEC} | sed -e '/-L/s/-L//' -e '/-l/s/-l.*//'`
  fi
fi

#--------------------------------------------------------------------
# If TCL_LIB_SPEC and/or TK_LIB_SPEC do not exist, construct them
#--------------------------------------------------------------------

if test "x$xc_with_tcl" != "x" ; then
  if test "x${TCL_LIB_SPEC}" == "x" ; then
    case $target in
      *-sunos4*|*-*-netbsd|NetBSD-*|FreeBSD-*|*-*-openbsd*|OpenBSD-*)
        TCL_LIB_NAME="tcl${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}"
        ;;
      *)
        TCL_LIB_NAME="tcl${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION}"
        ;;
    esac
    TCL_LIB_SPEC="-L${TCL_LIB_DIR} -l${TCL_LIB_NAME}"
  fi

  if test "x${TK_LIB_SPEC}" == "x" ; then
    case $target in
      *-sunos4*|*-*-netbsd|NetBSD-*|FreeBSD-*|*-*-openbsd*|OpenBSD-*)
        TK_LIB_NAME="tk${TK_MAJOR_VERSION}${TK_MINOR_VERSION}"
        ;;
      *)
        TK_LIB_NAME="tk${TK_MAJOR_VERSION}.${TK_MINOR_VERSION}"
        ;;
    esac
    TK_LIB_SPEC="-L${TK_LIB_DIR} -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 xcircuit startup script."
    AC_MSG_RESULT(no)
  else
    AC_MSG_RESULT([${WISH_EXE}])
  fi

  # Have to define SHDLIB_EXT here even though we have to do it below, too.
  case $target in
     *-hpux*)
	SHDLIB_EXT=".sl"
	;;
     *cygwin*)
	SHDLIB_EXT=".dll.a"
	;;
     *-darwin*)
	SHDLIB_EXT=".dylib"
	;;
     *-openbsd*)
	SHDLIB_EXT=".so.${TCL_LIB_FILE##*.so.}"
	;;
     *)
	SHDLIB_EXT=".so"
	;;
  esac
fi

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

# -----------------------------------------------------------------------
# 
# Tk libraries and header files
#
# -----------------------------------------------------------------------

if test "x$xc_with_tcl" != "x" ; then
  INC_SPECS="${INC_SPECS} ${TCL_INCLUDE_SPEC} ${TK_INCLUDE_SPEC}"
  LIB_SPECS="${LIB_SPECS} ${TCL_LIB_SPEC} ${TK_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

  #--------------------------------------------------------------------
  #
  # 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

  if test "x${TCL_SHLIB_SUFFIX}" == "x" ; then
    SHDLIB_EXT=".so"
  else
    SHDLIB_EXT="${TCL_SHLIB_SUFFIX}"
  fi

  if test "x${TCL_SHLIB_LD}" == "x" ; then

    # Construct shared library build arguments the painful way
    # This is not expected to be necessary, so the number of
    # supported systems has been pared down to a minimum.

    LDDL_FLAGS="-shared"
    LD_RUN_PATH=""
    SHLIB_LD="${CC}"
    EXTRA_LIB_SPECS=""

    case $target in
      *-darwin*)
        SHDLIB_EXT=".dylib"
        SHLIB_LIB_SPECS="${LIB_SPECS}"
        if test "${xc_with_gnu_ld}" = "yes" ; then
	   LDDL_FLAGS="-dynamiclib -bind_at_load"
        else
	   LDDL_FLAGS="-single_module -dynamiclib -flat_namespace"
	   LDDL_FLAGS="${LDDL_FLAGS} -undefined suppress -noprebind"
	   SHLIB_CFLAGS="-I/sw/include -fno-common"
        fi
        ;;

      *cygwin*)
        AC_DEFINE(CYGWIN)
        SHDLIB_EXT=".dll.a"
        LDDL_FLAGS="-shared -Wl,--enable-auto-image-base -Wl,-rpath,${loader_run_path}"
        SHLIB_LIB_SPECS="${LIB_SPECS}"
        ;;

      *-linux*)
        SHLIB_CFLAGS="-fPIC"
        LDDL_FLAGS='-shared -Wl,-soname,$@'
        LD_RUN_PATH="-Wl,-rpath,${loader_run_path}"
    
        EXTRA_LIB_SPECS="-ldl"

        case $target in
	   x86_64-*)
	      # AMD 64-bit archictecture
	      # Add -fPIC to standard compile switch
	      CFLAGS="${CFLAGS} -fPIC"
	      ;;
        esac
        ;;
  
      *-netbsd*|*-freebsd*|*-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"
          SHLIB_LD="ld"
          LDDL_FLAGS="-shared"
        fi
        ;;
    esac

    if test "$GCC" = "yes" ; then
       CFLAGS="-fPIC ${CFLAGS}"
    fi

  else

    # Rely on shared lib arguments in tclConfig.sh

    SHLIB_LD="${TCL_SHLIB_LD}"
    EXTRA_LIB_FLAGS=""
    LDDL_FLAGS="${TCL_LD_FLAGS}"
    LD_RUN_PATH=""

    case $target in
      *-linux*)
        LD_RUN_PATH="-Wl,-rpath,${loader_run_path}"
	;;
    esac
  fi

  # 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
    if test "x${TCL_SHLIB_CFLAGS}" = "x" ; then
       SHLIB_CFLAGS="-fPIC ${SHLIB_CFLAGS}"
    else
       SHLIB_CFLAGS="${TCL_SHLIB_CFLAGS} ${SHLIB_CFLAGS}"
    fi
  fi
  CFLAGS="${CFLAGS} ${SHLIB_CFLAGS}"

  if test "${xc_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(LDDL_FLAGS)
  AC_SUBST(SHLIB_LIB_SPECS)
  AC_SUBST(EXTRA_LIB_SPECS)
  AC_SUBST(LD_RUN_PATH)
  AC_SUBST(LDFLAGS)
  AC_SUBST(INC_SPECS)
  AC_SUBST(LIB_SPECS)
  AC_SUBST(TCL_LIB_DIR)
  AC_SUBST(WISH_EXE)

fi

dnl Disable the ASG (automatic schematic generation) package.  Disabled by default.
AC_ARG_ENABLE(asg,
[ --enable-asg		enable support for Automatic Schematic Generation], [
  AC_DEFINE(ASG)
  AC_DEFINE(CONFIGURED)
  SUBDIRS="asg spiceparser"
  dnl Object files to link into the final executable or shared object
  dnl These must be in the correct order!
     SUBLIB="asg/libasg.a spiceparser/libspiceparser.a"
],)

dnl Disable LGF (analog/diglog) file support.  Enabled by default.
AC_ARG_ENABLE(lgf,
[  --disable-lgf           disable support for reading Caltech tools
			  analog simulator .lgf files], , [
  HAVE_LGF=LGF
  AC_DEFINE(LGF)
])

dnl Disable fix for input focus on some window managers.  Enabled by default.
AC_ARG_ENABLE(focus-fix,
[  --disable-focus-fix     disable focus fix for some window managers], , [
  AC_DEFINE(INPUT_FOCUS)
])

dnl Path to Ghostscript
AC_ARG_WITH(gs,
[  --with-gs=DIR           path to ghostscript], [
  if test -f "$withval"; then
    GS_EXEC=$withval
  else
    GS_EXEC=gs
  fi
], [
  AC_CHECK_PROG(GS_EXEC, gs, , gs)])
AC_DEFINE_UNQUOTED(GS_EXEC, "$GS_EXEC")

dnl Path to ngspice
AC_ARG_WITH(ngspice,
[  --with-ngspice=DIR           path to ngspice], [
  if test -f "$withval"; then
    SPICE_EXEC=$withval
  else
    SPICE_EXEC=ngspice
  fi
], [
  AC_CHECK_PROG(SPICE_EXEC, ngspice, , ngspice)])
AC_DEFINE_UNQUOTED(SPICE_EXEC, "$SPICE_EXEC")

dnl Path to Python

xc_with_python=""
PYTHON=

AC_ARG_WITH(python,
[  --with-python=DIR       path to python interpreter],
  xc_with_python=$withval) 

if test "x$xc_with_tcl" != "x" ; then
  xc_with_python=""
elif test "$xc_with_python" = "no" ; then
  xc_with_python=""
elif test "$xc_with_python" = "yes" ; then
  AC_PATH_PROG(PYTHON,python)
elif test "x$xc_with_python" != x; then
  test -f "$xc_with_python" && PYTHON=$xc_with_python
fi

if test "x$PYTHON" != x; then
  _py_version=`$PYTHON -c 'import sys; print sys.version[[0:3]]'`
  _py_prefix=`$PYTHON -c 'import sys; print sys.prefix'`
  _py_exec_prefix=`$PYTHON -c 'import sys; print sys.exec_prefix'`

  _py_include="$_py_prefix/include/python$_py_version"
  _py_lib="$_py_exec_prefix/lib/python$_py_version/config"
  _py_makefile="$_py_lib/Makefile"

  if test $_py_version = 1.5; then
    echo
    echo "*** WARNING:" 
    echo "*** Python version 1.5 detected:  This version of Python has a known fatal"
    echo "*** bug.  Disabling Python interface.  If you want the embedded Python"
    echo "*** interface, you will need to get an updated version of Python."
    echo
    PYTHON=""
  fi
fi

if test "x$PYTHON" != x; then
  if test -f $_py_makefile; then
    _py_libs=`sed -n -e 's/^LIBS=\(.*\)/\1/p' $_py_makefile`
    _py_libm=`sed -n -e 's/^LIBM=\(.*\)/\1/p' $_py_makefile`
  else
    _py_libs='-lpthread -ldl -lutil -ldb'
    _py_libm='-lm'
  fi
      
  # Now that we think we know where the python include and
  # library files are, make sure we can build a small
  # program against them.
  _save_CPPFLAGS=${CPPFLAGS}
  _save_LDFLAGS=${LDFLAGS}
  _save_LIBS=${LIBS}

  CPPFLAGS="$CPPFLAGS -I$_py_include"
  LDFLAGS="$LDFLAGS -L$_py_lib"
    
  case "$target_os" in
	*cygwin*)
		PYLIB="-lpython$_py_version"
		LIBS="$PYLIB.dll $LIBS $X_PRE_LIBS $_py_libs"
		;;
	*)
		LIBS="$LIBS -lpython$_py_version $_py_libs $_py_libm"
		;;		
  esac    
    

  HAVE_PYTHON=0
  AC_CHECK_HEADER(Python.h,[
      AC_MSG_CHECKING([for Py_Initialize in -lpython$_py_version])
      AC_TRY_LINK([#include "Python.h"],[Py_Initialize();],[
        HAVE_PYTHON=1
	INTERPRETER=PYTHON
        AC_MSG_RESULT(yes)
        AC_DEFINE(HAVE_PYTHON)],
        AC_MSG_RESULT(no))])

  if test "x$HAVE_PYTHON" = x0; then
    CPPFLAGS=$_save_CPPFLAGS
    LDFLAGS=$_save_LDFLAGS
    LIBS=$_save_LIBS
    PYTHON=""
  fi
fi

if test "x$PYTHON" != x; then
  STARTUP_FILE="xcstartup.py"
  INTERP_PATH="python"
  WRAPPER_SCRIPT=""
  SUBDIRS="${SUBDIRS} Xw"
  SUBLIB="${SUBLIB} Xw/libxcXw.a"
  XCIRCUIT_TARGET="xcircuit"
elif test "x$xc_with_tcl" != "x" ; then
  INTERPRETER=TCL
  STARTUP_FILE="xcstartup.tcl"
  INTERP_PATH="tcl"
  WRAPPER_SCRIPT="wrapper.tcl"
  AC_DEFINE(TCL_WRAPPER)
  XCIRCUIT_TARGET="tcl"
  ALL_TARGET="all-recursive"
  INSTALL_TARGET="install-recursive"
else
  STARTUP_FILE="startup.script"
  INTERP_PATH="."
  WRAPPER_SCRIPT=""
  SUBDIRS="${SUBDIRS} Xw"
  SUBLIB="${SUBLIB} Xw/libxcXw.a"
  XCIRCUIT_TARGET="xcircuit"
fi

# Add -lm last to LDFLAGS, or Tcl/Tk's addition of -lieee can cause
# an error.
EXTRA_LIB_SPECS="$EXTRA_LIB_SPECS -lm"

dnl Memory debugging:
dnl The non-Tcl version uses (links to) ElectricFence.
dnl Tcl must use the Tcl memory debugger.
dnl Caveats:
dnl We should try to ensure that ElectricFence is available, or that
dnl the Tcl version used has memory debugging compiled in

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

AC_SUBST(SUBDIRS)
AC_SUBST(SUBLIB)
AC_SUBST(STDLIBS)
AC_SUBST(GS_LIBS)
AC_SUBST(STARTUP_FILE)
AC_SUBST(INTERP_PATH)
AC_SUBST(WRAPPER_SCRIPT)
AC_SUBST(XCIRCUIT_TARGET)
AC_SUBST(CFLAGS)
AC_SUBST(LD)
AC_SUBST(LDFLAGS)

AC_SUBST(INTERPRETER)
AC_SUBST(HAVE_LGF)

AC_SUBST(ALL_TARGET)
AC_SUBST(INSTALL_TARGET)

dnl Automake requires these
AC_SUBST(ACLOCAL)
AC_SUBST(AUTOCONF)
AC_SUBST(AUTOMAKE)
AC_SUBST(AUTOHEADER)

AC_OUTPUT(Makefile Xw/Makefile asg/Makefile spiceparser/Makefile)

echo ""
echo "Configuration results:"
echo "----------------------------------------------------"
echo ""

if test "x$xc_with_tcl" == "x" ; then
   if test "x$PYTHON" != x; then
      echo "Using Python interface (not recommended)"
   else
      echo "No Tcl/Tk, using standard Xlib/Xt interface."
      echo "If that is not what you wanted, then make sure"
      echo "you have Tcl/Tk development packages installed?"
   fi
else
   echo "Using Tcl/Tk interface"
fi
echo ""

if test "x$xc_with_cairo" == "x" ; then
   echo "No Cairo graphics."
   echo "If that is not what you wanted, then make sure"
   echo "you have libcairo and fontconfig installed."
   echo "Try installing package cairo-devel."
else
   echo "Using Cairo graphics"
fi
echo ""
echo "CFLAGS=${CFLAGS}"