File: configure.in

package info (click to toggle)
blt8.0 2.4f-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 6,440 kB
  • ctags: 6,543
  • sloc: ansic: 57,358; tcl: 10,169; sh: 1,694; makefile: 551
file content (1024 lines) | stat: -rw-r--r-- 27,303 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
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
AC_INIT(src/bltInit.c)
AC_CONFIG_HEADER(src/bltConfig.h)
AC_CONFIG_AUX_DIR(cf)
AC_PREREQ(2.0)	

# -----------------------------------------------------------------------
#
# 	Handle command line options
#
#		--with-tcl=DIR
#		--with-tk=DIR
#		--with-cc=CC		
#		--with-cflags=flags	This is probably for me only
#
# -----------------------------------------------------------------------

bltIncludes=""
bltLibraries=""
bltAuxLibs=""
bltRunPath=""

blt_ckcmd_tcl_home=""
blt_ckcmd_tk_home=""
blt_ckcmd_jpeg_home="no"
blt_ckcmd_cc=""
blt_ckcmd_cflags="$CFLAGS"

AC_ARG_WITH(tcl, [  --with-tcl=DIR          find Tcl headers and libraries in DIR],
  blt_ckcmd_tcl_home=$withval)
AC_ARG_WITH(tk, [  --with-tk=DIR          find Tk headers and libraries in DIR],
  blt_ckcmd_tk_home=$withval)
AC_ARG_ENABLE(jpeg, [  --enable-jpeg=DIR          find JPEG headers and libraries in DIR], [
  unset ac_cv_header_jpeglib_h
  unset ac_cv_lib_jpeg ac_cv_lib_jpeg_jpeg_read_header
  blt_ckcmd_jpeg_home=$enableval ])
AC_ARG_WITH(cc, [  --with-cc=CC		  set C compiler to CC], [
  blt_ckcmd_cc=$with_cc 
  unset ac_cv_prog_CC
  unset ac_cv_prog_CPP ])
AC_ARG_WITH(cflags, [  --with-cflags=FLAGS  	  set compiler flags to FLAGS],
  blt_ckcmd_cflags="$with_cflags")

AC_CANONICAL_SYSTEM

# -----------------------------------------------------------------------
#
# 	Set a variable containing current working directory if /bin/sh
#	doesn't do it already.
#
# -----------------------------------------------------------------------

PWD=`pwd`

# -----------------------------------------------------------------------
#
# 	C compiler and debugging flags
#
# -----------------------------------------------------------------------

blt_ckenv_cc=$CC

#
# CC search order
#
#  1. command line (--with-cc)
#  2. environment variable ($CC)
#  3. cached variable ($blt_cv_prog_cc)
#  4. check for program (AC_PROG_CC)
#  4. default to cc
#

AC_MSG_CHECKING([which C compiler])
if test "x${blt_ckcmd_cc}" != "x" ; then 
  CC=${blt_ckcmd_cc}
  unset ac_cv_prog_CPP
  unset ac_cv_prog_CC
elif test "x${blt_ckenv_cc}" != "x" ; then
  unset ac_cv_prog_CPP
  unset ac_cv_prog_CC
elif test "x${blt_cv_prog_cc}" != "x" ; then
  CC=${blt_cv_prog_cc}
  unset ac_cv_prog_CC
else 
  AC_PROG_CC
fi
if test "x${CC}" = "x" ; then
  CC=cc
fi
AC_MSG_RESULT([$CC])

unset blt_cv_prog_cc
AC_CACHE_VAL(blt_cv_prog_cc, blt_cv_prog_cc=$CC)
AC_SUBST(CC)
AC_PROG_CPP
if test "x${GCC}" != "x" ; then
  bltHaveGcc="yes"
else
  AC_MSG_CHECKING([if C compiler is really gcc])
    AC_EGREP_CPP(_cc_is_gcc_, [
#ifdef __GNUC__
    _cc_is_gcc_
#endif
],      [bltHaveGcc=yes], [bltHaveGcc=no])
  AC_MSG_RESULT([$bltHaveGcc])
fi

if test "${bltHaveGcc}" = "yes" ; then
  GCCFLAGS="-Wwrite-strings -Wshadow -Wtraditional -fwritable-strings -Wall"
else 
  GCCFLAGS=""
fi
AC_SUBST(GCCFLAGS)

#
# CFLAGS search order
#
#  1. command line (--with-cflags)
#  2. cached variable ($blt_cv_prog_cflags)
#  3. set to "-O6" if using gcc ($bltHaveGcc)
#  4. otherwise, default to "-O"
#
AC_MSG_CHECKING([default compiler flags])
if test  "x${blt_ckcmd_cflags}" != "x" ; then 
  CFLAGS=${blt_ckcmd_cflags}
elif test "x${blt_cv_prog_cflags}" != "x" ; then
  CFLAGS=${blt_cv_prog_cflags}"
elif test "${bltHaveGcc}" = "yes" ; then
  CFLAGS="-O6"
else
  CFLAGS="-O""
fi
AC_MSG_RESULT([$CFLAGS])
unset blt_cv_prog_cflags
AC_CACHE_VAL(blt_cv_prog_cflags, blt_cv_prog_cflags=$CFLAGS)
AC_SUBST(CFLAGS)

# -----------------------------------------------------------------------
#
# Programs:	Check for existence of ranlib and install programs
#
# -----------------------------------------------------------------------

AC_PROG_INSTALL
AC_PROG_RANLIB
AC_PROG_LN_S

# -----------------------------------------------------------------------
#
# Headers:	Check for header files used
#
# -----------------------------------------------------------------------

AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_HEADER_TIME
AC_CHECK_HEADERS(string.h float.h math.h errno.h limits.h sys/param.h)
AC_CHECK_HEADERS(sys/time.h waitflags.h sys/wait.h)
AC_CHECK_HEADERS(malloc.h memory.h)
AC_CHECK_HEADERS(setjmp.h)

if test "${blt_ckcmd_jpeg_home}" != "no" ; then
  oldFlags=${CPPFLAGS}
  if test "${blt_ckcmd_jpeg_home}" = "yes" ; then
    CPPFLAGS=""
  else
    CPPFLAGS="-I${blt_ckcmd_jpeg_home}/include"
  fi
  AC_CHECK_HEADERS(jpeglib.h, [blt_jpeglib_h="${CPPFLAGS}"], [blt_jpeglib_h=""])
  CPPFLAGS=${oldFlags}
fi

# Run this check after jpeglib.h because jpeglib.h sets HAVE_STDLIB_H
AC_CHECK_HEADERS(stdlib.h unistd.h)

AC_MSG_CHECKING([whether strdup is declared in header files])
AC_CACHE_VAL(blt_cv_decl_strdup, 
    AC_EGREP_CPP(strdup, [
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
],      [blt_cv_decl_strdup=yes], [blt_cv_decl_strdup=no]))

if test "${blt_cv_decl_strdup}" = "no"; then
    AC_DEFINE(NO_DECL_STRDUP)
fi
AC_MSG_RESULT([$blt_cv_decl_strdup])

AC_MSG_CHECKING([whether drand48 is declared in header files])
AC_CACHE_VAL(blt_cv_decl_drand48, 
    AC_EGREP_CPP(drand48, [
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_MATH_H
#include <math.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
],      [blt_cv_decl_drand48=yes], [blt_cv_decl_drand48=no]))

if test "${blt_cv_decl_drand48}" = "no"; then
    AC_DEFINE(NO_DECL_DRAND48)
fi
AC_MSG_RESULT([$blt_cv_decl_drand48])

# -----------------------------------------------------------------------
#
# Functions: 	Check for  strdup, drand48, and srand48.
#
# -----------------------------------------------------------------------

AC_HAVE_FUNCS(strdup drand48 srand48)

# -----------------------------------------------------------------------
#
# Types:	Check for existence of types of size_t and pid_t
#
# -----------------------------------------------------------------------

AC_TYPE_SIZE_T
AC_TYPE_PID_T
AC_C_BIGENDIAN

# -----------------------------------------------------------------------
#
#	Check whether <sys/wait.h> defines the type "union wait" 
#	correctly.  It's needed because of weirdness in HP-UX where 
#	"union wait" is defined in both the BSD and SYS-V  environments.  
#	Checking the usability of WIFEXITED seems to do	the trick.
#
# -----------------------------------------------------------------------

AC_MSG_CHECKING([whether union wait is defined correctly])
AC_CACHE_VAL(blt_cv_struct_wait_works,
    AC_TRY_COMPILE([#include <sys/types.h> 
#include <sys/wait.h>], [
union wait x;
WIFEXITED(x);		/* Generates compiler error if WIFEXITED
			 * uses an int. */
], 
    	[blt_cv_struct_wait_works="yes"], 
	[blt_cv_struct_wait_works="no"]))

if test "${blt_cv_struct_wait_works}" = "no"; then
    AC_DEFINE(NO_UNION_WAIT)
fi
AC_MSG_RESULT([$blt_cv_struct_wait_works])

# -----------------------------------------------------------------------
#
# 	Check the smallest value such that 1.0 + x != 1.0.
#	For ANSI compilers this is DBL_EPSILON in float.h
#
#--------------------------------------------------------------------

AC_MSG_CHECKING([whether DBL_EPSILON is defined in float.h])
AC_CACHE_VAL(blt_cv_found_dbl_epsilon,
    AC_EGREP_CPP(yes,	
   [
#ifdef HAVE_FLOAT_H
#include <float.h>
#endif
#ifdef DBL_EPSILON
 yes
#endif
], blt_cv_found_dbl_epsilon=yes, blt_cv_found_dbl_epsilon=no) 
)
AC_MSG_RESULT([${blt_cv_found_dbl_epsilon}])

if test "${blt_cv_found_dbl_epsilon}" = "no" ; then
  AC_CACHE_VAL(blt_cv_dbl_epsilon, 
  oldFlags="$CFLAGS"
  CFLAGS="-g -lm"
  AC_MSG_CHECKING([whether DBL_EPSILON can be computed])
  AC_TRY_RUN_WITH_OUTPUT(blt_cv_dbl_epsilon, [
main () {
    double e, u;
    u = 1.0;
    for(;;) {
       u *= 0.5;
       if ((1.0 + u) == 1.0) {
	   break;
       }
    }
    e = u * 2.0;
    printf("%.17e\n", e);
    exit(0);
}])
    CFLAGS="$oldFlags"
    AC_DEFINE_UNQUOTED(BLT_DBL_EPSILON, ${blt_cv_dbl_epsilon})
    AC_MSG_RESULT([${blt_cv_dbl_epsilon}])
)
fi

AC_PATH_X

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

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

guesses="\
 $blt_ckcmd_tcl_home \
 $blt_ckcmd_tcl_home/lib \
 $blt_cv_tcl_lib \
 $prefix/lib \
 $exec_prefix/lib \
 /usr/local/tcl/lib \
 /usr/local/tcl/tcl8.0/lib \
 /usr/local/tcl/tcl7.6/lib \
 /usr/local/tcl/tcl7.5/lib \
 $PWD/../tcl8.0/unix \
 $PWD/../tcl7.6/unix \
 $PWD/../tcl7.5/unix \
 /usr/local/lib /usr/lib"

for dir in $guesses; do
  if test -r "$dir/tclConfig.sh" ; then
    tclConfigFile="$dir/tclConfig.sh"
    break
  fi
done
AC_MSG_RESULT([${tclConfigFile}])

if test "x$tclConfigFile" = "x" ; then
  echo "can't find Tcl configuration script \"tclConfig.sh\""
  exit 1
fi

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

AC_MSG_CHECKING([for tkConfig.sh])
tkConfigFile=""
guesses="\
 $blt_ckcmd_tk_home \
 $blt_ckcmd_tk_home/lib \
 $blt_ckcmd_tcl_home \
 $blt_ckcmd_tcl_home/lib \
 $blt_cv_tk_lib \
 $prefix/lib \
 $exec_prefix/lib \
 /usr/local/tcl/lib \
 /usr/local/tcl/tk8.0/lib \
 /usr/local/tcl/tk4.2/lib \
 /usr/local/tcl/tk4.1/lib \
 $PWD/../tk8.0/unix \
 $PWD/../tk4.2/unix \
 $PWD/../tk4.1/unix \
 /usr/local/lib /usr/lib"

for dir in $guesses; do
  if test -r "$dir/tkConfig.sh" ; then
    tkConfigFile="$dir/tkConfig.sh"
    break
  fi
done
AC_MSG_RESULT([${tkConfigFile}])

# -----------------------------------------------------------------------
#
#	Find the [incr Tcl] build configuration file "itclConfig.sh"
#
#	If we find one, use this directory's versions of tclConfig.sh
#	and tkConfig.sh.   This will point us to versions of Tcl and
#	Tk with namespace support.
#
# -----------------------------------------------------------------------

AC_MSG_CHECKING([for itclConfig.sh])
itclConfigFile=""
guesses="\
 $blt_ckcmd_tk_home \
 $blt_ckcmd_tk_home/lib \
 $blt_ckcmd_tcl_home \
 $blt_ckcmd_tcl_home/lib \
 $blt_cv_tk_lib \
 $prefix/lib \
 $exec_prefix/lib \
 /usr/local/tcl/lib \
 /usr/local/tcl/tk8.0/lib \
 /usr/local/tcl/tk4.2/lib \
 /usr/local/tcl/tk4.1/lib \
 /usr/local/tcl/tcl8.0/lib \
 /usr/local/tcl/tcl7.6/lib \
 /usr/local/tcl/tcl7.5/lib \
 $XLIBDIR \
 /usr/local/lib /usr/lib"

for dir in $guesses; do
  if test -r "$dir/itclConfig.sh" ; then
    itclConfigFile="$dir/itclConfig.sh"
    if test -r "$dir/tclConfig.sh" ; then
      tclConfigFile="$dir/tclConfig.sh"
    fi
    if test -r "$dir/tkConfig.sh" ; then
      tkConfigFile="$dir/tkConfig.sh"
    fi
    break
  fi
done
AC_MSG_RESULT([${itclConfigFile}])

# -----------------------------------------------------------------------
#
#	Source in the Tcl/Tk/[incr Tcl] configuration scripts.  
#
#	First source the Tcl/Tk scripts.  Then source the [incr Tcl]
#	scripts, if needed.  The variables [incr Tcl] script will
#	override those of the the tclConfig.sh or tkConfig.sh
#
#	BTW: Does anyone actually use the tclConfig.sh and tkConfig.sh 
#	scripts? They seem to be always missing something.  For example, 
#	why don't they say where to find the Tcl and Tk header files?
#
#       For example, give me the library directory paths separately 
#	(I can't easily parse "-Ldir", but I can always paste a -L 
#	on the front).  If I want to specify equivalent of the -R flag, 
#	I need the build a path of the library directories. Such as
#
#	   "-R $(BLTLIB):$(TKLIB):$(TCLLIB):($XLIB):$(JPEGLIB)"
#
# -----------------------------------------------------------------------

if test "x$tkConfigFile" != "x" ; then
  . $tclConfigFile
  . $tkConfigFile
fi

tclIncSpec="-I${TCL_PREFIX}/include"
tkIncSpec="-I${TK_PREFIX}/include"
tclLibDir=${TCL_PREFIX}/lib
tkLibDir=${TK_PREFIX}/lib

itclLibSpec=""
itclIncSpec=""
itclSuffix=""
if test "x$itclConfigFile" != "x" ; then
  . $itclConfigFile
  if test "${ITCL_MAJOR_VERSION}" = "2" ; then 
    tclIncSpec="-I${TCL_PREFIX}/include/itcl"
    tkIncSpec="-I${TK_PREFIX}/include/itcl"
    tclLibDir=${TCL_PREFIX}/lib/itcl
    tkLibDir=${TK_PREFIX}/lib/itcl
    itclSuffix="i"
  fi
fi

tclLibSpec=${TCL_LIB_SPEC}
tkLibSpec=${TK_LIB_SPEC}

case $target in
  *-sunos4*|NetBSD-*|FreeBSD-*|OpenBSD-*)
    tclLib="-ltcl${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${itclSuffix}"
    tkLib="-ltk${TK_MAJOR_VERSION}${TK_MINOR_VERSION}${itclSuffix}"
    ;;
  *)
    tclLib="-ltcl${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION}${itclSuffix}"
    tkLib="-ltk${TK_MAJOR_VERSION}.${TK_MINOR_VERSION}${itclSuffix}"
    ;;
esac

# -----------------------------------------------------------------------
# 
# Tk libraries and header files
#
# -----------------------------------------------------------------------
bltIncludes="${bltIncludes} ${tkIncSpec}"
bltLibraries="${bltLibraries} ${tkLibSpec}"
if test "x${tkLibDir}" != "x" ; then
  bltRunPath="${bltRunPath}:${tkLibDir}"
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 "${tkIncSpec}" != "${tclIncSpec}" ; then
  bltIncludes="${bltIncludes} ${tclIncSpec}"
fi

if test "${tkLibDir}" = "${tclLibDir}" ; then
  bltLibraries="${bltLibraries} ${tclLib}"
else 
  bltLibraries="${bltLibraries} ${tclLibSpec}"
  if test "x${tclLibDir}" != "x" ; then
    bltRunPath="${bltRunPath}:${tclLibDir}"
  fi
fi

# -----------------------------------------------------------------------
# 
# [incr Tcl] include files
#
# -----------------------------------------------------------------------
if test "x${itclIncSpec}" != "x" ; then
  bltIncludes="${itclIncSpec} ${bltIncludes}"
fi

# -----------------------------------------------------------------------
# 
# [incr Tcl] libraries
#
# -----------------------------------------------------------------------
if test "x${itclLibSpec}" != "x" ; then
  bltLibraries="${itclLibSpec} ${bltLibraries}"
fi

# -----------------------------------------------------------------------
# 
# -lX11
#
# -----------------------------------------------------------------------

if test "${tkLibDir}" = "${x_libraries}" ; then
  bltLibraries="${bltLibraries} -lX11"
else 
  if test "x${x_libraries}" = "x" ; then
    bltLibraries="${bltLibraries} -lX11"
  else
    bltLibraries="${bltLibraries} -L${x_libraries} -lX11"
    if test "x${tclLibDir}" != "x" ; then
      bltRunPath="${bltRunPath}:${x_libraries}"
    fi
  fi
fi
if test "${tkIncDir}" != "${x_includes}" ; then
  if test "x${x_includes}" != "x" ; then
    bltIncludes="${bltIncludes} -I${x_includes}"
  fi
fi

# -----------------------------------------------------------------------
# 
# -lsocket
#
# -----------------------------------------------------------------------
AC_CHECK_LIB(socket, main)

# -----------------------------------------------------------------------
# 
# -lnsl
#
# -----------------------------------------------------------------------
AC_CHECK_LIB(nsl, main)

# -----------------------------------------------------------------------
# 
# -lm
#
# -----------------------------------------------------------------------
AC_CHECK_LIB(m, main)

# -----------------------------------------------------------------------
# 
# JPEG library
#
# -----------------------------------------------------------------------
if test "${blt_ckcmd_jpeg_home}" != "no" ; then
  if test "${blt_ckcmd_jpeg_home}" = "yes" ; then
    spec="-ljpeg"
    dir=""
  else
    spec="-L${blt_ckcmd_jpeg_home}/lib -ljpeg"
    dir=${blt_ckcmd_jpeg_home}/lib
  fi
  AC_CHECK_LIB(jpeg, jpeg_read_header, [found=yes], [found=no], $spec)
  if test "${found}" = "yes" ; then
    bltLibraries="${bltLibraries} ${spec}"
    if test "x${dir}" != "x" ; then
      bltRunPath="${bltRunPath}:${dir}"
      bltAuxLibs="${dir}/libjpeg ${bltAuxLibs}"
    else 
      bltAuxLibs="libjpeg ${bltAuxLibs}"
    fi
  fi
fi

if test "x${blt_jpeglib_h}" != "x" ; then
  bltIncludes="${bltIncludes} ${blt_jpeglib_h}"
fi

# -----------------------------------------------------------------------
#
# 	Set up a new default prefix to installation path.  The ways
#	the prefix can be set and their precedence are as follows:
#
#	1. --prefix option given to ./configure. (prefix != NONE)
#       2. use previously configured Tk prefix
#
# -----------------------------------------------------------------------

if test "$prefix" = "NONE" ; then
  prefix=${TK_PREFIX}
fi

if test "$exec_prefix" = "NONE" ; then
  exec_prefix=$prefix
fi


# -------------------------------------------------------------------------
#
#	Check for [incr Tcl] header files
#
# -------------------------------------------------------------------------

oldFlags=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $bltIncludes"
AC_CHECK_HEADERS(itcl.h)
AC_CHECK_HEADERS(itk.h)
CPPFLAGS=$oldFlags

# -------------------------------------------------------------------------
#
#	Extract the BLT version number for the blt.h header
#
# -------------------------------------------------------------------------

AC_MSG_CHECKING([BLT major version number])
AC_CACHE_VAL(blt_cv_major_version, 
  oldFlags="$CFLAGS"
  CFLAGS="$CFLAGS $bltIncludes"
  AC_TRY_RUN_WITH_OUTPUT(blt_cv_major_version, [
#include "${srcdir}/blt.h"
main() { printf("%d", BLT_MAJOR_VERSION); exit(0); }
  ])
  CFLAGS="$oldFlags"
)
bltMajor=${blt_cv_major_version}
AC_MSG_RESULT([$blt_cv_major_version])

AC_MSG_CHECKING([BLT minor version number])
AC_CACHE_VAL(blt_cv_minor_version, 
  oldFlags="$CFLAGS"
  CFLAGS="$CFLAGS $bltIncludes"
  AC_TRY_RUN_WITH_OUTPUT(blt_cv_minor_version, [
#include "${srcdir}/blt.h"
main() { printf("%d", BLT_MINOR_VERSION); exit(0); }
  ])
  CFLAGS="$oldFlags"
)

AC_MSG_RESULT([$blt_cv_minor_version])
bltMinor=${blt_cv_minor_version}

# Add BLT to the run path
if test "x${libdir}" != "x" ; then
  bltRunPath="${libdir}${bltRunPath}"
fi

bltLibraries="${bltLibraries} ${LIBS}"

#--------------------------------------------------------------------
#
#	Check if we can generate shared libraries on this system.
#	Set flags to generate shared libraries for systems that we 
#	know about.  Start with Tcl's variables, make changes
#	as we know about the different systems.
#
#	Why don't I just use the tclConfig.sh script information?
#       
#	1. Imbedding major *and* minor version numbers in library 
#	   names is really dumb.  I'm sorry but it is (It should
#	   have been an omen when it failed with the SunOS linker). 
#	
#	   Header files, man pages, etc aren't versioned, so what's
#	   the point?  Worse, it defeats the whole rationale behind
#	   shared libraries.  You're *supposed* to be able to slip
#	   in a new version of library and let the programs 
#	   automatically use them.  So in that vein, putting major 
#	   version numbers in the library name makes sense, but not
#	   the minor too. And that's why most systems have version 
#	   numbers built into the shared library suffix (e.g. .so.8). 
#
#	   So now tclConfig.sh isn't a convenience, it's a damn
#	   necessity.  How else do you know the name of the 
#	   library?  So what do most people do? They make symbolic
#	   links to libtcl.a libtk.a, etc.  Kind of funny isn't it?
#
#       2. On linux (ELF) it doesn't version the library properly.
#          Also it fails to set the -Wl,-rpath flag.
#
#	3. Some of the flags Tcl chooses are compiler dependent.
#	   What if you compile the Tcl/Tk libraries with one compiler,
#	   and compile and link BLT with another?  
#
#--------------------------------------------------------------------

LIB_BASE_NAME=libBLT

# Initialize shared library build variables

SHLIB_CFLAGS="$TCL_SHLIB_CFLAGS"
SHLIB_LD="$TCL_SHLIB_LD"
SHLIB_LD_FLAGS="$TCL_LD_FLAGS"
SHLIB_RUNPATH="$TCL_LD_SEARCH_FLAGS"

SHLIB_SUFFIX=".so.${bltMajor}"
SHLIB_TARGET=""
SHLIB_CFLAGS=""
SHLIB_LD_LIBS=""
LDFLAGS=""

buildShared="yes"

case $target in

  *-aix4.[[2-9]]*)
    # No Position-Independent flags needed
    SHLIB_CFLAGS=""

    # Use shell-script to link shared library
    srcPath=`cd ${srcdir}/cf; pwd`
    SHLIB_LD="${srcdir}/cf/ldAix /bin/ld -bhalt:4 -bM:SRE -bE:lib.exp -H512 -T512 -bnoentry"
    SHLIB_LD_LIBS="${bltLibraries}"
    bltLibraries="${bltLibraries} -ldl"
    LDFLAGS="-L${bltRunPath}"
    ;;

  *-aix*)
    # No Position-Independent flags needed
    SHLIB_CFLAGS=""

    # Use shell-script to link shared library
    srcPath=`cd ${srcdir}/cf; pwd`
    SHLIB_LD="${srcPath}/cf/ldAix /bin/ld -bhalt:4 -bM:SRE -bE:lib.exp -H512 -T512 -bnoentry"
    SHLIB_LD_LIBS="${bltLibraries}"
    bltLibraries="${bltLibraries} -lld"
    LDFLAGS="-L${bltRunPath}"
    ;;

  *-bsdi*)
    SHLIB_CFLAGS=""
    SHLIB_LD="shlicc"
    SHLIB_LD_FLAGS="-r"
    SHLIB_LD_LIBS="${bltLibraries}"
    bltLibraries="${bltLibraries} -ldl"
    ;;

  *-dgux*)
    SHLIB_CFLAGS="-K PIC"
    SHLIB_LD="cc"
    SHLIB_LD_FLAGS="-G"
    bltLibraries="${bltLibraries} -ldl"
    ;;

  *-hpux*)
    AC_CHECK_LIB(dld, shl_load, [found=yes], [found=no])
    if test "${found}" = "yes" ; then
      SHLIB_CFLAGS="+z"
      SHLIB_LD="ld"
      SHLIB_LD_FLAGS="-b -n"
      SHLIB_SUFFIX=".sl"

      bltLibraries="${bltLibraries} -ldld"
      LDFLAGS="-Wl,-E -Wl,+b,${bltRunPath}:."
    fi
    ;;

  *-irix-[56]*)
    SHLIB_CFLAGS=""
    SHLIB_LD="ld"
    SHLIB_LD_FLAGS="-shared -rdata_shared"
    LDFLAGS="-Wl,-rpath,${bltRunPath}"
    ;;

  *-irix64-*)
    SHLIB_CFLAGS=""
    SHLIB_LD="ld"
    SHLIB_LD_FLAGS="-32 -shared -rdata_shared -rpath /usr/local/lib"

    LDFLAGS="-Wl,-rpath,${bltRunPath}"
    ;;

  *-linux*)
    SHLIB_CFLAGS="-fPIC"
    SHLIB_LD="${CC}"
    SHLIB_SUFFIX=".so.${bltMajor}.${bltMinor}"
    SHLIB_LD_FLAGS="-shared -Wl,-E -Wl,-soname,libBLT.so.${bltMajor}"

    bltLibraries="${bltLibraries} -ldl"
    LDFLAGS="-Wl,-rpath,${bltRunPath}"
    ;;

  *-ncr-sysv4-*2*)

    SHLIB_CFLAGS="-K PIC"
    SHLIB_LD="cc"
    SHLIB_LD_FLAGS="-G"
    SHLIB_SUFFIX=".so"

    bltLibraries="${bltLibraries} -ldl"
    ;;

  *-ncr-sysv4*)
    SHLIB_CFLAGS="-K PIC"
    SHLIB_LD="cc"
    SHLIB_LD_FLAGS="-G -Wl,-Bexport"
    SHLIB_SUFFIX=".so"

    bltLibraries="${bltLibraries} -ldl"
    LDFLAGS="-Wl,-Bexport"
    ;;

  *-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"
      SHLIB_LD_FLAGS="-Bshareable -x"
      SHLIB_SUFFIX=".so"
    fi
    ;;

  *-nextstep*)
    SHLIB_CFLAGS=""
    SHLIB_LD="cc"
    SHLIB_LD_FLAGS="-nostdlib -r"
    SHLIB_SUFFIX=".so"
    ;;

  *-osf1-1.[012]*)
    # OSF/1 1.[012] from OSF, and derivatives, including Paragon OSF/1

    SHLIB_CFLAGS=""

    # Warning: Ugly Makefile Hack 
    #	Make package name same as library name

    SHLIB_LD='ld -R -export $@:'
    SHLIB_SUFFIX=".so"
    ;;

  *-osf1-1.*)
    # OSF/1 1.3 from OSF using ELF, and derivatives, including AD2

    SHLIB_CFLAGS="-fpic"
    SHLIB_LD="ld -shared"
    SHLIB_SUFFIX=".so"
    ;;

  *-osf1V*)
    # Digital OSF/1

    SHLIB_CFLAGS=""
    SHLIB_LD='ld'
    SHLIB_LD_FLAGS='-shared -expect_unresolved "*"'
    SHLIB_SUFFIX=".so"
    LDFLAGS="-Wl,-rpath,${bltRunPath}"
    ;;

  *-sco*)
    # Note, dlopen is available only on SCO 3.2.5 and greater.  However,
    # this test works, since "uname -s" was non-standard in 3.2.4 and
    # below.

    SHLIB_CFLAGS="-Kpic -belf"
    SHLIB_LD="ld"
    SHLIB_LD_FLAGS="-G"
    SHLIB_SUFFIX=".so"
    LDFLAGS="-belf -Wl,-Bexport"
    ;;

  *-sni-sysv*)

    SHLIB_CFLAGS="-K PIC"
    SHLIB_LD="cc"
    SHLIB_LD_FLAGS="-G"
    SHLIB_SUFFIX=".so"

    bltLibraries="${bltLibraries} -ldl"
    ;;

  *-sunos4*)

    SHLIB_CFLAGS="-PIC"
    SHLIB_LD="ld"
    SHLIB_LD_FLAGS="-assert pure-text"
    SHLIB_SUFFIX=".so.${bltMajor}.${bltMinor}"
    bltLibraries="${bltLibraries} -ldl"
    ;;

  *-solaris2*)

    SHLIB_CFLAGS="-KPIC"
    SHLIB_LD="/usr/ccs/bin/ld"
    SHLIB_LD_FLAGS="-G -z text"
    SHLIB_LD_LIBS="$(bltLibraries)"

    bltLibraries="${bltLibraries} -ldl"
    LDFLAGS="-R ${bltRunPath}"
    ;;

  *-mips-dde-sysv*)

    SHLIB_CFLAGS="-KPIC"
    SHLIB_LD="cc"
    SHLIB_LD_FLAGS="-G"
    SHLIB_SUFFIX=".so"

    bltLibraries="${bltLibraries} -ldl"

    # Some UNIX_SV* systems (unixware 1.1.2 for example) have linkers
    # that don't grok the -Bexport option.  Test that it does.

    hold_ldflags=$LDFLAGS
    AC_MSG_CHECKING(for ld accepts -Bexport flag)
    LDFLAGS="${LDFLAGS} -Wl,-Bexport"
    AC_TRY_LINK(, [int i;], found=yes, found=no)
    LDFLAGS=$hold_ldflags
    AC_MSG_RESULT($found)
    if test $found = yes; then
      LDFLAGS="-Wl,-Bexport"
    fi
    ;;

  *)
    buildShared="no"
    ;;

esac

# If we're running gcc, then change the C flags for compiling shared
# libraries to the right flags for gcc, instead of those for the
# standard manufacturer compiler.

if test "$bltHaveGcc" = "yes" ; then
  SHLIB_CFLAGS="-fPIC"
fi

if test "${buildShared}" = "yes" ; then
  SHLIB_TARGET="shared"
  AC_SUBST(SHLIB_CFLAGS)
  AC_SUBST(SHLIB_TARGET)
  AC_SUBST(SHLIB_LD)
  AC_SUBST(SHLIB_LD_FLAGS)
  AC_SUBST(SHLIB_LD_LIBS)
  AC_SUBST(SHLIB_LIBS)
  AC_SUBST(SHLIB_SUFFIX)
fi

AC_SUBST(LDFLAGS)
AC_SUBST(EXTRA_LDFLAGS)

INCLUDES=${bltIncludes}
AC_SUBST(INCLUDES)
LIBS=${bltLibraries}
AC_SUBST(LIBS)
BLT_MAJOR_VERSION=${bltMajor}
AC_SUBST(BLT_MAJOR_VERSION)
BLT_MINOR_VERSION=${bltMinor}
AC_SUBST(BLT_MINOR_VERSION)
BLT_VERSION=${bltMajor}.${bltMinor}
AC_SUBST(BLT_VERSION)
AUX_LIBS="${bltAuxLibs}"
AC_SUBST(AUX_LIBS)

#--------------------------------------------------------------------
#	Propagate prefix argument as installation directory.
#--------------------------------------------------------------------

BLT_LIBRARY="$libdir/blt${bltMajor}.${bltMinor}"
AC_SUBST(BLT_LIBRARY)

#--------------------------------------------------------------------
#	Print out some of the more important settings 
#--------------------------------------------------------------------
echo ""
echo "Configuration results:"
echo ""
echo "  tcl.h      found in  $tclIncSpec"
echo "  tk.h       found in  $tkIncSpec"
echo "  X11/Xlib.h found in  -I$x_includes"
echo "  libtcl.a   found in  $tclLibSpec"
echo "  libtk.a    found in  $tkLibSpec"
echo "  libX11.a   found in  -L$x_libraries -lX11"
echo ""
echo "Directories where BLT is to be installed:"
echo ""
echo "  \"\$prefix\" is $prefix"
echo "  \"\$exec_prefix\" is $exec_prefix"
echo ""
echo "  bltwish      to be installed in  $bindir"
echo "  libBLT.a     to be installed in  $libdir"
echo "  scripts      to be installed in  $BLT_LIBRARY"
echo "  manual pages to be installed in  $mandir"
echo ""

#--------------------------------------------------------------------
#
#	Generate the following Makefiles
#
#	   ./Makefile
#	   ./src/Makefile
#	   ./src/shared/Makefile
#	   ./man/Makefile
#	   ./library/Makefile
#	   ./library/pkgIndex.tcl
#	   ./man/man.macros
#	   ./demos/Makefile
#
#--------------------------------------------------------------------
AC_OUTPUT(Makefile src/Makefile src/shared/Makefile man/Makefile library/Makefile library/pkgIndex.tcl man/man.macros demos/Makefile)