1dnl configure.in: autoconf script for Vim
2
3dnl Process this file with autoconf 2.12 or 2.13 to produce "configure".
4dnl Should also work with autoconf 2.54 and later.
5
6AC_INIT(vim.h)
7AC_CONFIG_HEADER(auto/config.h:config.h.in)
8
9dnl Being able to run configure means the system is Unix (compatible).
10AC_DEFINE(UNIX)
11AC_PROG_MAKE_SET
12
13dnl Checks for programs.
14AC_PROG_CC	dnl required by almost everything
15AC_PROG_CPP	dnl required by header file checks
16AC_PROGRAM_EGREP dnl required by AC_EGREP_CPP
17AC_ISC_POSIX	dnl required by AC_C_CROSS
18AC_PROG_AWK	dnl required for "make html" in ../doc
19
20dnl Don't strip if we don't have it
21AC_CHECK_PROG(STRIP, strip, strip, :)
22
23dnl Check for extension of executables
24AC_EXEEXT
25
26dnl Check for standard headers.  We don't use this in Vim but other stuff
27dnl in autoconf needs it, where it uses STDC_HEADERS.
28AC_HEADER_STDC
29AC_HEADER_SYS_WAIT
30
31dnl Set default value for CFLAGS if none is defined or it's empty
32if test -z "$CFLAGS"; then
33  CFLAGS="-O"
34  test "$GCC" = yes && CFLAGS="-O2 -fno-strength-reduce -Wall"
35fi
36if test "$GCC" = yes; then
37  dnl method that should work for nearly all versions
38  gccversion=`"$CC" -dumpversion`
39  if test "x$gccversion" = "x"; then
40    dnl old method; fall-back for when -dumpversion doesn't work
41    gccversion=`"$CC" --version | sed -e '2,$d' -e 's/darwin.//' -e 's/^[[^0-9]]*\([[0-9]]\.[[0-9.]]*\).*$/\1/g'`
42  fi
43  dnl version 4.0.1 was reported to cause trouble on Macintosh by Marcin Dalecki
44  if test "$gccversion" = "3.0.1" -o "$gccversion" = "3.0.2" -o "$gccversion" = "4.0.1"; then
45    echo 'GCC [[34]].0.[[12]] has a bug in the optimizer, disabling "-O#"'
46    CFLAGS=`echo "$CFLAGS" | sed 's/-O[[23456789]]/-O/'`
47  else
48    if test "$gccversion" = "3.1" -o "$gccversion" = "3.2" -o "$gccversion" = "3.2.1" && `echo "$CFLAGS" | grep -v fno-strength-reduce >/dev/null`; then
49      echo 'GCC 3.1 and 3.2 have a bug in the optimizer, adding "-fno-strength-reduce"'
50      CFLAGS="$CFLAGS -fno-strength-reduce"
51    fi
52  fi
53fi
54
55dnl If configure thinks we are cross compiling, there might be something
56dnl wrong with the CC or CFLAGS settings, give a useful warning message
57if test "$cross_compiling" = yes; then
58  AC_MSG_RESULT([cannot compile a simple program; if not cross compiling check CC and CFLAGS])
59fi
60
61dnl gcc-cpp has the wonderful -MM option to produce nicer dependencies.
62dnl But gcc 3.1 changed the meaning!  See near the end.
63test "$GCC" = yes && CPP_MM=M; AC_SUBST(CPP_MM)
64
65if test -f ./toolcheck; then
66  AC_CHECKING(for buggy tools)
67  sh ./toolcheck 1>&AC_FD_MSG
68fi
69
70OS_EXTRA_SRC=""; OS_EXTRA_OBJ=""
71
72dnl Check for BeOS, which needs an extra source file
73AC_MSG_CHECKING(for BeOS)
74case `uname` in
75    BeOS)	OS_EXTRA_SRC=os_beos.c; OS_EXTRA_OBJ=objects/os_beos.o
76		BEOS=yes; AC_MSG_RESULT(yes);;
77    *)		BEOS=no; AC_MSG_RESULT(no);;
78esac
79
80dnl If QNX is found, assume we don't want to use Xphoton
81dnl unless it was specifically asked for (--with-x)
82AC_MSG_CHECKING(for QNX)
83case `uname` in
84    QNX)	OS_EXTRA_SRC=os_qnx.c; OS_EXTRA_OBJ=objects/os_qnx.o
85		test -z "$with_x" && with_x=no
86		QNX=yes; AC_MSG_RESULT(yes);;
87    *)		QNX=no; AC_MSG_RESULT(no);;
88esac
89
90dnl Check for Darwin and MacOS X
91dnl We do a check for MacOS X in the very beginning because there
92dnl are a lot of other things we need to change besides GUI stuff
93AC_MSG_CHECKING([for Darwin (Mac OS X)])
94if test "`(uname) 2>/dev/null`" = Darwin; then
95  AC_MSG_RESULT(yes)
96
97  AC_MSG_CHECKING(--disable-darwin argument)
98  AC_ARG_ENABLE(darwin,
99	  [  --disable-darwin        Disable Darwin (Mac OS X) support.],
100	  , [enable_darwin="yes"])
101  if test "$enable_darwin" = "yes"; then
102    AC_MSG_RESULT(no)
103    AC_MSG_CHECKING(if Darwin files are there)
104    if test -f os_macosx.m; then
105      AC_MSG_RESULT(yes)
106    else
107      AC_MSG_RESULT([no, Darwin support disabled])
108      enable_darwin=no
109    fi
110  else
111    AC_MSG_RESULT([yes, Darwin support excluded])
112  fi
113
114  AC_MSG_CHECKING(--with-mac-arch argument)
115  AC_ARG_WITH(mac-arch, [  --with-mac-arch=ARCH    current, intel, ppc or both],
116	MACARCH="$withval"; AC_MSG_RESULT($MACARCH),
117	MACARCH="current"; AC_MSG_RESULT(defaulting to $MACARCH))
118
119  AC_MSG_CHECKING(--with-developer-dir argument)
120  AC_ARG_WITH(developer-dir, [  --with-developer-dir=PATH    use PATH as location for Xcode developer tools],
121	DEVELOPER_DIR="$withval"; AC_MSG_RESULT($DEVELOPER_DIR),
122        DEVELOPER_DIR=""; AC_MSG_RESULT(not present))
123  
124  if test "x$DEVELOPER_DIR" = "x"; then
125    AC_PATH_PROG(XCODE_SELECT, xcode-select)
126    if test "x$XCODE_SELECT" != "x"; then
127      AC_MSG_CHECKING(for developer dir using xcode-select)
128      DEVELOPER_DIR=`$XCODE_SELECT -print-path`
129      AC_MSG_RESULT([$DEVELOPER_DIR])
130    else
131      DEVELOPER_DIR=/Developer
132    fi
133  fi
134
135  if test "x$MACARCH" = "xboth"; then
136    AC_MSG_CHECKING(for 10.4 universal SDK)
137    dnl There is a terrible inconsistency (but we appear to get away with it):
138    dnl $CFLAGS uses the 10.4u SDK library for the headers, while $CPPFLAGS
139    dnl doesn't, because "gcc -E" doesn't grok it.  That means the configure
140    dnl tests using the preprocessor are actually done with the wrong header
141    dnl files. $LDFLAGS is set at the end, because configure uses it together
142    dnl with $CFLAGS and we can only have one -sysroot argument.
143    save_cppflags="$CPPFLAGS"
144    save_cflags="$CFLAGS"
145    save_ldflags="$LDFLAGS"
146    CFLAGS="$CFLAGS -isysroot $DEVELOPER_DIR/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
147    AC_TRY_LINK([ ], [ ],
148	AC_MSG_RESULT(found, will make universal binary),
149
150	AC_MSG_RESULT(not found)
151	CFLAGS="$save_cflags"
152	AC_MSG_CHECKING(if Intel architecture is supported)
153	CPPFLAGS="$CPPFLAGS -arch i386"
154	LDFLAGS="$save_ldflags -arch i386"
155	AC_TRY_LINK([ ], [ ],
156	    AC_MSG_RESULT(yes); MACARCH="intel",
157	    AC_MSG_RESULT(no, using PowerPC)
158		MACARCH="ppc"
159		CPPFLAGS="$save_cppflags -arch ppc"
160		LDFLAGS="$save_ldflags -arch ppc"))
161  elif test "x$MACARCH" = "xintel"; then
162    CPPFLAGS="$CPPFLAGS -arch intel"
163    LDFLAGS="$LDFLAGS -arch intel"
164  elif test "x$MACARCH" = "xppc"; then
165    CPPFLAGS="$CPPFLAGS -arch ppc"
166    LDFLAGS="$LDFLAGS -arch ppc"
167  fi
168
169  if test "$enable_darwin" = "yes"; then
170    MACOSX=yes
171    OS_EXTRA_SRC="os_macosx.m os_mac_conv.c";
172    OS_EXTRA_OBJ="objects/os_macosx.o objects/os_mac_conv.o"
173    dnl TODO: use -arch i386 on Intel machines
174    CPPFLAGS="$CPPFLAGS -DMACOS_X_UNIX -no-cpp-precomp"
175
176    dnl If Carbon is found, assume we don't want X11
177    dnl unless it was specifically asked for (--with-x)
178    dnl or Motif, Athena or GTK GUI is used.
179    AC_CHECK_HEADER(Carbon/Carbon.h, CARBON=yes)
180    if test "x$CARBON" = "xyes"; then
181      if test -z "$with_x" -a "X$enable_gui" != Xmotif -a "X$enable_gui" != Xathena -a "X$enable_gui" != Xgtk2; then
182	with_x=no
183      fi
184    fi
185  fi
186
187  dnl Avoid a bug with -O2 with gcc 4.0.1.  Symptom: malloc() reports double
188  dnl free.  This happens in expand_filename(), because the optimizer swaps
189  dnl two blocks of code, both using "repl", that can't be swapped.
190  if test "$MACARCH" = "intel" -o "$MACARCH" = "both"; then
191    CFLAGS=`echo "$CFLAGS" | sed 's/-O[[23456789]]/-Oz/'`
192  fi
193
194else
195  AC_MSG_RESULT(no)
196fi
197
198AC_SUBST(OS_EXTRA_SRC)
199AC_SUBST(OS_EXTRA_OBJ)
200
201dnl Add /usr/local/lib to $LDFLAGS and /usr/local/include to CFLAGS.
202dnl Only when the directory exists and it wasn't there yet.
203dnl For gcc don't do this when it is already in the default search path.
204dnl Skip all of this when cross-compiling.
205if test "$cross_compiling" = no; then
206  AC_MSG_CHECKING(--with-local-dir argument)
207  have_local_include=''
208  have_local_lib=''
209  AC_ARG_WITH([local-dir], [  --with-local-dir=PATH   search PATH instead of /usr/local for local libraries.
210  --without-local-dir     do not search /usr/local for local libraries.], [
211    local_dir="$withval"
212    case "$withval" in
213    */*) ;;
214    no)
215      # avoid adding local dir to LDFLAGS and CPPFLAGS
216      have_local_include=yes
217      have_local_lib=yes
218      ;;
219    *) AC_MSG_ERROR(must pass path argument to --with-local-dir) ;;
220    esac
221	AC_MSG_RESULT($local_dir)
222  ], [
223    local_dir=/usr/local
224    AC_MSG_RESULT(Defaulting to $local_dir)
225  ])
226  if test "$GCC" = yes -a "$local_dir" != no; then
227    echo 'void f(){}' > conftest.c
228    dnl -no-cpp-precomp is needed for OS X 10.2 (Ben Fowler)
229    have_local_include=`${CC-cc} -no-cpp-precomp -c -v conftest.c 2>&1 | grep "${local_dir}/include"`
230    have_local_lib=`${CC-cc} -c -v conftest.c 2>&1 | grep "${local_dir}/lib"`
231    rm -f conftest.c conftest.o
232  fi
233  if test -z "$have_local_lib" -a -d "${local_dir}/lib"; then
234    tt=`echo "$LDFLAGS" | sed -e "s+-L${local_dir}/lib ++g" -e "s+-L${local_dir}/lib$++g"`
235    if test "$tt" = "$LDFLAGS"; then
236      LDFLAGS="$LDFLAGS -L${local_dir}/lib"
237    fi
238  fi
239  if test -z "$have_local_include" -a -d "${local_dir}/include"; then
240    tt=`echo "$CPPFLAGS" | sed -e "s+-I${local_dir}/include ++g" -e "s+-I${local_dir}/include$++g"`
241    if test "$tt" = "$CPPFLAGS"; then
242      CPPFLAGS="$CPPFLAGS -I${local_dir}/include"
243    fi
244  fi
245fi
246
247AC_MSG_CHECKING(--with-vim-name argument)
248AC_ARG_WITH(vim-name, [  --with-vim-name=NAME    what to call the Vim executable],
249	VIMNAME="$withval"; AC_MSG_RESULT($VIMNAME),
250	VIMNAME="vim"; AC_MSG_RESULT(Defaulting to $VIMNAME))
251AC_SUBST(VIMNAME)
252AC_MSG_CHECKING(--with-ex-name argument)
253AC_ARG_WITH(ex-name, [  --with-ex-name=NAME     what to call the Ex executable],
254	EXNAME="$withval"; AC_MSG_RESULT($EXNAME),
255	EXNAME="ex"; AC_MSG_RESULT(Defaulting to ex))
256AC_SUBST(EXNAME)
257AC_MSG_CHECKING(--with-view-name argument)
258AC_ARG_WITH(view-name, [  --with-view-name=NAME   what to call the View executable],
259	VIEWNAME="$withval"; AC_MSG_RESULT($VIEWNAME),
260	VIEWNAME="view"; AC_MSG_RESULT(Defaulting to view))
261AC_SUBST(VIEWNAME)
262
263AC_MSG_CHECKING(--with-global-runtime argument)
264AC_ARG_WITH(global-runtime, [  --with-global-runtime=DIR    global runtime directory in 'runtimepath'],
265	AC_MSG_RESULT($withval); AC_DEFINE_UNQUOTED(RUNTIME_GLOBAL, "$withval"),
266	AC_MSG_RESULT(no))
267
268AC_MSG_CHECKING(--with-modified-by argument)
269AC_ARG_WITH(modified-by, [  --with-modified-by=NAME       name of who modified a release version],
270	AC_MSG_RESULT($withval); AC_DEFINE_UNQUOTED(MODIFIED_BY, "$withval"),
271	AC_MSG_RESULT(no))
272
273dnl Check for EBCDIC stolen from the LYNX port to z/OS Unix
274AC_MSG_CHECKING(if character set is EBCDIC)
275AC_TRY_COMPILE([ ],
276[ /* TryCompile function for CharSet.
277   Treat any failure as ASCII for compatibility with existing art.
278   Use compile-time rather than run-time tests for cross-compiler
279   tolerance.  */
280#if '0'!=240
281make an error "Character set is not EBCDIC"
282#endif ],
283[ # TryCompile action if true
284cf_cv_ebcdic=yes ],
285[ # TryCompile action if false
286cf_cv_ebcdic=no])
287# end of TryCompile ])
288# end of CacheVal CvEbcdic
289AC_MSG_RESULT($cf_cv_ebcdic)
290case "$cf_cv_ebcdic" in  #(vi
291    yes)	AC_DEFINE(EBCDIC)
292		line_break='"\\n"'
293		;;
294    *)		line_break='"\\012"';;
295esac
296AC_SUBST(line_break)
297
298if test "$cf_cv_ebcdic" = "yes"; then
299dnl If we have EBCDIC we most likley have z/OS Unix, let's test it!
300AC_MSG_CHECKING(for z/OS Unix)
301case `uname` in
302    OS/390)	zOSUnix="yes";
303		dnl If using cc the environment variable _CC_CCMODE must be
304		dnl set to "1", so that some compiler extensions are enabled.
305		dnl If using c89 the environment variable is named _CC_C89MODE.
306		dnl Note: compile with c89 never tested.
307		if test "$CC" = "cc"; then
308		  ccm="$_CC_CCMODE"
309		  ccn="CC"
310		else
311		  if test "$CC" = "c89"; then
312		    ccm="$_CC_C89MODE"
313		    ccn="C89"
314		  else
315		    ccm=1
316		  fi
317		fi
318		if test "$ccm" != "1"; then
319		  echo ""
320		  echo "------------------------------------------"
321		  echo " On z/OS Unix, the environment variable"
322		  echo " __CC_${ccn}MODE must be set to \"1\"!"
323		  echo " Do:"
324		  echo "    export _CC_${ccn}MODE=1"
325		  echo " and then call configure again."
326		  echo "------------------------------------------"
327		  exit 1
328		fi
329		CFLAGS="$CFLAGS -D_ALL_SOURCE -Wc,float\\(IEEE\\)";
330                LDFLAGS="$LDFLAGS -Wl,EDIT=NO"
331		AC_MSG_RESULT(yes)
332		;;
333    *)		zOSUnix="no";
334		AC_MSG_RESULT(no)
335		;;
336esac
337fi
338
339dnl Set QUOTESED. Needs additional backslashes on zOS
340if test "$zOSUnix" = "yes"; then
341    QUOTESED="sed -e 's/[[\\\\\"]]/\\\\\\\\&/g' -e 's/\\\\\\\\\"/\"/' -e 's/\\\\\\\\\";\$\$/\";/'"
342else
343    QUOTESED="sed -e 's/[[\\\\\"]]/\\\\&/g' -e 's/\\\\\"/\"/' -e 's/\\\\\";\$\$/\";/'"
344fi
345AC_SUBST(QUOTESED)
346
347
348dnl Link with -lselinux for SELinux stuff; if not found
349AC_MSG_CHECKING(--disable-selinux argument)
350AC_ARG_ENABLE(selinux,
351	[  --disable-selinux	  Don't check for SELinux support.],
352	, enable_selinux="yes")
353if test "$enable_selinux" = "yes"; then
354  AC_MSG_RESULT(no)
355  AC_CHECK_LIB(selinux, is_selinux_enabled,
356	  [LIBS="$LIBS -lselinux"
357	   AC_DEFINE(HAVE_SELINUX)])
358else
359   AC_MSG_RESULT(yes)
360fi
361
362dnl Check user requested features.
363
364AC_MSG_CHECKING(--with-features argument)
365AC_ARG_WITH(features, [  --with-features=TYPE    tiny, small, normal, big or huge (default: normal)],
366	features="$withval"; AC_MSG_RESULT($features),
367	features="normal"; AC_MSG_RESULT(Defaulting to normal))
368
369dovimdiff=""
370dogvimdiff=""
371case "$features" in
372  tiny)		AC_DEFINE(FEAT_TINY) ;;
373  small)	AC_DEFINE(FEAT_SMALL) ;;
374  normal)	AC_DEFINE(FEAT_NORMAL) dovimdiff="installvimdiff";
375			dogvimdiff="installgvimdiff" ;;
376  big)		AC_DEFINE(FEAT_BIG) dovimdiff="installvimdiff";
377			dogvimdiff="installgvimdiff" ;;
378  huge)		AC_DEFINE(FEAT_HUGE) dovimdiff="installvimdiff";
379			dogvimdiff="installgvimdiff" ;;
380  *)		AC_MSG_RESULT([Sorry, $features is not supported]) ;;
381esac
382
383AC_SUBST(dovimdiff)
384AC_SUBST(dogvimdiff)
385
386AC_MSG_CHECKING(--with-compiledby argument)
387AC_ARG_WITH(compiledby, [  --with-compiledby=NAME  name to show in :version message],
388	compiledby="$withval"; AC_MSG_RESULT($withval),
389	compiledby=""; AC_MSG_RESULT(no))
390AC_SUBST(compiledby)
391
392AC_MSG_CHECKING(--disable-xsmp argument)
393AC_ARG_ENABLE(xsmp,
394	[  --disable-xsmp          Disable XSMP session management],
395	, enable_xsmp="yes")
396
397if test "$enable_xsmp" = "yes"; then
398  AC_MSG_RESULT(no)
399  AC_MSG_CHECKING(--disable-xsmp-interact argument)
400  AC_ARG_ENABLE(xsmp-interact,
401	  [  --disable-xsmp-interact Disable XSMP interaction],
402	  , enable_xsmp_interact="yes")
403  if test "$enable_xsmp_interact" = "yes"; then
404    AC_MSG_RESULT(no)
405    AC_DEFINE(USE_XSMP_INTERACT)
406  else
407    AC_MSG_RESULT(yes)
408  fi
409else
410  AC_MSG_RESULT(yes)
411fi
412
413dnl Check for Lua feature.
414AC_MSG_CHECKING(--enable-luainterp argument)
415AC_ARG_ENABLE(luainterp,
416	[  --enable-luainterp[=OPTS]     Include Lua interpreter.  [default=no] [OPTS=no/yes/dynamic]], ,
417	[enable_luainterp="no"])
418AC_MSG_RESULT($enable_luainterp)
419
420if test "$enable_luainterp" = "yes" -o "$enable_luainterp" = "dynamic"; then
421  dnl -- find the lua executable
422  AC_SUBST(vi_cv_path_lua)
423
424  AC_MSG_CHECKING(--with-lua-prefix argument)
425  AC_ARG_WITH(lua_prefix,
426	[  --with-lua-prefix=PFX   Prefix where Lua is installed.],
427	with_lua_prefix="$withval"; AC_MSG_RESULT($with_lua_prefix),
428	with_lua_prefix="";AC_MSG_RESULT(no))
429
430  if test "X$with_lua_prefix" != "X"; then
431       vi_cv_path_lua_pfx="$with_lua_prefix"
432  else
433    AC_MSG_CHECKING(LUA_PREFIX environment var)
434    if test "X$LUA_PREFIX" != "X"; then
435	AC_MSG_RESULT("$LUA_PREFIX")
436	vi_cv_path_lua_pfx="$LUA_PREFIX"
437    else
438	AC_MSG_RESULT([not set, default to /usr])
439	vi_cv_path_lua_pfx="/usr"
440    fi
441  fi
442
443  LUA_INC=
444  if test "X$vi_cv_path_lua_pfx" != "X"; then
445    AC_MSG_CHECKING(if lua.h can be found in $vi_cv_path_lua_pfx/include)
446    if test -f $vi_cv_path_lua_pfx/include/lua.h; then
447      AC_MSG_RESULT(yes)
448    else
449      AC_MSG_RESULT(no)
450      dnl -- try to find Lua executable
451      AC_PATH_PROG(vi_cv_path_lua, lua)
452      if test "X$vi_cv_path_lua" != "X"; then
453        dnl -- find Lua version
454        AC_CACHE_CHECK(Lua version, vi_cv_version_lua,
455        [ vi_cv_version_lua=`${vi_cv_path_lua} -e "print(_VERSION)" | sed 's/.* //'` ])
456        AC_MSG_CHECKING(if lua.h can be found in $vi_cv_path_lua_pfx/include/lua$vi_cv_version_lua)
457        if test -f $vi_cv_path_lua_pfx/include/lua$vi_cv_version_lua/lua.h; then
458          AC_MSG_RESULT(yes)
459          LUA_INC=/lua$vi_cv_version_lua
460        else
461          AC_MSG_RESULT(no)
462          vi_cv_path_lua_pfx=
463        fi
464      fi
465    fi
466  fi
467
468  if test "X$vi_cv_path_lua_pfx" != "X"; then
469    if test "X$vi_cv_version_lua" != "X"; then
470      dnl Test alternate location using version
471      LUA_LIBS="-L${vi_cv_path_lua_pfx}/lib -llua$vi_cv_version_lua"
472    else
473      LUA_LIBS="-L${vi_cv_path_lua_pfx}/lib -llua"
474    fi
475    LUA_CFLAGS="-I${vi_cv_path_lua_pfx}/include${LUA_INC}"
476    LUA_SRC="if_lua.c"
477    LUA_OBJ="objects/if_lua.o"
478    LUA_PRO="if_lua.pro"
479    AC_DEFINE(FEAT_LUA)
480    if test "$enable_luainterp" = "dynamic"; then
481      dnl Determine the SONAME for the current version, but fallback to
482      dnl liblua${vi_cv_version_lua}.so if no SONAME-versioned file is found.
483      for i in 0 1 2 3 4 5 6 7 8 9; do
484	if test -f "${vi_cv_path_lua_pfx}/lib/liblua${vi_cv_version_lua}.so.$i"; then
485	  LUA_SONAME=".$i"
486	  break
487	fi
488      done
489      AC_DEFINE(DYNAMIC_LUA)
490      LUA_LIBS=""
491      LUA_CFLAGS="-DDYNAMIC_LUA_DLL=\\\"liblua${vi_cv_version_lua}.so$LUA_SONAME\\\" $LUA_CFLAGS"
492    fi
493  fi
494  AC_SUBST(LUA_SRC)
495  AC_SUBST(LUA_OBJ)
496  AC_SUBST(LUA_PRO)
497  AC_SUBST(LUA_LIBS)
498  AC_SUBST(LUA_CFLAGS)
499fi
500
501
502dnl Check for MzScheme feature.
503AC_MSG_CHECKING(--enable-mzschemeinterp argument)
504AC_ARG_ENABLE(mzschemeinterp,
505	[  --enable-mzschemeinterp   Include MzScheme interpreter.], ,
506	[enable_mzschemeinterp="no"])
507AC_MSG_RESULT($enable_mzschemeinterp)
508
509if test "$enable_mzschemeinterp" = "yes"; then
510  dnl -- find the mzscheme executable
511  AC_SUBST(vi_cv_path_mzscheme)
512
513  AC_MSG_CHECKING(--with-plthome argument)
514  AC_ARG_WITH(plthome,
515	[  --with-plthome=PLTHOME   Use PLTHOME.],
516	with_plthome="$withval"; AC_MSG_RESULT($with_plthome),
517	with_plthome="";AC_MSG_RESULT("no"))
518
519  if test "X$with_plthome" != "X"; then
520       vi_cv_path_mzscheme_pfx="$with_plthome"
521  else
522    AC_MSG_CHECKING(PLTHOME environment var)
523    if test "X$PLTHOME" != "X"; then
524	AC_MSG_RESULT("$PLTHOME")
525	vi_cv_path_mzscheme_pfx="$PLTHOME"
526    else
527	AC_MSG_RESULT(not set)
528	dnl -- try to find MzScheme executable
529	AC_PATH_PROG(vi_cv_path_mzscheme, mzscheme)
530
531	dnl resolve symbolic link, the executable is often elsewhere and there
532	dnl are no links for the include files.
533	if test "X$vi_cv_path_mzscheme" != "X"; then
534	  lsout=`ls -l $vi_cv_path_mzscheme`
535	  if echo "$lsout" | grep -e '->' >/dev/null 2>/dev/null; then
536	    vi_cv_path_mzscheme=`echo "$lsout" | sed 's/.*-> \(.*\)/\1/'`
537	  fi
538	fi
539
540	if test "X$vi_cv_path_mzscheme" != "X"; then
541	    dnl -- find where MzScheme thinks it was installed
542	    AC_CACHE_CHECK(MzScheme install prefix,vi_cv_path_mzscheme_pfx,
543	    dnl different versions of MzScheme differ in command line processing
544	    dnl use universal approach
545	    echo "(display (simplify-path		\
546	       (build-path (call-with-values	\
547		(lambda () (split-path (find-system-path (quote exec-file)))) \
548		(lambda (base name must-be-dir?) base)) (quote up))))" > mzdirs.scm
549	    dnl Remove a trailing slash
550	    [ vi_cv_path_mzscheme_pfx=`${vi_cv_path_mzscheme} -r mzdirs.scm | \
551		sed -e 's+/$++'` ])
552	    rm -f mzdirs.scm
553	fi
554    fi
555  fi
556
557  SCHEME_INC=
558  if test "X$vi_cv_path_mzscheme_pfx" != "X"; then
559    AC_MSG_CHECKING(if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include)
560    if test -f $vi_cv_path_mzscheme_pfx/include/scheme.h; then
561      SCHEME_INC=${vi_cv_path_mzscheme_pfx}/include
562      AC_MSG_RESULT(yes)
563    else
564      AC_MSG_RESULT(no)
565      AC_MSG_CHECKING(if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include/plt)
566      if test -f $vi_cv_path_mzscheme_pfx/include/plt/scheme.h; then
567	AC_MSG_RESULT(yes)
568	SCHEME_INC=${vi_cv_path_mzscheme_pfx}/include/plt
569      else
570	AC_MSG_RESULT(no)
571	AC_MSG_CHECKING(if scheme.h can be found in /usr/include/plt/)
572	if test -f /usr/include/plt/scheme.h; then
573	  AC_MSG_RESULT(yes)
574	  SCHEME_INC=/usr/include/plt
575	else
576	  AC_MSG_RESULT(no)
577	  vi_cv_path_mzscheme_pfx=
578	fi
579      fi
580    fi
581  fi
582
583  if test "X$vi_cv_path_mzscheme_pfx" != "X"; then
584    if test "x$MACOSX" = "xyes"; then
585      MZSCHEME_LIBS="-framework PLT_MzScheme"
586    elif test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzscheme3m.a"; then
587      MZSCHEME_LIBS="${vi_cv_path_mzscheme_pfx}/lib/libmzscheme3m.a"
588      MZSCHEME_CFLAGS="-DMZ_PRECISE_GC"
589    elif test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"; then
590      MZSCHEME_LIBS="${vi_cv_path_mzscheme_pfx}/lib/libmzscheme.a ${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"
591    else
592      dnl Using shared objects
593      if test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzscheme3m.so"; then
594        MZSCHEME_LIBS="-L${vi_cv_path_mzscheme_pfx}/lib -lmzscheme3m"
595	MZSCHEME_CFLAGS="-DMZ_PRECISE_GC"
596      else
597        MZSCHEME_LIBS="-L${vi_cv_path_mzscheme_pfx}/lib -lmzscheme -lmzgc"
598      fi
599      if test "$GCC" = yes; then
600	dnl Make Vim remember the path to the library.  For when it's not in
601	dnl $LD_LIBRARY_PATH.
602	MZSCHEME_LIBS="${MZSCHEME_LIBS} -Wl,-rpath -Wl,${vi_cv_path_mzscheme_pfx}/lib"
603      elif test "`(uname) 2>/dev/null`" = SunOS &&
604			       uname -r | grep '^5' >/dev/null; then
605	MZSCHEME_LIBS="${MZSCHEME_LIBS} -R ${vi_cv_path_mzscheme_pfx}/lib"
606      fi
607    fi
608    if test -d $vi_cv_path_mzscheme_pfx/lib/plt/collects; then
609      SCHEME_COLLECTS=lib/plt/
610    fi
611    if test -f "${vi_cv_path_mzscheme_pfx}/${SCHEME_COLLECTS}collects/scheme/base.ss" ; then
612      dnl need to generate bytecode for MzScheme base
613      MZSCHEME_EXTRA="mzscheme_base.c"
614      MZSCHEME_CFLAGS="${MZSCHEME_CFLAGS} -DINCLUDE_MZSCHEME_BASE"
615      MZSCHEME_MZC="${vi_cv_path_mzscheme_pfx}/bin/mzc"
616    fi
617    MZSCHEME_CFLAGS="${MZSCHEME_CFLAGS} -I${SCHEME_INC} \
618      -DMZSCHEME_COLLECTS='\"${vi_cv_path_mzscheme_pfx}/${SCHEME_COLLECTS}collects\"'"
619    MZSCHEME_SRC="if_mzsch.c"
620    MZSCHEME_OBJ="objects/if_mzsch.o"
621    MZSCHEME_PRO="if_mzsch.pro"
622    AC_DEFINE(FEAT_MZSCHEME)
623  fi
624  AC_SUBST(MZSCHEME_SRC)
625  AC_SUBST(MZSCHEME_OBJ)
626  AC_SUBST(MZSCHEME_PRO)
627  AC_SUBST(MZSCHEME_LIBS)
628  AC_SUBST(MZSCHEME_CFLAGS)
629  AC_SUBST(MZSCHEME_EXTRA)
630  AC_SUBST(MZSCHEME_MZC)
631fi
632
633
634AC_MSG_CHECKING(--enable-perlinterp argument)
635AC_ARG_ENABLE(perlinterp,
636	[  --enable-perlinterp[=OPTS]     Include Perl interpreter.  [default=no] [OPTS=no/yes/dynamic]], ,
637	[enable_perlinterp="no"])
638AC_MSG_RESULT($enable_perlinterp)
639if test "$enable_perlinterp" = "yes" -o "$enable_perlinterp" = "dynamic"; then
640  AC_SUBST(vi_cv_path_perl)
641  AC_PATH_PROG(vi_cv_path_perl, perl)
642  if test "X$vi_cv_path_perl" != "X"; then
643    AC_MSG_CHECKING(Perl version)
644    if $vi_cv_path_perl -e 'require 5.003_01' >/dev/null 2>/dev/null; then
645     eval `$vi_cv_path_perl -V:usethreads`
646     eval `$vi_cv_path_perl -V:libperl`
647     if test "X$usethreads" = "XUNKNOWN" -o "X$usethreads" = "Xundef"; then
648       badthreads=no
649     else
650       if $vi_cv_path_perl -e 'require 5.6.0' >/dev/null 2>/dev/null; then
651	 eval `$vi_cv_path_perl -V:use5005threads`
652	 if test "X$use5005threads" = "XUNKNOWN" -o "X$use5005threads" = "Xundef"; then
653	   badthreads=no
654	 else
655	   badthreads=yes
656	   AC_MSG_RESULT(>>> Perl > 5.6 with 5.5 threads cannot be used <<<)
657	 fi
658       else
659	 badthreads=yes
660	 AC_MSG_RESULT(>>> Perl 5.5 with threads cannot be used <<<)
661       fi
662     fi
663     if test $badthreads = no; then
664      AC_MSG_RESULT(OK)
665      eval `$vi_cv_path_perl -V:shrpenv`
666      if test "X$shrpenv" = "XUNKNOWN"; then # pre 5.003_04
667	shrpenv=""
668      fi
669      vi_cv_perllib=`$vi_cv_path_perl -MConfig -e 'print $Config{privlibexp}'`
670      AC_SUBST(vi_cv_perllib)
671      dnl Remove "-fno-something", it breaks using cproto.
672      perlcppflags=`$vi_cv_path_perl -Mlib=$srcdir -MExtUtils::Embed \
673	      -e 'ccflags;perl_inc;print"\n"' | sed -e 's/-fno[[^ ]]*//'`
674      dnl Remove "-lc", it breaks on FreeBSD when using "-pthread".
675      perllibs=`cd $srcdir; $vi_cv_path_perl -MExtUtils::Embed -e 'ldopts' | \
676		sed -e '/Warning/d' -e '/Note (probably harmless)/d' \
677			-e 's/-bE:perl.exp//' -e 's/-lc //'`
678      dnl Don't add perl lib to $LIBS: if it's not in LD_LIBRARY_PATH
679      dnl a test in configure may fail because of that.
680      perlldflags=`cd $srcdir; $vi_cv_path_perl -MExtUtils::Embed \
681		-e 'ccdlflags' | sed -e 's/-bE:perl.exp//'`
682
683      dnl check that compiling a simple program still works with the flags
684      dnl added for Perl.
685      AC_MSG_CHECKING([if compile and link flags for Perl are sane])
686      cflags_save=$CFLAGS
687      libs_save=$LIBS
688      ldflags_save=$LDFLAGS
689      CFLAGS="$CFLAGS $perlcppflags"
690      LIBS="$LIBS $perllibs"
691      LDFLAGS="$perlldflags $LDFLAGS"
692      AC_TRY_LINK(,[ ],
693	     AC_MSG_RESULT(yes); perl_ok=yes,
694	     AC_MSG_RESULT(no: PERL DISABLED); perl_ok=no)
695      CFLAGS=$cflags_save
696      LIBS=$libs_save
697      LDFLAGS=$ldflags_save
698      if test $perl_ok = yes; then
699	if test "X$perlcppflags" != "X"; then
700	  dnl remove -pipe and -Wxxx, it confuses cproto
701	  PERL_CFLAGS=`echo "$perlcppflags" | sed -e 's/-pipe //' -e 's/-W[[^ ]]*//'`
702	fi
703	if test "X$perlldflags" != "X"; then
704	  LDFLAGS="$perlldflags $LDFLAGS"
705	fi
706	PERL_LIBS=$perllibs
707	PERL_SRC="auto/if_perl.c if_perlsfio.c"
708	PERL_OBJ="objects/if_perl.o objects/if_perlsfio.o"
709	PERL_PRO="if_perl.pro if_perlsfio.pro"
710	AC_DEFINE(FEAT_PERL)
711      fi
712     fi
713    else
714      AC_MSG_RESULT(>>> too old; need Perl version 5.003_01 or later <<<)
715    fi
716  fi
717
718  if test "x$MACOSX" = "xyes"; then
719    dnl Mac OS X 10.2 or later
720    dir=/System/Library/Perl
721    darwindir=$dir/darwin
722    if test -d $darwindir; then
723      PERL=/usr/bin/perl
724    else
725      dnl Mac OS X 10.3
726      dir=/System/Library/Perl/5.8.1
727      darwindir=$dir/darwin-thread-multi-2level
728      if test -d $darwindir; then
729	PERL=/usr/bin/perl
730      fi
731    fi
732    if test -n "$PERL"; then
733      PERL_DIR="$dir"
734      PERL_CFLAGS="-DFEAT_PERL -I$darwindir/CORE"
735      PERL_OBJ="objects/if_perl.o objects/if_perlsfio.o $darwindir/auto/DynaLoader/DynaLoader.a"
736      PERL_LIBS="-L$darwindir/CORE -lperl"
737    fi
738    dnl Perl on Mac OS X 10.5 adds "-arch" flags but these should only
739    dnl be included if requested by passing --with-mac-arch to
740    dnl configure, so strip these flags first (if present)
741    PERL_LIBS=`echo "$PERL_LIBS" | sed -e 's/-arch\ ppc//' -e 's/-arch\ i386//' -e 's/-arch\ x86_64//'`
742    PERL_CFLAGS=`echo "$PERL_CFLAGS" | sed -e 's/-arch\ ppc//' -e 's/-arch\ i386//' -e 's/-arch\ x86_64//'`
743  fi
744  if test "$enable_perlinterp" = "dynamic"; then
745    if test "$perl_ok" = "yes" -a "X$libperl" != "X"; then
746      AC_DEFINE(DYNAMIC_PERL)
747      PERL_CFLAGS="-DDYNAMIC_PERL_DLL=\\\"$libperl\\\" $PERL_CFLAGS"
748    fi
749  fi
750fi
751AC_SUBST(shrpenv)
752AC_SUBST(PERL_SRC)
753AC_SUBST(PERL_OBJ)
754AC_SUBST(PERL_PRO)
755AC_SUBST(PERL_CFLAGS)
756AC_SUBST(PERL_LIBS)
757
758AC_MSG_CHECKING(--enable-pythoninterp argument)
759AC_ARG_ENABLE(pythoninterp,
760	[  --enable-pythoninterp[=OPTS]   Include Python interpreter. [default=no] [OPTS=no/yes/dynamic]], ,
761	[enable_pythoninterp="no"])
762AC_MSG_RESULT($enable_pythoninterp)
763if test "$enable_pythoninterp" = "yes" -o "$enable_pythoninterp" = "dynamic"; then
764  dnl -- find the python executable
765  AC_PATH_PROG(vi_cv_path_python, python)
766  if test "X$vi_cv_path_python" != "X"; then
767
768    dnl -- get its version number
769    AC_CACHE_CHECK(Python version,vi_cv_var_python_version,
770    [[vi_cv_var_python_version=`
771	    ${vi_cv_path_python} -c 'import sys; print sys.version[:3]'`
772    ]])
773
774    dnl -- it must be at least version 1.4
775    AC_MSG_CHECKING(Python is 1.4 or better)
776    if ${vi_cv_path_python} -c \
777	"import sys; sys.exit(${vi_cv_var_python_version} < 1.4)"
778    then
779      AC_MSG_RESULT(yep)
780
781      dnl -- find where python thinks it was installed
782      AC_CACHE_CHECK(Python's install prefix,vi_cv_path_python_pfx,
783      [ vi_cv_path_python_pfx=`
784	    ${vi_cv_path_python} -c \
785		"import sys; print sys.prefix"` ])
786
787      dnl -- and where it thinks it runs
788      AC_CACHE_CHECK(Python's execution prefix,vi_cv_path_python_epfx,
789      [ vi_cv_path_python_epfx=`
790	    ${vi_cv_path_python} -c \
791		"import sys; print sys.exec_prefix"` ])
792
793      dnl -- python's internal library path
794
795      AC_CACHE_VAL(vi_cv_path_pythonpath,
796      [ vi_cv_path_pythonpath=`
797	    unset PYTHONPATH;
798	    ${vi_cv_path_python} -c \
799		"import sys, string; print string.join(sys.path,':')"` ])
800
801      dnl -- where the Python implementation library archives are
802
803      AC_ARG_WITH(python-config-dir,
804	[  --with-python-config-dir=PATH  Python's config directory],
805	[ vi_cv_path_python_conf="${withval}" ] )
806
807      AC_CACHE_CHECK(Python's configuration directory,vi_cv_path_python_conf,
808      [
809	vi_cv_path_python_conf=
810	for path in "${vi_cv_path_python_pfx}" "${vi_cv_path_python_epfx}"; do
811	  for subdir in lib64 lib share; do
812	    d="${path}/${subdir}/python${vi_cv_var_python_version}/config"
813	    if test -d "$d" && test -f "$d/config.c"; then
814	      vi_cv_path_python_conf="$d"
815	    fi
816	  done
817	done
818      ])
819
820      PYTHON_CONFDIR="${vi_cv_path_python_conf}"
821
822      if test "X$PYTHON_CONFDIR" = "X"; then
823	AC_MSG_RESULT([can't find it!])
824      else
825
826	dnl -- we need to examine Python's config/Makefile too
827	dnl    see what the interpreter is built from
828	AC_CACHE_VAL(vi_cv_path_python_plibs,
829	[
830	    pwd=`pwd`
831	    tmp_mkf="$pwd/config-PyMake$$"
832	    cat -- "${PYTHON_CONFDIR}/Makefile" - <<'eof' >"${tmp_mkf}"
833__:
834	@echo "python_BASEMODLIBS='$(BASEMODLIBS)'"
835	@echo "python_LIBS='$(LIBS)'"
836	@echo "python_SYSLIBS='$(SYSLIBS)'"
837	@echo "python_LINKFORSHARED='$(LINKFORSHARED)'"
838	@echo "python_INSTSONAME='$(INSTSONAME)'"
839eof
840	    dnl -- delete the lines from make about Entering/Leaving directory
841	    eval "`cd ${PYTHON_CONFDIR} && make -f "${tmp_mkf}" __ | sed '/ directory /d'`"
842	    rm -f -- "${tmp_mkf}"
843	    if test "x$MACOSX" = "xyes" && ${vi_cv_path_python} -c \
844		"import sys; sys.exit(${vi_cv_var_python_version} < 2.3)"; then
845	      vi_cv_path_python_plibs="-framework Python"
846	    else
847	      if test "${vi_cv_var_python_version}" = "1.4"; then
848		  vi_cv_path_python_plibs="${PYTHON_CONFDIR}/libModules.a ${PYTHON_CONFDIR}/libPython.a ${PYTHON_CONFDIR}/libObjects.a ${PYTHON_CONFDIR}/libParser.a"
849	      else
850		  vi_cv_path_python_plibs="-L${PYTHON_CONFDIR} -lpython${vi_cv_var_python_version}"
851	      fi
852	      vi_cv_path_python_plibs="${vi_cv_path_python_plibs} ${python_BASEMODLIBS} ${python_LIBS} ${python_SYSLIBS} ${python_LINKFORSHARED}"
853	      dnl remove -ltermcap, it can conflict with an earlier -lncurses
854	      vi_cv_path_python_plibs=`echo $vi_cv_path_python_plibs | sed s/-ltermcap//`
855	    fi
856	])
857
858	PYTHON_LIBS="${vi_cv_path_python_plibs}"
859	if test "${vi_cv_path_python_pfx}" = "${vi_cv_path_python_epfx}"; then
860	  PYTHON_CFLAGS="-I${vi_cv_path_python_pfx}/include/python${vi_cv_var_python_version}"
861	else
862	  PYTHON_CFLAGS="-I${vi_cv_path_python_pfx}/include/python${vi_cv_var_python_version} -I${vi_cv_path_python_epfx}/include/python${vi_cv_var_python_version}"
863	fi
864	PYTHON_SRC="if_python.c"
865	dnl For Mac OSX 10.2 config.o is included in the Python library.
866	if test "x$MACOSX" = "xyes"; then
867	  PYTHON_OBJ="objects/if_python.o"
868	else
869	  PYTHON_OBJ="objects/if_python.o objects/py_config.o"
870	fi
871	if test "${vi_cv_var_python_version}" = "1.4"; then
872	   PYTHON_OBJ="$PYTHON_OBJ objects/py_getpath.o"
873	fi
874	PYTHON_GETPATH_CFLAGS="-DPYTHONPATH='\"${vi_cv_path_pythonpath}\"' -DPREFIX='\"${vi_cv_path_python_pfx}\"' -DEXEC_PREFIX='\"${vi_cv_path_python_epfx}\"'"
875
876	dnl On FreeBSD linking with "-pthread" is required to use threads.
877	dnl _THREAD_SAFE must be used for compiling then.
878	dnl The "-pthread" is added to $LIBS, so that the following check for
879	dnl sigaltstack() will look in libc_r (it's there in libc!).
880	dnl Otherwise, when using GCC, try adding -pthread to $CFLAGS.  GCC
881	dnl will then define target-specific defines, e.g., -D_REENTRANT.
882	dnl Don't do this for Mac OSX, -pthread will generate a warning.
883	AC_MSG_CHECKING([if -pthread should be used])
884	threadsafe_flag=
885	thread_lib=
886	dnl if test "x$MACOSX" != "xyes"; then
887        if test "`(uname) 2>/dev/null`" != Darwin; then
888	  test "$GCC" = yes && threadsafe_flag="-pthread"
889	  if test "`(uname) 2>/dev/null`" = FreeBSD; then
890	    threadsafe_flag="-D_THREAD_SAFE"
891	    thread_lib="-pthread"
892	  fi
893	fi
894	libs_save_old=$LIBS
895	if test -n "$threadsafe_flag"; then
896	  cflags_save=$CFLAGS
897	  CFLAGS="$CFLAGS $threadsafe_flag"
898	  LIBS="$LIBS $thread_lib"
899	  AC_TRY_LINK(,[ ],
900	     AC_MSG_RESULT(yes); PYTHON_CFLAGS="$PYTHON_CFLAGS $threadsafe_flag",
901	     AC_MSG_RESULT(no); LIBS=$libs_save_old
902	     )
903	  CFLAGS=$cflags_save
904	else
905	  AC_MSG_RESULT(no)
906	fi
907
908	dnl Check that compiling a simple program still works with the flags
909	dnl added for Python.
910	AC_MSG_CHECKING([if compile and link flags for Python are sane])
911	cflags_save=$CFLAGS
912	libs_save=$LIBS
913	CFLAGS="$CFLAGS $PYTHON_CFLAGS"
914	LIBS="$LIBS $PYTHON_LIBS"
915	AC_TRY_LINK(,[ ],
916	       AC_MSG_RESULT(yes); python_ok=yes,
917	       AC_MSG_RESULT(no: PYTHON DISABLED); python_ok=no)
918	CFLAGS=$cflags_save
919	LIBS=$libs_save
920	if test $python_ok = yes; then
921	  AC_DEFINE(FEAT_PYTHON)
922	else
923	  LIBS=$libs_save_old
924	  PYTHON_SRC=
925	  PYTHON_OBJ=
926	  PYTHON_LIBS=
927	  PYTHON_CFLAGS=
928	fi
929
930      fi
931    else
932      AC_MSG_RESULT(too old)
933    fi
934  fi
935fi
936
937AC_SUBST(PYTHON_CONFDIR)
938AC_SUBST(PYTHON_LIBS)
939AC_SUBST(PYTHON_GETPATH_CFLAGS)
940AC_SUBST(PYTHON_CFLAGS)
941AC_SUBST(PYTHON_SRC)
942AC_SUBST(PYTHON_OBJ)
943
944
945AC_MSG_CHECKING(--enable-python3interp argument)
946AC_ARG_ENABLE(python3interp,
947	[  --enable-python3interp[=OPTS]   Include Python3 interpreter. [default=no] [OPTS=no/yes/dynamic]], ,
948	[enable_python3interp="no"])
949AC_MSG_RESULT($enable_python3interp)
950if test "$enable_python3interp" = "yes" -o "$enable_python3interp" = "dynamic"; then
951  dnl -- find the python3 executable
952  AC_PATH_PROG(vi_cv_path_python3, python3)
953  if test "X$vi_cv_path_python3" != "X"; then
954
955    dnl -- get its version number
956    AC_CACHE_CHECK(Python version,vi_cv_var_python3_version,
957    [[vi_cv_var_python3_version=`
958          ${vi_cv_path_python3} -c 'import sys; print(sys.version[:3])'`
959    ]])
960
961    dnl -- find where python3 thinks it was installed
962    AC_CACHE_CHECK(Python's install prefix,vi_cv_path_python3_pfx,
963    [ vi_cv_path_python3_pfx=`
964     ${vi_cv_path_python3} -c \
965     "import sys; print(sys.prefix)"` ])
966
967    dnl -- and where it thinks it runs
968    AC_CACHE_CHECK(Python's execution prefix,vi_cv_path_python3_epfx,
969    [ vi_cv_path_python3_epfx=`
970     ${vi_cv_path_python3} -c \
971     "import sys; print(sys.exec_prefix)"` ])
972
973    dnl -- python3's internal library path
974
975    AC_CACHE_VAL(vi_cv_path_python3path,
976    [ vi_cv_path_python3path=`
977     unset PYTHONPATH;
978     ${vi_cv_path_python3} -c \
979     "import sys, string; print(':'.join(sys.path))"` ])
980
981    dnl -- where the Python implementation library archives are
982
983    AC_ARG_WITH(python3-config-dir,
984     [  --with-python3-config-dir=PATH  Python's config directory],
985     [ vi_cv_path_python3_conf="${withval}" ] )
986
987    AC_CACHE_CHECK(Python's configuration directory,vi_cv_path_python3_conf,
988    [
989     vi_cv_path_python3_conf=
990     for path in "${vi_cv_path_python3_pfx}" "${vi_cv_path_python3_epfx}"; do
991       for subdir in lib64 lib share; do
992         d="${path}/${subdir}/python${vi_cv_var_python3_version}/config"
993         if test -d "$d" && test -f "$d/config.c"; then
994           vi_cv_path_python3_conf="$d"
995         fi
996       done
997     done
998    ])
999
1000    PYTHON3_CONFDIR="${vi_cv_path_python3_conf}"
1001
1002    if test "X$PYTHON3_CONFDIR" = "X"; then
1003      AC_MSG_RESULT([can't find it!])
1004    else
1005
1006      dnl -- we need to examine Python's config/Makefile too
1007      dnl    see what the interpreter is built from
1008      AC_CACHE_VAL(vi_cv_path_python3_plibs,
1009      [
1010          pwd=`pwd`
1011          tmp_mkf="$pwd/config-PyMake$$"
1012          cat -- "${PYTHON3_CONFDIR}/Makefile" - <<'eof' >"${tmp_mkf}"
1013__:
1014	@echo "python3_BASEMODLIBS='$(BASEMODLIBS)'"
1015	@echo "python3_LIBS='$(LIBS)'"
1016	@echo "python3_SYSLIBS='$(SYSLIBS)'"
1017	@echo "python3_LINKFORSHARED='$(LINKFORSHARED)'"
1018	@echo "python3_INSTSONAME='$(INSTSONAME)'"
1019eof
1020          dnl -- delete the lines from make about Entering/Leaving directory
1021          eval "`cd ${PYTHON3_CONFDIR} && make -f "${tmp_mkf}" __ | sed '/ directory /d'`"
1022          rm -f -- "${tmp_mkf}"
1023          vi_cv_path_python3_plibs="-L${PYTHON3_CONFDIR} -lpython${vi_cv_var_python3_version}"
1024          vi_cv_path_python3_plibs="${vi_cv_path_python3_plibs} ${python3_BASEMODLIBS} ${python3_LIBS} ${python3_SYSLIBS} ${python3_LINKFORSHARED}"
1025          dnl remove -ltermcap, it can conflict with an earlier -lncurses
1026          vi_cv_path_python3_plibs=`echo $vi_cv_path_python3_plibs | sed s/-ltermcap//`
1027          vi_cv_path_python3_plibs=`echo $vi_cv_path_python3_plibs | sed s/-lffi//`
1028      ])
1029
1030      PYTHON3_LIBS="${vi_cv_path_python3_plibs}"
1031      if test "${vi_cv_path_python3_pfx}" = "${vi_cv_path_python3_epfx}"; then
1032        PYTHON3_CFLAGS="-I${vi_cv_path_python3_pfx}/include/python${vi_cv_var_python3_version}"
1033      else
1034        PYTHON3_CFLAGS="-I${vi_cv_path_python3_pfx}/include/python${vi_cv_var_python3_version} -I${vi_cv_path_python3_epfx}/include/python${vi_cv_var_python3_version}"
1035      fi
1036      PYTHON3_SRC="if_python3.c"
1037      dnl For Mac OSX 10.2 config.o is included in the Python library.
1038      if test "x$MACOSX" = "xyes"; then
1039        PYTHON3_OBJ="objects/if_python3.o"
1040      else
1041        PYTHON3_OBJ="objects/if_python3.o objects/py3_config.o"
1042      fi
1043
1044      dnl On FreeBSD linking with "-pthread" is required to use threads.
1045      dnl _THREAD_SAFE must be used for compiling then.
1046      dnl The "-pthread" is added to $LIBS, so that the following check for
1047      dnl sigaltstack() will look in libc_r (it's there in libc!).
1048      dnl Otherwise, when using GCC, try adding -pthread to $CFLAGS.  GCC
1049      dnl will then define target-specific defines, e.g., -D_REENTRANT.
1050      dnl Don't do this for Mac OSX, -pthread will generate a warning.
1051      AC_MSG_CHECKING([if -pthread should be used])
1052      threadsafe_flag=
1053      thread_lib=
1054      dnl if test "x$MACOSX" != "xyes"; then
1055      if test "`(uname) 2>/dev/null`" != Darwin; then
1056        test "$GCC" = yes && threadsafe_flag="-pthread"
1057        if test "`(uname) 2>/dev/null`" = FreeBSD; then
1058          threadsafe_flag="-D_THREAD_SAFE"
1059          thread_lib="-pthread"
1060        fi
1061      fi
1062      libs_save_old=$LIBS
1063      if test -n "$threadsafe_flag"; then
1064        cflags_save=$CFLAGS
1065        CFLAGS="$CFLAGS $threadsafe_flag"
1066        LIBS="$LIBS $thread_lib"
1067        AC_TRY_LINK(,[ ],
1068           AC_MSG_RESULT(yes); PYTHON3_CFLAGS="$PYTHON3_CFLAGS $threadsafe_flag",
1069           AC_MSG_RESULT(no); LIBS=$libs_save_old
1070           )
1071        CFLAGS=$cflags_save
1072      else
1073        AC_MSG_RESULT(no)
1074      fi
1075
1076      dnl check that compiling a simple program still works with the flags
1077      dnl added for Python.
1078      AC_MSG_CHECKING([if compile and link flags for Python 3 are sane])
1079      cflags_save=$CFLAGS
1080      libs_save=$LIBS
1081      CFLAGS="$CFLAGS $PYTHON3_CFLAGS"
1082      LIBS="$LIBS $PYTHON3_LIBS"
1083      AC_TRY_LINK(,[ ],
1084             AC_MSG_RESULT(yes); python3_ok=yes,
1085             AC_MSG_RESULT(no: PYTHON3 DISABLED); python3_ok=no)
1086      CFLAGS=$cflags_save
1087      LIBS=$libs_save
1088      if test "$python3_ok" = yes; then
1089        AC_DEFINE(FEAT_PYTHON3)
1090      else
1091        LIBS=$libs_save_old
1092        PYTHON3_SRC=
1093        PYTHON3_OBJ=
1094        PYTHON3_LIBS=
1095        PYTHON3_CFLAGS=
1096      fi
1097    fi
1098  fi
1099fi
1100
1101AC_SUBST(PYTHON3_CONFDIR)
1102AC_SUBST(PYTHON3_LIBS)
1103AC_SUBST(PYTHON3_CFLAGS)
1104AC_SUBST(PYTHON3_SRC)
1105AC_SUBST(PYTHON3_OBJ)
1106
1107dnl if python2.x and python3.x are enabled one can only link in code
1108dnl with dlopen(), dlsym(), dlclose() 
1109if test "$python_ok" = yes && test "$python3_ok" = yes; then
1110  AC_DEFINE(DYNAMIC_PYTHON)
1111  AC_DEFINE(DYNAMIC_PYTHON3)
1112  AC_MSG_CHECKING(whether we can do without RTLD_GLOBAL)
1113  cflags_save=$CFLAGS
1114  CFLAGS="$CFLAGS $PYTHON3_CFLAGS"
1115  ldflags_save=$LDFLAGS
1116  LDFLAGS="$LDFLAGS -ldl"
1117  AC_RUN_IFELSE([
1118    #include <dlfcn.h>
1119    /* If this program fails, then RTLD_GLOBAL is needed.
1120     * RTLD_GLOBAL will be used and then it is not possible to
1121     * have both python versions enabled in the same vim instance.
1122     * Only the first pyhton version used will be switched on.
1123     */
1124
1125    int no_rtl_global_needed_for(char *python_instsoname)
1126    {
1127      int needed = 0;
1128      void* pylib = dlopen(python_instsoname, RTLD_LAZY);
1129      if (pylib != 0)
1130      {
1131          void (*init)(void) = dlsym(pylib, "Py_Initialize");
1132          int (*simple)(char*) = dlsym(pylib, "PyRun_SimpleString");
1133          void (*final)(void) = dlsym(pylib, "Py_Finalize");
1134          (*init)();
1135          needed = (*simple)("import termios") == -1;
1136          (*final)();
1137          dlclose(pylib);
1138      }
1139      return !needed;
1140    }
1141
1142    int main(int argc, char** argv)
1143    {
1144      int not_needed = 0;
1145      if (no_rtl_global_needed_for("libpython2.7.so.1.0") && no_rtl_global_needed_for("libpython3.1.so.1.0"))
1146            not_needed = 1;
1147      return !not_needed;
1148    }],
1149    [AC_MSG_RESULT(yes);AC_DEFINE(PY_NO_RTLD_GLOBAL)], [AC_MSG_RESULT(no)])
1150  CFLAGS=$cflags_save
1151  LDFLAGS=$ldflags_save
1152  PYTHON_SRC="if_python.c"
1153  PYTHON_OBJ="objects/if_python.o"
1154  PYTHON_CFLAGS="$PYTHON_CFLAGS -DDYNAMIC_PYTHON_DLL=\\\"${python_INSTSONAME}\\\""
1155  PYTHON_LIBS=
1156  PYTHON3_SRC="if_python3.c"
1157  PYTHON3_OBJ="objects/if_python3.o"
1158  PYTHON3_CFLAGS="$PYTHON3_CFLAGS -DDYNAMIC_PYTHON3_DLL=\\\"${python3_INSTSONAME}\\\""
1159  PYTHON3_LIBS=
1160elif test "$python_ok" = yes && test "$enable_pythoninterp" = "dynamic"; then
1161  AC_DEFINE(DYNAMIC_PYTHON)
1162  PYTHON_SRC="if_python.c"
1163  PYTHON_OBJ="objects/if_python.o"
1164  PYTHON_CFLAGS="$PYTHON_CFLAGS -DDYNAMIC_PYTHON_DLL=\\\"${python_INSTSONAME}\\\""
1165  PYTHON_LIBS=
1166elif test "$python3_ok" = yes && test "$enable_python3interp" = "dynamic"; then
1167  AC_DEFINE(DYNAMIC_PYTHON3)
1168  PYTHON3_SRC="if_python3.c"
1169  PYTHON3_OBJ="objects/if_python3.o"
1170  PYTHON3_CFLAGS="$PYTHON3_CFLAGS -DDYNAMIC_PYTHON3_DLL=\\\"${python3_INSTSONAME}\\\""
1171  PYTHON3_LIBS=
1172fi
1173
1174AC_MSG_CHECKING(--enable-tclinterp argument)
1175AC_ARG_ENABLE(tclinterp,
1176	[  --enable-tclinterp      Include Tcl interpreter.], ,
1177	[enable_tclinterp="no"])
1178AC_MSG_RESULT($enable_tclinterp)
1179
1180if test "$enable_tclinterp" = "yes"; then
1181
1182  dnl on FreeBSD tclsh is a silly script, look for tclsh8.[5420]
1183  AC_MSG_CHECKING(--with-tclsh argument)
1184  AC_ARG_WITH(tclsh, [  --with-tclsh=PATH       which tclsh to use (default: tclsh8.0)],
1185	tclsh_name="$withval"; AC_MSG_RESULT($tclsh_name),
1186	tclsh_name="tclsh8.5"; AC_MSG_RESULT(no))
1187  AC_PATH_PROG(vi_cv_path_tcl, $tclsh_name)
1188  AC_SUBST(vi_cv_path_tcl)
1189
1190  dnl when no specific version specified, also try 8.4, 8.2 and 8.0
1191  if test "X$vi_cv_path_tcl" = "X" -a $tclsh_name = "tclsh8.5"; then
1192    tclsh_name="tclsh8.4"
1193    AC_PATH_PROG(vi_cv_path_tcl, $tclsh_name)
1194  fi
1195  if test "X$vi_cv_path_tcl" = "X" -a $tclsh_name = "tclsh8.4"; then
1196    tclsh_name="tclsh8.2"
1197    AC_PATH_PROG(vi_cv_path_tcl, $tclsh_name)
1198  fi
1199  if test "X$vi_cv_path_tcl" = "X" -a $tclsh_name = "tclsh8.2"; then
1200    tclsh_name="tclsh8.0"
1201    AC_PATH_PROG(vi_cv_path_tcl, $tclsh_name)
1202  fi
1203  dnl still didn't find it, try without version number
1204  if test "X$vi_cv_path_tcl" = "X"; then
1205    tclsh_name="tclsh"
1206    AC_PATH_PROG(vi_cv_path_tcl, $tclsh_name)
1207  fi
1208  if test "X$vi_cv_path_tcl" != "X"; then
1209    AC_MSG_CHECKING(Tcl version)
1210    if echo 'exit [[expr [info tclversion] < 8.0]]' | $vi_cv_path_tcl - ; then
1211      tclver=`echo 'puts [[info tclversion]]' | $vi_cv_path_tcl -`
1212      AC_MSG_RESULT($tclver - OK);
1213      tclloc=`echo 'set l [[info library]];set i [[string last lib $l]];incr i -2;puts [[string range $l 0 $i]]' | $vi_cv_path_tcl -`
1214
1215      AC_MSG_CHECKING(for location of Tcl include)
1216      if test "x$MACOSX" != "xyes"; then
1217	tclinc="$tclloc/include $tclloc/include/tcl $tclloc/include/tcl$tclver /usr/local/include /usr/local/include/tcl$tclver /usr/include /usr/include/tcl$tclver"
1218      else
1219	dnl For Mac OS X 10.3, use the OS-provided framework location
1220	tclinc="/System/Library/Frameworks/Tcl.framework/Headers"
1221      fi
1222      TCL_INC=
1223      for try in $tclinc; do
1224	if test -f "$try/tcl.h"; then
1225	  AC_MSG_RESULT($try/tcl.h)
1226	  TCL_INC=$try
1227	  break
1228	fi
1229      done
1230      if test -z "$TCL_INC"; then
1231	AC_MSG_RESULT(<not found>)
1232	SKIP_TCL=YES
1233      fi
1234      if test -z "$SKIP_TCL"; then
1235	AC_MSG_CHECKING(for location of tclConfig.sh script)
1236	if test "x$MACOSX" != "xyes"; then
1237	  tclcnf=`echo $tclinc | sed s/include/lib/g`
1238	  tclcnf="$tclcnf `echo $tclinc | sed s/include/lib64/g`"
1239	else
1240	  dnl For Mac OS X 10.3, use the OS-provided framework location
1241	  tclcnf="/System/Library/Frameworks/Tcl.framework"
1242	fi
1243	for try in $tclcnf; do
1244	  if test -f $try/tclConfig.sh; then
1245	    AC_MSG_RESULT($try/tclConfig.sh)
1246	    . $try/tclConfig.sh
1247	    dnl use eval, because tcl 8.2 includes ${TCL_DBGX}
1248	    TCL_LIBS=`eval echo "$TCL_LIB_SPEC $TCL_LIBS"`
1249	    dnl Use $TCL_DEFS for -D_THREAD_SAFE et al.  But only use the
1250	    dnl "-D_ABC" items.  Watch out for -DFOO=long\ long.
1251	    TCL_DEFS=`echo $TCL_DEFS | sed -e 's/\\\\ /\\\\X/g' | tr ' ' '\012' | sed -e '/^[[^-]]/d' -e '/^-[[^D]]/d' -e '/-D[[^_]]/d' -e 's/-D_/ -D_/' | tr '\012' ' ' | sed -e 's/\\\\X/\\\\ /g'`
1252	    break
1253	  fi
1254	done
1255	if test -z "$TCL_LIBS"; then
1256	  AC_MSG_RESULT(<not found>)
1257	  AC_MSG_CHECKING(for Tcl library by myself)
1258	  tcllib=`echo $tclinc | sed s/include/lib/g`
1259	  tcllib="$tcllib `echo $tclinc | sed s/include/lib64/g`"
1260	  for ext in .so .a ; do
1261	    for ver in "" $tclver ; do
1262	      for try in $tcllib ; do
1263		trylib=tcl$ver$ext
1264		if test -f $try/lib$trylib ; then
1265		  AC_MSG_RESULT($try/lib$trylib)
1266		  TCL_LIBS="-L$try -ltcl$ver -ldl -lm"
1267		  if test "`(uname) 2>/dev/null`" = SunOS &&
1268					 uname -r | grep '^5' >/dev/null; then
1269		    TCL_LIBS="$TCL_LIBS -R $try"
1270		  fi
1271		  break 3
1272		fi
1273	      done
1274	    done
1275	  done
1276	  if test -z "$TCL_LIBS"; then
1277	    AC_MSG_RESULT(<not found>)
1278	    SKIP_TCL=YES
1279	  fi
1280	fi
1281	if test -z "$SKIP_TCL"; then
1282	  AC_DEFINE(FEAT_TCL)
1283	  TCL_SRC=if_tcl.c
1284	  TCL_OBJ=objects/if_tcl.o
1285	  TCL_PRO=if_tcl.pro
1286	  TCL_CFLAGS="-I$TCL_INC $TCL_DEFS"
1287	fi
1288      fi
1289    else
1290      AC_MSG_RESULT(too old; need Tcl version 8.0 or later)
1291    fi
1292  fi
1293fi
1294AC_SUBST(TCL_SRC)
1295AC_SUBST(TCL_OBJ)
1296AC_SUBST(TCL_PRO)
1297AC_SUBST(TCL_CFLAGS)
1298AC_SUBST(TCL_LIBS)
1299
1300AC_MSG_CHECKING(--enable-rubyinterp argument)
1301AC_ARG_ENABLE(rubyinterp,
1302	[  --enable-rubyinterp     Include Ruby interpreter.], ,
1303	[enable_rubyinterp="no"])
1304AC_MSG_RESULT($enable_rubyinterp)
1305if test "$enable_rubyinterp" = "yes"; then
1306  AC_MSG_CHECKING(--with-ruby-command argument)
1307  AC_ARG_WITH(ruby-command, [  --with-ruby-command=RUBY  name of the Ruby command (default: ruby)],
1308	RUBY_CMD="$withval"; AC_MSG_RESULT($RUBY_CMD),
1309	RUBY_CMD="ruby"; AC_MSG_RESULT(defaulting to $RUBY_CMD))
1310  AC_SUBST(vi_cv_path_ruby)
1311  AC_PATH_PROG(vi_cv_path_ruby, $RUBY_CMD)
1312  if test "X$vi_cv_path_ruby" != "X"; then
1313    AC_MSG_CHECKING(Ruby version)
1314    if $vi_cv_path_ruby -e '(VERSION rescue RUBY_VERSION) >= "1.6.0" or exit 1' >/dev/null 2>/dev/null; then
1315      AC_MSG_RESULT(OK)
1316      AC_MSG_CHECKING(Ruby header files)
1317      rubyhdrdir=`$vi_cv_path_ruby -r mkmf -e 'print Config::CONFIG[["rubyhdrdir"]] || Config::CONFIG[["archdir"]] || $hdrdir' 2>/dev/null`
1318      if test "X$rubyhdrdir" != "X"; then
1319	AC_MSG_RESULT($rubyhdrdir)
1320	RUBY_CFLAGS="-I$rubyhdrdir"
1321        rubyarch=`$vi_cv_path_ruby -r rbconfig -e 'print Config::CONFIG[["arch"]]'`
1322        if test -d "$rubyhdrdir/$rubyarch"; then
1323          RUBY_CFLAGS="$RUBY_CFLAGS -I$rubyhdrdir/$rubyarch"
1324        fi
1325        rubyversion=`$vi_cv_path_ruby -r rbconfig -e 'print Config::CONFIG[["ruby_version"]].gsub(/\./, "")[[0,2]]'`
1326        RUBY_CFLAGS="$RUBY_CFLAGS -DRUBY_VERSION=$rubyversion"
1327	rubylibs=`$vi_cv_path_ruby -r rbconfig -e 'print Config::CONFIG[["LIBS"]]'`
1328	if test "X$rubylibs" != "X"; then
1329	  RUBY_LIBS="$rubylibs"
1330	fi
1331	librubyarg=`$vi_cv_path_ruby -r rbconfig -e 'print Config.expand(Config::CONFIG[["LIBRUBYARG"]])'`
1332	if test -f "$rubyhdrdir/$librubyarg"; then
1333	  librubyarg="$rubyhdrdir/$librubyarg"
1334	else
1335	  rubylibdir=`$vi_cv_path_ruby -r rbconfig -e 'print Config.expand(Config::CONFIG[["libdir"]])'`
1336	  if test -f "$rubylibdir/$librubyarg"; then
1337	    librubyarg="$rubylibdir/$librubyarg"
1338	  elif test "$librubyarg" = "libruby.a"; then
1339	    dnl required on Mac OS 10.3 where libruby.a doesn't exist
1340	    librubyarg="-lruby"
1341	  else
1342	    librubyarg=`$vi_cv_path_ruby -r rbconfig -e "print '$librubyarg'.gsub(/-L\./, %'-L#{Config.expand(Config::CONFIG[\"libdir\"])}')"`
1343	  fi
1344	fi
1345
1346	if test "X$librubyarg" != "X"; then
1347	  RUBY_LIBS="$librubyarg $RUBY_LIBS"
1348	fi
1349	rubyldflags=`$vi_cv_path_ruby -r rbconfig -e 'print Config::CONFIG[["LDFLAGS"]]'`
1350	if test "X$rubyldflags" != "X"; then
1351	  dnl Ruby on Mac OS X 10.5 adds "-arch" flags but these should only
1352	  dnl be included if requested by passing --with-mac-arch to
1353	  dnl configure, so strip these flags first (if present)
1354	  rubyldflags=`echo "$rubyldflags" | sed -e 's/-arch\ ppc//' -e 's/-arch\ i386//' -e 's/-arch\ x86_64//'`
1355	  if test "X$rubyldflags" != "X"; then
1356	    LDFLAGS="$rubyldflags $LDFLAGS"
1357	  fi
1358	fi
1359	RUBY_SRC="if_ruby.c"
1360	RUBY_OBJ="objects/if_ruby.o"
1361	RUBY_PRO="if_ruby.pro"
1362	AC_DEFINE(FEAT_RUBY)
1363      else
1364	AC_MSG_RESULT(not found; disabling Ruby)
1365      fi
1366    else
1367      AC_MSG_RESULT(too old; need Ruby version 1.6.0 or later)
1368    fi
1369  fi
1370fi
1371AC_SUBST(RUBY_SRC)
1372AC_SUBST(RUBY_OBJ)
1373AC_SUBST(RUBY_PRO)
1374AC_SUBST(RUBY_CFLAGS)
1375AC_SUBST(RUBY_LIBS)
1376
1377AC_MSG_CHECKING(--enable-cscope argument)
1378AC_ARG_ENABLE(cscope,
1379	[  --enable-cscope         Include cscope interface.], ,
1380	[enable_cscope="no"])
1381AC_MSG_RESULT($enable_cscope)
1382if test "$enable_cscope" = "yes"; then
1383  AC_DEFINE(FEAT_CSCOPE)
1384fi
1385
1386AC_MSG_CHECKING(--enable-workshop argument)
1387AC_ARG_ENABLE(workshop,
1388	[  --enable-workshop       Include Sun Visual Workshop support.], ,
1389	[enable_workshop="no"])
1390AC_MSG_RESULT($enable_workshop)
1391if test "$enable_workshop" = "yes"; then
1392  AC_DEFINE(FEAT_SUN_WORKSHOP)
1393  WORKSHOP_SRC="workshop.c integration.c"
1394  AC_SUBST(WORKSHOP_SRC)
1395  WORKSHOP_OBJ="objects/workshop.o objects/integration.o"
1396  AC_SUBST(WORKSHOP_OBJ)
1397  if test "${enable_gui-xxx}" = xxx; then
1398    enable_gui=motif
1399  fi
1400fi
1401
1402AC_MSG_CHECKING(--disable-netbeans argument)
1403AC_ARG_ENABLE(netbeans,
1404	[  --disable-netbeans      Disable NetBeans integration support.],
1405	, [enable_netbeans="yes"])
1406if test "$enable_netbeans" = "yes"; then
1407  AC_MSG_RESULT(no)
1408  dnl On Solaris we need the socket and nsl library.
1409  AC_CHECK_LIB(socket, socket)
1410  AC_CHECK_LIB(nsl, gethostbyname)
1411  AC_MSG_CHECKING(whether compiling netbeans integration is possible)
1412  AC_TRY_LINK([
1413#include <stdio.h>
1414#include <stdlib.h>
1415#include <stdarg.h>
1416#include <fcntl.h>
1417#include <netdb.h>
1418#include <netinet/in.h>
1419#include <errno.h>
1420#include <sys/types.h>
1421#include <sys/socket.h>
1422	/* Check bitfields */
1423	struct nbbuf {
1424	unsigned int  initDone:1;
1425	ushort signmaplen;
1426	};
1427	    ], [
1428		/* Check creating a socket. */
1429		struct sockaddr_in server;
1430		(void)socket(AF_INET, SOCK_STREAM, 0);
1431		(void)htons(100);
1432		(void)gethostbyname("microsoft.com");
1433		if (errno == ECONNREFUSED)
1434		  (void)connect(1, (struct sockaddr *)&server, sizeof(server));
1435	    ],
1436	AC_MSG_RESULT(yes),
1437	AC_MSG_RESULT(no); enable_netbeans="no")
1438else
1439  AC_MSG_RESULT(yes)
1440fi
1441if test "$enable_netbeans" = "yes"; then
1442  AC_DEFINE(FEAT_NETBEANS_INTG)
1443  NETBEANS_SRC="netbeans.c"
1444  AC_SUBST(NETBEANS_SRC)
1445  NETBEANS_OBJ="objects/netbeans.o"
1446  AC_SUBST(NETBEANS_OBJ)
1447fi
1448
1449AC_MSG_CHECKING(--enable-sniff argument)
1450AC_ARG_ENABLE(sniff,
1451	[  --enable-sniff          Include Sniff interface.], ,
1452	[enable_sniff="no"])
1453AC_MSG_RESULT($enable_sniff)
1454if test "$enable_sniff" = "yes"; then
1455  AC_DEFINE(FEAT_SNIFF)
1456  SNIFF_SRC="if_sniff.c"
1457  AC_SUBST(SNIFF_SRC)
1458  SNIFF_OBJ="objects/if_sniff.o"
1459  AC_SUBST(SNIFF_OBJ)
1460fi
1461
1462AC_MSG_CHECKING(--enable-multibyte argument)
1463AC_ARG_ENABLE(multibyte,
1464	[  --enable-multibyte      Include multibyte editing support.], ,
1465	[enable_multibyte="no"])
1466AC_MSG_RESULT($enable_multibyte)
1467if test "$enable_multibyte" = "yes"; then
1468  AC_DEFINE(FEAT_MBYTE)
1469fi
1470
1471AC_MSG_CHECKING(--enable-hangulinput argument)
1472AC_ARG_ENABLE(hangulinput,
1473	[  --enable-hangulinput    Include Hangul input support.], ,
1474	[enable_hangulinput="no"])
1475AC_MSG_RESULT($enable_hangulinput)
1476
1477AC_MSG_CHECKING(--enable-xim argument)
1478AC_ARG_ENABLE(xim,
1479	[  --enable-xim            Include XIM input support.],
1480	AC_MSG_RESULT($enable_xim),
1481	[enable_xim="auto"; AC_MSG_RESULT(defaulting to auto)])
1482
1483AC_MSG_CHECKING(--enable-fontset argument)
1484AC_ARG_ENABLE(fontset,
1485	[  --enable-fontset        Include X fontset output support.], ,
1486	[enable_fontset="no"])
1487AC_MSG_RESULT($enable_fontset)
1488dnl defining FEAT_XFONTSET is delayed, so that it can be disabled for no GUI
1489
1490test -z "$with_x" && with_x=yes
1491test "${enable_gui-yes}" != no -a "x$MACOSX" != "xyes" -a "x$QNX" != "xyes" && with_x=yes
1492if test "$with_x" = no; then
1493  AC_MSG_RESULT(defaulting to: don't HAVE_X11)
1494else
1495  dnl Do this check early, so that its failure can override user requests.
1496
1497  AC_PATH_PROG(xmkmfpath, xmkmf)
1498
1499  AC_PATH_XTRA
1500
1501  dnl On z/OS Unix the X libraries are DLLs. To use them the code must
1502  dnl be compiled with a special option.
1503  dnl Also add SM, ICE and Xmu to X_EXTRA_LIBS.
1504  if test "$zOSUnix" = "yes"; then
1505    CFLAGS="$CFLAGS -W c,dll"
1506    LDFLAGS="$LDFLAGS -W l,dll"
1507    X_EXTRA_LIBS="$X_EXTRA_LIBS -lSM -lICE -lXmu"
1508  fi
1509
1510  dnl On my HPUX system the X include dir is found, but the lib dir not.
1511  dnl This is a desparate try to fix this.
1512
1513  if test -d "$x_includes" && test ! -d "$x_libraries"; then
1514    x_libraries=`echo "$x_includes" | sed s/include/lib/`
1515    AC_MSG_RESULT(Corrected X libraries to $x_libraries)
1516    X_LIBS="$X_LIBS -L$x_libraries"
1517    if test "`(uname) 2>/dev/null`" = SunOS &&
1518					 uname -r | grep '^5' >/dev/null; then
1519      X_LIBS="$X_LIBS -R $x_libraries"
1520    fi
1521  fi
1522
1523  if test -d "$x_libraries" && test ! -d "$x_includes"; then
1524    x_includes=`echo "$x_libraries" | sed s/lib/include/`
1525    AC_MSG_RESULT(Corrected X includes to $x_includes)
1526    X_CFLAGS="$X_CFLAGS -I$x_includes"
1527  fi
1528
1529  dnl Remove "-I/usr/include " from X_CFLAGS, should not be needed.
1530  X_CFLAGS="`echo $X_CFLAGS\  | sed 's%-I/usr/include %%'`"
1531  dnl Remove "-L/usr/lib " from X_LIBS, should not be needed.
1532  X_LIBS="`echo $X_LIBS\  | sed 's%-L/usr/lib %%'`"
1533  dnl Same for "-R/usr/lib ".
1534  X_LIBS="`echo $X_LIBS\  | sed -e 's%-R/usr/lib %%' -e 's%-R /usr/lib %%'`"
1535
1536
1537  dnl Check if the X11 header files are correctly installed. On some systems
1538  dnl Xlib.h includes files that don't exist.  On some systems X11/Intrinsic.h
1539  dnl is missing.
1540  AC_MSG_CHECKING(if X11 header files can be found)
1541  cflags_save=$CFLAGS
1542  CFLAGS="$CFLAGS $X_CFLAGS"
1543  AC_TRY_COMPILE([#include <X11/Xlib.h>
1544#include <X11/Intrinsic.h>], ,
1545	AC_MSG_RESULT(yes),
1546	AC_MSG_RESULT(no); no_x=yes)
1547  CFLAGS=$cflags_save
1548
1549  if test "${no_x-no}" = yes; then
1550    with_x=no
1551  else
1552    AC_DEFINE(HAVE_X11)
1553    X_LIB="-lXt -lX11";
1554    AC_SUBST(X_LIB)
1555
1556    ac_save_LDFLAGS="$LDFLAGS"
1557    LDFLAGS="-L$x_libraries $LDFLAGS"
1558
1559    dnl Check for -lXdmcp (needed on SunOS 4.1.4)
1560    dnl For HP-UX 10.20 it must be before -lSM -lICE
1561    AC_CHECK_LIB(Xdmcp, _XdmcpAuthDoIt, [X_EXTRA_LIBS="$X_EXTRA_LIBS -lXdmcp"],,
1562		[-lXt $X_PRE_LIBS -lX11 $X_EXTRA_LIBS -lXdmcp])
1563
1564    dnl Some systems need -lnsl -lsocket when testing for ICE.
1565    dnl The check above doesn't do this, try here (again).  Also needed to get
1566    dnl them after Xdmcp.  link.sh will remove them when not needed.
1567    dnl Check for other function than above to avoid the cached value
1568    AC_CHECK_LIB(ICE, IceOpenConnection,
1569		  [X_EXTRA_LIBS="$X_EXTRA_LIBS -lSM -lICE"],, [$X_EXTRA_LIBS])
1570
1571    dnl Check for -lXpm (needed for some versions of Motif)
1572    LDFLAGS="$X_LIBS $ac_save_LDFLAGS"
1573    AC_CHECK_LIB(Xpm, XpmCreatePixmapFromData, [X_PRE_LIBS="$X_PRE_LIBS -lXpm"],,
1574		[-lXt $X_PRE_LIBS -lXpm -lX11 $X_EXTRA_LIBS])
1575
1576    dnl Check that the X11 header files don't use implicit declarations
1577    AC_MSG_CHECKING(if X11 header files implicitly declare return values)
1578    cflags_save=$CFLAGS
1579    CFLAGS="$CFLAGS $X_CFLAGS -Werror"
1580    AC_TRY_COMPILE([#include <X11/Xlib.h>], ,
1581	AC_MSG_RESULT(no),
1582	CFLAGS="$CFLAGS -Wno-implicit-int"
1583	AC_TRY_COMPILE([#include <X11/Xlib.h>], ,
1584	    AC_MSG_RESULT(yes); cflags_save="$cflags_save -Wno-implicit-int",
1585	    AC_MSG_RESULT(test failed)
1586	)
1587    )
1588    CFLAGS=$cflags_save
1589
1590    LDFLAGS="$ac_save_LDFLAGS"
1591
1592    AC_MSG_CHECKING(size of wchar_t is 2 bytes)
1593    AC_CACHE_VAL(ac_cv_small_wchar_t,
1594	[AC_TRY_RUN([
1595#include <X11/Xlib.h>
1596#if STDC_HEADERS
1597# include <stdlib.h>
1598# include <stddef.h>
1599#endif
1600		main()
1601		{
1602		  if (sizeof(wchar_t) <= 2)
1603		    exit(1);
1604		  exit(0);
1605		}],
1606		ac_cv_small_wchar_t="no",
1607		ac_cv_small_wchar_t="yes",
1608		AC_MSG_ERROR(failed to compile test program))])
1609    AC_MSG_RESULT($ac_cv_small_wchar_t)
1610    if test "x$ac_cv_small_wchar_t" = "xyes" ; then
1611      AC_DEFINE(SMALL_WCHAR_T)
1612    fi
1613
1614  fi
1615fi
1616
1617test "x$with_x" = xno -a "x$MACOSX" != "xyes" -a "x$QNX" != "xyes" && enable_gui=no
1618
1619AC_MSG_CHECKING(--enable-gui argument)
1620AC_ARG_ENABLE(gui,
1621 [  --enable-gui[=OPTS]     X11 GUI [default=auto] [OPTS=auto/no/gtk2/gnome2/motif/athena/neXtaw/photon/carbon]], , enable_gui="auto")
1622
1623dnl Canonicalize the --enable-gui= argument so that it can be easily compared.
1624dnl Do not use character classes for portability with old tools.
1625enable_gui_canon=`echo "_$enable_gui" | \
1626	sed 's/[[ _+-]]//g;y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
1627
1628dnl Skip everything by default.
1629SKIP_GTK2=YES
1630SKIP_GNOME=YES
1631SKIP_MOTIF=YES
1632SKIP_ATHENA=YES
1633SKIP_NEXTAW=YES
1634SKIP_PHOTON=YES
1635SKIP_CARBON=YES
1636GUITYPE=NONE
1637
1638if test "x$QNX" = "xyes" -a "x$with_x" = "xno" ; then
1639  SKIP_PHOTON=
1640  case "$enable_gui_canon" in
1641    no)		AC_MSG_RESULT(no GUI support)
1642		SKIP_PHOTON=YES ;;
1643    yes|"")	AC_MSG_RESULT(yes - automatic GUI support) ;;
1644    auto)	AC_MSG_RESULT(auto - automatic GUI support) ;;
1645    photon)	AC_MSG_RESULT(Photon GUI support) ;;
1646    *)		AC_MSG_RESULT([Sorry, $enable_gui GUI is not supported])
1647		SKIP_PHOTON=YES ;;
1648  esac
1649
1650elif test "x$MACOSX" = "xyes" -a "x$with_x" = "xno" ; then
1651  SKIP_CARBON=
1652  case "$enable_gui_canon" in
1653    no)		AC_MSG_RESULT(no GUI support)
1654		SKIP_CARBON=YES ;;
1655    yes|"")	AC_MSG_RESULT(yes - automatic GUI support) ;;
1656    auto)	AC_MSG_RESULT(auto - Carbon GUI is outdated - disable GUI support)
1657		SKIP_CARBON=YES ;;
1658    carbon)	AC_MSG_RESULT(Carbon GUI support) ;;
1659    *)		AC_MSG_RESULT([Sorry, $enable_gui GUI is not supported])
1660		SKIP_CARBON=YES ;;
1661  esac
1662
1663else
1664
1665  case "$enable_gui_canon" in
1666    no|none)	AC_MSG_RESULT(no GUI support) ;;
1667    yes|""|auto)	AC_MSG_RESULT(yes/auto - automatic GUI support)
1668		SKIP_GTK2=
1669		SKIP_GNOME=
1670		SKIP_MOTIF=
1671		SKIP_ATHENA=
1672		SKIP_NEXTAW=
1673		SKIP_CARBON=;;
1674    gtk2)	AC_MSG_RESULT(GTK+ 2.x GUI support)
1675		SKIP_GTK2=;;
1676    gnome2)	AC_MSG_RESULT(GNOME 2.x GUI support)
1677		SKIP_GNOME=
1678		SKIP_GTK2=;;
1679    motif)	AC_MSG_RESULT(Motif GUI support)
1680		SKIP_MOTIF=;;
1681    athena)	AC_MSG_RESULT(Athena GUI support)
1682		SKIP_ATHENA=;;
1683    nextaw)	AC_MSG_RESULT(neXtaw GUI support)
1684		SKIP_NEXTAW=;;
1685    *)		AC_MSG_RESULT([Sorry, $enable_gui GUI is not supported]) ;;
1686  esac
1687
1688fi
1689
1690if test "x$SKIP_GTK2" != "xYES" -a "$enable_gui_canon" != "gtk2" \
1691				-a "$enable_gui_canon" != "gnome2"; then
1692  AC_MSG_CHECKING(whether or not to look for GTK+ 2)
1693  AC_ARG_ENABLE(gtk2-check,
1694	[  --enable-gtk2-check     If auto-select GUI, check for GTK+ 2 [default=yes]],
1695	, enable_gtk2_check="yes")
1696  AC_MSG_RESULT($enable_gtk2_check)
1697  if test "x$enable_gtk2_check" = "xno"; then
1698    SKIP_GTK2=YES
1699    SKIP_GNOME=YES
1700  fi
1701fi
1702
1703if test "x$SKIP_GNOME" != "xYES" -a "$enable_gui_canon" != "gnome2"; then
1704  AC_MSG_CHECKING(whether or not to look for GNOME)
1705  AC_ARG_ENABLE(gnome-check,
1706	[  --enable-gnome-check    If GTK GUI, check for GNOME [default=no]],
1707	, enable_gnome_check="no")
1708  AC_MSG_RESULT($enable_gnome_check)
1709  if test "x$enable_gnome_check" = "xno"; then
1710    SKIP_GNOME=YES
1711  fi
1712fi
1713
1714if test "x$SKIP_MOTIF" != "xYES" -a "$enable_gui_canon" != "motif"; then
1715  AC_MSG_CHECKING(whether or not to look for Motif)
1716  AC_ARG_ENABLE(motif-check,
1717	[  --enable-motif-check    If auto-select GUI, check for Motif [default=yes]],
1718	, enable_motif_check="yes")
1719  AC_MSG_RESULT($enable_motif_check)
1720  if test "x$enable_motif_check" = "xno"; then
1721    SKIP_MOTIF=YES
1722  fi
1723fi
1724
1725if test "x$SKIP_ATHENA" != "xYES" -a "$enable_gui_canon" != "athena"; then
1726  AC_MSG_CHECKING(whether or not to look for Athena)
1727  AC_ARG_ENABLE(athena-check,
1728	[  --enable-athena-check   If auto-select GUI, check for Athena [default=yes]],
1729	, enable_athena_check="yes")
1730  AC_MSG_RESULT($enable_athena_check)
1731  if test "x$enable_athena_check" = "xno"; then
1732    SKIP_ATHENA=YES
1733  fi
1734fi
1735
1736if test "x$SKIP_NEXTAW" != "xYES" -a "$enable_gui_canon" != "nextaw"; then
1737  AC_MSG_CHECKING(whether or not to look for neXtaw)
1738  AC_ARG_ENABLE(nextaw-check,
1739	[  --enable-nextaw-check   If auto-select GUI, check for neXtaw [default=yes]],
1740	, enable_nextaw_check="yes")
1741  AC_MSG_RESULT($enable_nextaw_check);
1742  if test "x$enable_nextaw_check" = "xno"; then
1743    SKIP_NEXTAW=YES
1744  fi
1745fi
1746
1747if test "x$SKIP_CARBON" != "xYES" -a "$enable_gui_canon" != "carbon"; then
1748  AC_MSG_CHECKING(whether or not to look for Carbon)
1749  AC_ARG_ENABLE(carbon-check,
1750	[  --enable-carbon-check   If auto-select GUI, check for Carbon [default=yes]],
1751	, enable_carbon_check="yes")
1752  AC_MSG_RESULT($enable_carbon_check);
1753  if test "x$enable_carbon_check" = "xno"; then
1754    SKIP_CARBON=YES
1755  fi
1756fi
1757
1758
1759if test "x$MACOSX" = "xyes" -a -z "$SKIP_CARBON" -a "x$CARBON" = "xyes"; then
1760  AC_MSG_CHECKING(for Carbon GUI)
1761  dnl already did the check, just give the message
1762  AC_MSG_RESULT(yes);
1763  GUITYPE=CARBONGUI
1764  if test "$VIMNAME" = "vim"; then
1765    VIMNAME=Vim
1766  fi
1767
1768  if test "x$MACARCH" = "xboth"; then
1769    CPPFLAGS="$CPPFLAGS -I$DEVELOPER_DIR/SDKs/MacOSX10.4u.sdk/Developer/Headers/FlatCarbon"
1770  else
1771    CPPFLAGS="$CPPFLAGS -I$DEVELOPER_DIR/Headers/FlatCarbon"
1772  fi
1773
1774  dnl Default install directory is not /usr/local
1775  if test x$prefix = xNONE; then
1776    prefix=/Applications
1777  fi
1778
1779  dnl Sorry for the hard coded default
1780  datadir='${prefix}/Vim.app/Contents/Resources'
1781
1782  dnl skip everything else
1783  SKIP_GTK2=YES;
1784  SKIP_GNOME=YES;
1785  SKIP_MOTIF=YES;
1786  SKIP_ATHENA=YES;
1787  SKIP_NEXTAW=YES;
1788  SKIP_PHOTON=YES;
1789  SKIP_CARBON=YES
1790fi
1791
1792dnl define an autoconf function to check for a specified version of GTK, and
1793dnl try to compile/link a GTK program.
1794dnl
1795dnl AM_PATH_GTK([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
1796dnl Test for GTK, and define GTK_CFLAGS, GTK_LIBDIR and GTK_LIBS
1797dnl
1798AC_DEFUN(AM_PATH_GTK,
1799[
1800  if test "X$GTK_CONFIG" != "Xno" -o "X$PKG_CONFIG" != "Xno"; then
1801  {
1802    min_gtk_version=ifelse([$1], ,2.2.0,$1)
1803    AC_MSG_CHECKING(for GTK - version >= $min_gtk_version)
1804    no_gtk=""
1805    if (test "X$SKIP_GTK2" != "XYES" -a "X$PKG_CONFIG" != "Xno") \
1806	  && $PKG_CONFIG --exists gtk+-2.0; then
1807    {
1808      dnl We should be using PKG_CHECK_MODULES() instead of this hack.
1809      dnl But I guess the dependency on pkgconfig.m4 is not wanted or
1810      dnl something like that.
1811      GTK_CFLAGS=`$PKG_CONFIG --cflags gtk+-2.0`
1812      GTK_LIBDIR=`$PKG_CONFIG --libs-only-L gtk+-2.0`
1813      GTK_LIBS=`$PKG_CONFIG --libs gtk+-2.0`
1814      gtk_major_version=`$PKG_CONFIG --modversion gtk+-2.0 | \
1815	     sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
1816      gtk_minor_version=`$PKG_CONFIG --modversion gtk+-2.0 | \
1817	     sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
1818      gtk_micro_version=`$PKG_CONFIG --modversion gtk+-2.0 | \
1819	     sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
1820    }
1821    else
1822      no_gtk=yes
1823    fi
1824
1825    if test "x$enable_gtktest" = "xyes" -a "x$no_gtk" = "x"; then
1826    {
1827      ac_save_CFLAGS="$CFLAGS"
1828      ac_save_LIBS="$LIBS"
1829      CFLAGS="$CFLAGS $GTK_CFLAGS"
1830      LIBS="$LIBS $GTK_LIBS"
1831
1832      dnl
1833      dnl Now check if the installed GTK is sufficiently new.
1834      dnl
1835      rm -f conf.gtktest
1836      AC_TRY_RUN([
1837#include <gtk/gtk.h>
1838#include <stdio.h>
1839#if STDC_HEADERS
1840# include <stdlib.h>
1841# include <stddef.h>
1842#endif
1843
1844int
1845main ()
1846{
1847int major, minor, micro;
1848char *tmp_version;
1849
1850system ("touch conf.gtktest");
1851
1852/* HP/UX 9 (%@#!) writes to sscanf strings */
1853tmp_version = g_strdup("$min_gtk_version");
1854if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
1855   printf("%s, bad version string\n", "$min_gtk_version");
1856   exit(1);
1857 }
1858
1859if ((gtk_major_version > major) ||
1860    ((gtk_major_version == major) && (gtk_minor_version > minor)) ||
1861    ((gtk_major_version == major) && (gtk_minor_version == minor) &&
1862				     (gtk_micro_version >= micro)))
1863{
1864    return 0;
1865}
1866return 1;
1867}
1868],, no_gtk=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
1869      CFLAGS="$ac_save_CFLAGS"
1870      LIBS="$ac_save_LIBS"
1871    }
1872    fi
1873    if test "x$no_gtk" = x ; then
1874      if test "x$enable_gtktest" = "xyes"; then
1875	AC_MSG_RESULT(yes; found version $gtk_major_version.$gtk_minor_version.$gtk_micro_version)
1876      else
1877	AC_MSG_RESULT(found version $gtk_major_version.$gtk_minor_version.$gtk_micro_version)
1878      fi
1879      ifelse([$2], , :, [$2])
1880    else
1881    {
1882      AC_MSG_RESULT(no)
1883      GTK_CFLAGS=""
1884      GTK_LIBS=""
1885      ifelse([$3], , :, [$3])
1886    }
1887    fi
1888  }
1889  else
1890    GTK_CFLAGS=""
1891    GTK_LIBS=""
1892    ifelse([$3], , :, [$3])
1893  fi
1894  AC_SUBST(GTK_CFLAGS)
1895  AC_SUBST(GTK_LIBS)
1896  rm -f conf.gtktest
1897])
1898
1899dnl ---------------------------------------------------------------------------
1900dnl gnome
1901dnl ---------------------------------------------------------------------------
1902AC_DEFUN([GNOME_INIT_HOOK],
1903[
1904  AC_SUBST(GNOME_LIBS)
1905  AC_SUBST(GNOME_LIBDIR)
1906  AC_SUBST(GNOME_INCLUDEDIR)
1907
1908  AC_ARG_WITH(gnome-includes,
1909    [  --with-gnome-includes=DIR Specify location of GNOME headers],
1910    [CFLAGS="$CFLAGS -I$withval"]
1911  )
1912
1913  AC_ARG_WITH(gnome-libs,
1914    [  --with-gnome-libs=DIR   Specify location of GNOME libs],
1915    [LDFLAGS="$LDFLAGS -L$withval" gnome_prefix=$withval]
1916  )
1917
1918  AC_ARG_WITH(gnome,
1919    [  --with-gnome            Specify prefix for GNOME files],
1920    if test x$withval = xyes; then
1921      want_gnome=yes
1922      ifelse([$1], [], :, [$1])
1923    else
1924      if test "x$withval" = xno; then
1925	want_gnome=no
1926      else
1927	want_gnome=yes
1928	LDFLAGS="$LDFLAGS -L$withval/lib"
1929	CFLAGS="$CFLAGS -I$withval/include"
1930	gnome_prefix=$withval/lib
1931      fi
1932    fi,
1933    want_gnome=yes)
1934
1935  if test "x$want_gnome" = xyes; then
1936  {
1937    AC_MSG_CHECKING(for libgnomeui-2.0)
1938    if $PKG_CONFIG --exists libgnomeui-2.0; then
1939      AC_MSG_RESULT(yes)
1940      GNOME_LIBS=`$PKG_CONFIG --libs-only-l libgnomeui-2.0`
1941      GNOME_LIBDIR=`$PKG_CONFIG --libs-only-L libgnomeui-2.0`
1942      GNOME_INCLUDEDIR=`$PKG_CONFIG --cflags libgnomeui-2.0`
1943
1944      dnl On FreeBSD we need -pthread but pkg-config doesn't include it.
1945      dnl This might not be the right way but it works for me...
1946      AC_MSG_CHECKING(for FreeBSD)
1947      if test "`(uname) 2>/dev/null`" = FreeBSD; then
1948	AC_MSG_RESULT(yes, adding -pthread)
1949	GNOME_INCLUDEDIR="$GNOME_INCLUDEDIR -D_THREAD_SAFE"
1950	GNOME_LIBS="$GNOME_LIBS -pthread"
1951      else
1952	AC_MSG_RESULT(no)
1953      fi
1954      $1
1955    else
1956      AC_MSG_RESULT(not found)
1957      if test "x$2" = xfail; then
1958	AC_MSG_ERROR(Could not find libgnomeui-2.0 via pkg-config)
1959      fi
1960    fi
1961  }
1962  fi
1963])
1964
1965AC_DEFUN([GNOME_INIT],[
1966	GNOME_INIT_HOOK([],fail)
1967])
1968
1969
1970dnl ---------------------------------------------------------------------------
1971dnl Check for GTK2.  If it fails, then continue on for Motif as before...
1972dnl ---------------------------------------------------------------------------
1973if test -z "$SKIP_GTK2"; then
1974
1975  AC_MSG_CHECKING(--disable-gtktest argument)
1976  AC_ARG_ENABLE(gtktest, [  --disable-gtktest       Do not try to compile and run a test GTK program],
1977	, enable_gtktest=yes)
1978  if test "x$enable_gtktest" = "xyes" ; then
1979    AC_MSG_RESULT(gtk test enabled)
1980  else
1981    AC_MSG_RESULT(gtk test disabled)
1982  fi
1983
1984  if test "X$PKG_CONFIG" = "X"; then
1985    AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
1986  fi
1987
1988  if test "x$PKG_CONFIG" != "xno"; then
1989    dnl First try finding version 2.2.0 or later.  The 2.0.x series has
1990    dnl problems (bold fonts, --remote doesn't work).
1991    AM_PATH_GTK(2.2.0,
1992		[GUI_LIB_LOC="$GTK_LIBDIR"
1993		 GTK_LIBNAME="$GTK_LIBS"
1994		GUI_INC_LOC="$GTK_CFLAGS"], )
1995    if test "x$GTK_CFLAGS" != "x"; then
1996      SKIP_ATHENA=YES
1997      SKIP_NEXTAW=YES
1998      SKIP_MOTIF=YES
1999      GUITYPE=GTK
2000      AC_SUBST(GTK_LIBNAME)
2001    fi
2002  fi
2003  if test "x$GUITYPE" = "xGTK"; then
2004    if test "$gtk_minor_version" = 1 -a "0$gtk_micro_version" -ge 1 \
2005	|| test "0$gtk_minor_version" -ge 2; then
2006      AC_DEFINE(HAVE_GTK_MULTIHEAD)
2007    fi
2008    dnl
2009    dnl if GTK exists, then check for GNOME.
2010    dnl
2011    if test -z "$SKIP_GNOME"; then
2012    {
2013      GNOME_INIT_HOOK([have_gnome=yes])
2014      if test "x$have_gnome" = xyes ; then
2015	AC_DEFINE(FEAT_GUI_GNOME)
2016	GUI_INC_LOC="$GUI_INC_LOC $GNOME_INCLUDEDIR"
2017	GTK_LIBNAME="$GTK_LIBNAME $GNOME_LIBDIR $GNOME_LIBS"
2018      fi
2019    }
2020    fi
2021  fi
2022fi
2023
2024dnl Check for Motif include files location.
2025dnl The LAST one found is used, this makes the highest version to be used,
2026dnl e.g. when Motif1.2 and Motif2.0 are both present.
2027
2028if test -z "$SKIP_MOTIF"; then
2029  gui_XXX="/usr/XXX/Motif* /usr/Motif*/XXX /usr/XXX /usr/shlib /usr/X11*/XXX /usr/XXX/X11* /usr/dt/XXX /local/Motif*/XXX /local/XXX/Motif* /usr/local/Motif*/XXX /usr/local/XXX/Motif* /usr/local/XXX /usr/local/X11*/XXX /usr/local/LessTif/Motif*/XXX $MOTIFHOME/XXX"
2030  dnl Remove "-I" from before $GUI_INC_LOC if it's there
2031  GUI_INC_LOC="`echo $GUI_INC_LOC|sed 's%-I%%g'`"
2032
2033  AC_MSG_CHECKING(for location of Motif GUI includes)
2034  gui_includes="`echo $x_includes|sed 's%/[^/][^/]*$%%'` `echo "$gui_XXX" | sed s/XXX/include/g` $GUI_INC_LOC"
2035  GUI_INC_LOC=
2036  for try in $gui_includes; do
2037    if test -f "$try/Xm/Xm.h"; then
2038      GUI_INC_LOC=$try
2039    fi
2040  done
2041  if test -n "$GUI_INC_LOC"; then
2042    if test "$GUI_INC_LOC" = /usr/include; then
2043      GUI_INC_LOC=
2044      AC_MSG_RESULT(in default path)
2045    else
2046      AC_MSG_RESULT($GUI_INC_LOC)
2047    fi
2048  else
2049    AC_MSG_RESULT(<not found>)
2050    SKIP_MOTIF=YES
2051  fi
2052fi
2053
2054dnl Check for Motif library files location.  In the same order as the include
2055dnl files, to avoid a mixup if several versions are present
2056
2057if test -z "$SKIP_MOTIF"; then
2058  AC_MSG_CHECKING(--with-motif-lib argument)
2059  AC_ARG_WITH(motif-lib,
2060  [  --with-motif-lib=STRING   Library for Motif ],
2061  [ MOTIF_LIBNAME="${withval}" ] )
2062
2063  if test -n "$MOTIF_LIBNAME"; then
2064    AC_MSG_RESULT($MOTIF_LIBNAME)
2065    GUI_LIB_LOC=
2066  else
2067    AC_MSG_RESULT(no)
2068
2069    dnl Remove "-L" from before $GUI_LIB_LOC if it's there
2070    GUI_LIB_LOC="`echo $GUI_LIB_LOC|sed 's%-L%%g'`"
2071
2072    AC_MSG_CHECKING(for location of Motif GUI libs)
2073    gui_libs="`echo $x_libraries|sed 's%/[^/][^/]*$%%'` `echo "$gui_XXX" | sed s/XXX/lib/g` `echo "$GUI_INC_LOC" | sed s/include/lib/` $GUI_LIB_LOC"
2074    GUI_LIB_LOC=
2075    for try in $gui_libs; do
2076      for libtry in "$try"/libXm.a "$try"/libXm.so* "$try"/libXm.sl "$try"/libXm.dylib; do
2077	if test -f "$libtry"; then
2078	  GUI_LIB_LOC=$try
2079	fi
2080      done
2081    done
2082    if test -n "$GUI_LIB_LOC"; then
2083      dnl Remove /usr/lib, it causes trouble on some systems
2084      if test "$GUI_LIB_LOC" = /usr/lib; then
2085	GUI_LIB_LOC=
2086	AC_MSG_RESULT(in default path)
2087      else
2088	if test -n "$GUI_LIB_LOC"; then
2089	  AC_MSG_RESULT($GUI_LIB_LOC)
2090	  if test "`(uname) 2>/dev/null`" = SunOS &&
2091					 uname -r | grep '^5' >/dev/null; then
2092	    GUI_LIB_LOC="$GUI_LIB_LOC -R $GUI_LIB_LOC"
2093	  fi
2094	fi
2095      fi
2096      MOTIF_LIBNAME=-lXm
2097    else
2098      AC_MSG_RESULT(<not found>)
2099      SKIP_MOTIF=YES
2100    fi
2101  fi
2102fi
2103
2104if test -z "$SKIP_MOTIF"; then
2105  SKIP_ATHENA=YES
2106  SKIP_NEXTAW=YES
2107  GUITYPE=MOTIF
2108  AC_SUBST(MOTIF_LIBNAME)
2109fi
2110
2111dnl Check if the Athena files can be found
2112
2113GUI_X_LIBS=
2114
2115if test -z "$SKIP_ATHENA"; then
2116  AC_MSG_CHECKING(if Athena header files can be found)
2117  cflags_save=$CFLAGS
2118  CFLAGS="$CFLAGS $X_CFLAGS"
2119  AC_TRY_COMPILE([
2120#include <X11/Intrinsic.h>
2121#include <X11/Xaw/Paned.h>], ,
2122	AC_MSG_RESULT(yes),
2123	AC_MSG_RESULT(no); SKIP_ATHENA=YES )
2124  CFLAGS=$cflags_save
2125fi
2126
2127if test -z "$SKIP_ATHENA"; then
2128  GUITYPE=ATHENA
2129fi
2130
2131if test -z "$SKIP_NEXTAW"; then
2132  AC_MSG_CHECKING(if neXtaw header files can be found)
2133  cflags_save=$CFLAGS
2134  CFLAGS="$CFLAGS $X_CFLAGS"
2135  AC_TRY_COMPILE([
2136#include <X11/Intrinsic.h>
2137#include <X11/neXtaw/Paned.h>], ,
2138	AC_MSG_RESULT(yes),
2139	AC_MSG_RESULT(no); SKIP_NEXTAW=YES )
2140  CFLAGS=$cflags_save
2141fi
2142
2143if test -z "$SKIP_NEXTAW"; then
2144  GUITYPE=NEXTAW
2145fi
2146
2147if test -z "$SKIP_ATHENA" -o -z "$SKIP_NEXTAW" -o -z "$SKIP_MOTIF"; then
2148  dnl Prepend -I and -L to $GUI_INC_LOC and $GUI_LIB_LOC if not empty
2149  dnl Avoid adding it when it twice
2150  if test -n "$GUI_INC_LOC"; then
2151    GUI_INC_LOC=-I"`echo $GUI_INC_LOC|sed 's%-I%%'`"
2152  fi
2153  if test -n "$GUI_LIB_LOC"; then
2154    GUI_LIB_LOC=-L"`echo $GUI_LIB_LOC|sed 's%-L%%'`"
2155  fi
2156
2157  dnl Check for -lXext and then for -lXmu
2158  ldflags_save=$LDFLAGS
2159  LDFLAGS="$X_LIBS $LDFLAGS"
2160  AC_CHECK_LIB(Xext, XShapeQueryExtension, [GUI_X_LIBS="-lXext"],,
2161		[-lXt $X_PRE_LIBS -lX11 $X_EXTRA_LIBS])
2162  dnl For Solaris we need -lw and -ldl before linking with -lXmu works.
2163  AC_CHECK_LIB(w, wslen, [X_EXTRA_LIBS="$X_EXTRA_LIBS -lw"],,
2164		[$GUI_X_LIBS -lXt $X_PRE_LIBS -lX11 $X_EXTRA_LIBS])
2165  AC_CHECK_LIB(dl, dlsym, [X_EXTRA_LIBS="$X_EXTRA_LIBS -ldl"],,
2166		[$GUI_X_LIBS -lXt $X_PRE_LIBS -lX11 $X_EXTRA_LIBS])
2167  AC_CHECK_LIB(Xmu, XmuCreateStippledPixmap, [GUI_X_LIBS="-lXmu $GUI_X_LIBS"],,
2168		[$GUI_X_LIBS -lXt $X_PRE_LIBS -lX11 $X_EXTRA_LIBS])
2169  if test -z "$SKIP_MOTIF"; then
2170    AC_CHECK_LIB(Xp, XpEndJob, [GUI_X_LIBS="-lXp $GUI_X_LIBS"],,
2171		[$GUI_X_LIBS -lXm -lXt $X_PRE_LIBS -lX11 $X_EXTRA_LIBS])
2172  fi
2173  LDFLAGS=$ldflags_save
2174
2175  dnl Execute xmkmf to figure out if -DNARROWPROTO is needed.
2176  AC_MSG_CHECKING(for extra X11 defines)
2177  NARROW_PROTO=
2178  rm -fr conftestdir
2179  if mkdir conftestdir; then
2180    cd conftestdir
2181    cat > Imakefile <<'EOF'
2182acfindx:
2183	@echo 'NARROW_PROTO="${PROTO_DEFINES}"'
2184EOF
2185    if (xmkmf) >/dev/null 2>/dev/null && test -f Makefile; then
2186      eval `${MAKE-make} acfindx 2>/dev/null | grep -v make`
2187    fi
2188    cd ..
2189    rm -fr conftestdir
2190  fi
2191  if test -z "$NARROW_PROTO"; then
2192    AC_MSG_RESULT(no)
2193  else
2194    AC_MSG_RESULT($NARROW_PROTO)
2195  fi
2196  AC_SUBST(NARROW_PROTO)
2197fi
2198
2199dnl Look for XSMP support - but don't necessarily restrict it to X11 GUIs
2200dnl use the X11 include path
2201if test "$enable_xsmp" = "yes"; then
2202  cppflags_save=$CPPFLAGS
2203  CPPFLAGS="$CPPFLAGS $X_CFLAGS"
2204  AC_CHECK_HEADERS(X11/SM/SMlib.h)
2205  CPPFLAGS=$cppflags_save
2206fi
2207
2208
2209if test -z "$SKIP_ATHENA" -o -z "$SKIP_NEXTAW" -o -z "$SKIP_MOTIF" -o -z "$SKIP_GTK2"; then
2210  dnl Check for X11/xpm.h and X11/Sunkeysym.h with the GUI include path
2211  cppflags_save=$CPPFLAGS
2212  CPPFLAGS="$CPPFLAGS $X_CFLAGS"
2213  AC_CHECK_HEADERS(X11/xpm.h X11/Sunkeysym.h)
2214
2215  dnl automatically disable XIM when XIMtext isn't in X11/Xlib.h
2216  if test ! "$enable_xim" = "no"; then
2217    AC_MSG_CHECKING(for XIMText in X11/Xlib.h)
2218    AC_EGREP_CPP(XIMText, [#include <X11/Xlib.h>],
2219		  AC_MSG_RESULT(yes),
2220		  AC_MSG_RESULT(no; xim has been disabled); enable_xim = "no")
2221  fi
2222  CPPFLAGS=$cppflags_save
2223
2224  dnl automatically enable XIM when hangul input isn't enabled
2225  if test "$enable_xim" = "auto" -a "$enable_hangulinput" != "yes" \
2226		-a "x$GUITYPE" != "xNONE" ; then
2227    AC_MSG_RESULT(X GUI selected; xim has been enabled)
2228    enable_xim="yes"
2229  fi
2230fi
2231
2232if test -z "$SKIP_ATHENA" -o -z "$SKIP_NEXTAW" -o -z "$SKIP_MOTIF"; then
2233  cppflags_save=$CPPFLAGS
2234  CPPFLAGS="$CPPFLAGS $X_CFLAGS"
2235dnl Xmu/Editres.h may exist but can only be used after including Intrinsic.h
2236  AC_MSG_CHECKING([for X11/Xmu/Editres.h])
2237  AC_TRY_COMPILE([
2238#include <X11/Intrinsic.h>
2239#include <X11/Xmu/Editres.h>],
2240		      [int i; i = 0;],
2241	      AC_MSG_RESULT(yes)
2242		      AC_DEFINE(HAVE_X11_XMU_EDITRES_H),
2243	      AC_MSG_RESULT(no))
2244  CPPFLAGS=$cppflags_save
2245fi
2246
2247dnl Only use the Xm directory when compiling Motif, don't use it for Athena
2248if test -z "$SKIP_MOTIF"; then
2249  cppflags_save=$CPPFLAGS
2250  CPPFLAGS="$CPPFLAGS $X_CFLAGS"
2251  AC_CHECK_HEADERS(Xm/Xm.h Xm/XpmP.h Xm/JoinSideT.h Xm/TraitP.h Xm/Manager.h \
2252		   Xm/UnhighlightT.h Xm/Notebook.h)
2253
2254  if test $ac_cv_header_Xm_XpmP_h = yes; then
2255    dnl Solaris uses XpmAttributes_21, very annoying.
2256    AC_MSG_CHECKING([for XpmAttributes_21 in Xm/XpmP.h])
2257    AC_TRY_COMPILE([#include <Xm/XpmP.h>], [XpmAttributes_21 attr;],
2258	AC_MSG_RESULT(yes); AC_DEFINE(XPMATTRIBUTES_TYPE, XpmAttributes_21),
2259	AC_MSG_RESULT(no); AC_DEFINE(XPMATTRIBUTES_TYPE, XpmAttributes)
2260	)
2261  else
2262    AC_DEFINE(XPMATTRIBUTES_TYPE, XpmAttributes)
2263  fi
2264  CPPFLAGS=$cppflags_save
2265fi
2266
2267if test "x$GUITYPE" = "xNONE" -a "$enable_xim" = "yes"; then
2268  AC_MSG_RESULT(no GUI selected; xim has been disabled)
2269  enable_xim="no"
2270fi
2271if test "x$GUITYPE" = "xNONE" -a "$enable_fontset" = "yes"; then
2272  AC_MSG_RESULT(no GUI selected; fontset has been disabled)
2273  enable_fontset="no"
2274fi
2275if test "x$GUITYPE:$enable_fontset" = "xGTK:yes"; then
2276  AC_MSG_RESULT(GTK+ 2 GUI selected; fontset has been disabled)
2277  enable_fontset="no"
2278fi
2279
2280if test -z "$SKIP_PHOTON"; then
2281  GUITYPE=PHOTONGUI
2282fi
2283
2284AC_SUBST(GUI_INC_LOC)
2285AC_SUBST(GUI_LIB_LOC)
2286AC_SUBST(GUITYPE)
2287AC_SUBST(GUI_X_LIBS)
2288
2289if test "$enable_workshop" = "yes" -a -n "$SKIP_MOTIF"; then
2290  AC_MSG_ERROR([cannot use workshop without Motif])
2291fi
2292
2293dnl defining FEAT_XIM and FEAT_XFONTSET is delayed, so that they can be disabled
2294if test "$enable_xim" = "yes"; then
2295  AC_DEFINE(FEAT_XIM)
2296fi
2297if test "$enable_fontset" = "yes"; then
2298  AC_DEFINE(FEAT_XFONTSET)
2299fi
2300
2301
2302dnl ---------------------------------------------------------------------------
2303dnl end of GUI-checking
2304dnl ---------------------------------------------------------------------------
2305
2306
2307dnl Only really enable hangul input when GUI and XFONTSET are available
2308if test "$enable_hangulinput" = "yes"; then
2309  if test "x$GUITYPE" = "xNONE"; then
2310    AC_MSG_RESULT(no GUI selected; hangul input has been disabled)
2311    enable_hangulinput=no
2312  else
2313    AC_DEFINE(FEAT_HANGULIN)
2314    HANGULIN_SRC=hangulin.c
2315    AC_SUBST(HANGULIN_SRC)
2316    HANGULIN_OBJ=objects/hangulin.o
2317    AC_SUBST(HANGULIN_OBJ)
2318  fi
2319fi
2320
2321dnl Checks for libraries and include files.
2322
2323AC_CACHE_CHECK([whether toupper is broken], [vim_cv_toupper_broken],
2324  [
2325    AC_RUN_IFELSE([[
2326#include "confdefs.h"
2327#include <ctype.h>
2328#if STDC_HEADERS
2329# include <stdlib.h>
2330# include <stddef.h>
2331#endif
2332main() { exit(toupper('A') == 'A' && tolower('z') == 'z'); }
2333  ]],[
2334    vim_cv_toupper_broken=yes
2335  ],[
2336    vim_cv_toupper_broken=no
2337  ],[
2338    AC_MSG_ERROR(cross-compiling: please set 'vim_cv_toupper_broken')
2339  ])])
2340
2341if test "x$vim_cv_toupper_broken" = "xyes" ; then
2342  AC_DEFINE(BROKEN_TOUPPER)
2343fi
2344
2345AC_MSG_CHECKING(whether __DATE__ and __TIME__ work)
2346AC_TRY_COMPILE([#include <stdio.h>], [printf("(" __DATE__ " " __TIME__ ")");],
2347	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_DATE_TIME),
2348	AC_MSG_RESULT(no))
2349
2350AC_MSG_CHECKING(whether __attribute__((unused)) is allowed)
2351AC_TRY_COMPILE([#include <stdio.h>], [int x __attribute__((unused));],
2352	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_ATTRIBUTE_UNUSED),
2353	AC_MSG_RESULT(no))
2354
2355dnl Checks for header files.
2356AC_CHECK_HEADER(elf.h, HAS_ELF=1)
2357dnl AC_CHECK_HEADER(dwarf.h, SVR4=1)
2358if test "$HAS_ELF" = 1; then
2359  AC_CHECK_LIB(elf, main)
2360fi
2361
2362AC_HEADER_DIRENT
2363
2364dnl If sys/wait.h is not found it might still exist but not be POSIX
2365dnl compliant. In that case we define HAVE_UNION_WAIT (for NeXT)
2366if test $ac_cv_header_sys_wait_h = no; then
2367  AC_MSG_CHECKING([for sys/wait.h that defines union wait])
2368  AC_TRY_COMPILE([#include <sys/wait.h>],
2369			[union wait xx, yy; xx = yy],
2370		AC_MSG_RESULT(yes)
2371			AC_DEFINE(HAVE_SYS_WAIT_H)
2372			AC_DEFINE(HAVE_UNION_WAIT),
2373		AC_MSG_RESULT(no))
2374fi
2375
2376AC_CHECK_HEADERS(stdarg.h stdint.h stdlib.h string.h \
2377	sys/select.h sys/utsname.h termcap.h fcntl.h \
2378	sgtty.h sys/ioctl.h sys/time.h sys/types.h \
2379	termio.h iconv.h inttypes.h langinfo.h math.h \
2380	unistd.h stropts.h errno.h sys/resource.h \
2381	sys/systeminfo.h locale.h sys/stream.h termios.h \
2382	libc.h sys/statfs.h poll.h sys/poll.h pwd.h \
2383	utime.h sys/param.h libintl.h libgen.h \
2384	util/debug.h util/msg18n.h frame.h sys/acl.h \
2385	sys/access.h sys/sysinfo.h wchar.h wctype.h)
2386
2387dnl sys/ptem.h depends on sys/stream.h on Solaris
2388AC_CHECK_HEADERS(sys/ptem.h, [], [],
2389[#if defined HAVE_SYS_STREAM_H
2390#  include <sys/stream.h>
2391#endif])
2392
2393dnl sys/sysctl.h depends on sys/param.h on OpenBSD
2394AC_CHECK_HEADERS(sys/sysctl.h, [], [],
2395[#if defined HAVE_SYS_PARAM_H
2396#  include <sys/param.h>
2397#endif])
2398
2399
2400dnl pthread_np.h may exist but can only be used after including pthread.h
2401AC_MSG_CHECKING([for pthread_np.h])
2402AC_TRY_COMPILE([
2403#include <pthread.h>
2404#include <pthread_np.h>],
2405		      [int i; i = 0;],
2406	      AC_MSG_RESULT(yes)
2407		      AC_DEFINE(HAVE_PTHREAD_NP_H),
2408	      AC_MSG_RESULT(no))
2409
2410AC_CHECK_HEADERS(strings.h)
2411if test "x$MACOSX" = "xyes"; then
2412  dnl The strings.h file on OS/X contains a warning and nothing useful.
2413  AC_DEFINE(NO_STRINGS_WITH_STRING_H)
2414else
2415
2416dnl Check if strings.h and string.h can both be included when defined.
2417AC_MSG_CHECKING([if strings.h can be included after string.h])
2418cppflags_save=$CPPFLAGS
2419CPPFLAGS="$CPPFLAGS $X_CFLAGS"
2420AC_TRY_COMPILE([
2421#if defined(_AIX) && !defined(_AIX51) && !defined(_NO_PROTO)
2422# define _NO_PROTO	/* like in os_unix.h, causes conflict for AIX (Winn) */
2423			/* but don't do it on AIX 5.1 (Uribarri) */
2424#endif
2425#ifdef HAVE_XM_XM_H
2426# include <Xm/Xm.h>	/* This breaks it for HP-UX 11 (Squassabia) */
2427#endif
2428#ifdef HAVE_STRING_H
2429# include <string.h>
2430#endif
2431#if defined(HAVE_STRINGS_H)
2432# include <strings.h>
2433#endif
2434		], [int i; i = 0;],
2435		AC_MSG_RESULT(yes),
2436		AC_DEFINE(NO_STRINGS_WITH_STRING_H)
2437		AC_MSG_RESULT(no))
2438CPPFLAGS=$cppflags_save
2439fi
2440
2441dnl Checks for typedefs, structures, and compiler characteristics.
2442AC_PROG_GCC_TRADITIONAL
2443AC_C_CONST
2444AC_C_VOLATILE
2445AC_TYPE_MODE_T
2446AC_TYPE_OFF_T
2447AC_TYPE_PID_T
2448AC_TYPE_SIZE_T
2449AC_TYPE_UID_T
2450AC_TYPE_UINT32_T
2451
2452AC_HEADER_TIME
2453AC_CHECK_TYPE(ino_t, long)
2454AC_CHECK_TYPE(dev_t, unsigned)
2455AC_C_BIGENDIAN(,,,)
2456
2457AC_MSG_CHECKING(for rlim_t)
2458if eval "test \"`echo '$''{'ac_cv_type_rlim_t'+set}'`\" = set"; then
2459  AC_MSG_RESULT([(cached) $ac_cv_type_rlim_t])
2460else
2461  AC_EGREP_CPP(dnl
2462changequote(<<,>>)dnl
2463<<(^|[^a-zA-Z_0-9])rlim_t[^a-zA-Z_0-9]>>dnl
2464changequote([,]),
2465  [
2466#include <sys/types.h>
2467#if STDC_HEADERS
2468# include <stdlib.h>
2469# include <stddef.h>
2470#endif
2471#ifdef HAVE_SYS_RESOURCE_H
2472# include <sys/resource.h>
2473#endif
2474	  ], ac_cv_type_rlim_t=yes, ac_cv_type_rlim_t=no)
2475	  AC_MSG_RESULT($ac_cv_type_rlim_t)
2476fi
2477if test $ac_cv_type_rlim_t = no; then
2478  cat >> confdefs.h <<\EOF
2479#define rlim_t unsigned long
2480EOF
2481fi
2482
2483AC_MSG_CHECKING(for stack_t)
2484if eval "test \"`echo '$''{'ac_cv_type_stack_t'+set}'`\" = set"; then
2485  AC_MSG_RESULT([(cached) $ac_cv_type_stack_t])
2486else
2487  AC_EGREP_CPP(stack_t,
2488  [
2489#include <sys/types.h>
2490#if STDC_HEADERS
2491# include <stdlib.h>
2492# include <stddef.h>
2493#endif
2494#include <signal.h>
2495	  ], ac_cv_type_stack_t=yes, ac_cv_type_stack_t=no)
2496	  AC_MSG_RESULT($ac_cv_type_stack_t)
2497fi
2498if test $ac_cv_type_stack_t = no; then
2499  cat >> confdefs.h <<\EOF
2500#define stack_t struct sigaltstack
2501EOF
2502fi
2503
2504dnl BSDI uses ss_base while others use ss_sp for the stack pointer.
2505AC_MSG_CHECKING(whether stack_t has an ss_base field)
2506AC_TRY_COMPILE([
2507#include <sys/types.h>
2508#if STDC_HEADERS
2509# include <stdlib.h>
2510# include <stddef.h>
2511#endif
2512#include <signal.h>
2513#include "confdefs.h"
2514			], [stack_t sigstk; sigstk.ss_base = 0; ],
2515	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SS_BASE),
2516	AC_MSG_RESULT(no))
2517
2518olibs="$LIBS"
2519AC_MSG_CHECKING(--with-tlib argument)
2520AC_ARG_WITH(tlib, [  --with-tlib=library     terminal library to be used ],)
2521if test -n "$with_tlib"; then
2522  AC_MSG_RESULT($with_tlib)
2523  LIBS="$LIBS -l$with_tlib"
2524  AC_MSG_CHECKING(for linking with $with_tlib library)
2525  AC_TRY_LINK([], [], AC_MSG_RESULT(OK), AC_MSG_ERROR(FAILED))
2526  dnl Need to check for tgetent() below.
2527  olibs="$LIBS"
2528else
2529  AC_MSG_RESULT([empty: automatic terminal library selection])
2530  dnl  On HP-UX 10.10 termcap or termlib should be used instead of
2531  dnl  curses, because curses is much slower.
2532  dnl  Newer versions of ncurses are preferred over anything.
2533  dnl  Older versions of ncurses have bugs, get a new one!
2534  dnl  Digital Unix (OSF1) should use curses (Ronald Schild).
2535  dnl  On SCO Openserver should prefer termlib (Roger Cornelius).
2536  case "`uname -s 2>/dev/null`" in
2537	OSF1|SCO_SV)	tlibs="ncurses curses termlib termcap";;
2538	*)	tlibs="ncurses termlib termcap curses";;
2539  esac
2540  for libname in $tlibs; do
2541    AC_CHECK_LIB(${libname}, tgetent,,)
2542    if test "x$olibs" != "x$LIBS"; then
2543      dnl It's possible that a library is found but it doesn't work
2544      dnl e.g., shared library that cannot be found
2545      dnl compile and run a test program to be sure
2546      AC_TRY_RUN([
2547#ifdef HAVE_TERMCAP_H
2548# include <termcap.h>
2549#endif
2550#if STDC_HEADERS
2551# include <stdlib.h>
2552# include <stddef.h>
2553#endif
2554main() {char *s; s=(char *)tgoto("%p1%d", 0, 1); exit(0); }],
2555			  res="OK", res="FAIL", res="FAIL")
2556      if test "$res" = "OK"; then
2557	break
2558      fi
2559      AC_MSG_RESULT($libname library is not usable)
2560      LIBS="$olibs"
2561    fi
2562  done
2563  if test "x$olibs" = "x$LIBS"; then
2564    AC_MSG_RESULT(no terminal library found)
2565  fi
2566fi
2567
2568if test "x$olibs" = "x$LIBS"; then
2569  AC_MSG_CHECKING([for tgetent()])
2570  AC_TRY_LINK([],
2571      [char s[10000]; int res = tgetent(s, "thisterminaldoesnotexist");],
2572	AC_MSG_RESULT(yes),
2573	AC_MSG_ERROR([NOT FOUND!
2574      You need to install a terminal library; for example ncurses.
2575      Or specify the name of the library with --with-tlib.]))
2576fi
2577
2578AC_CACHE_CHECK([whether we talk terminfo], [vim_cv_terminfo],
2579  [
2580    AC_RUN_IFELSE([[
2581#include "confdefs.h"
2582#ifdef HAVE_TERMCAP_H
2583# include <termcap.h>
2584#endif
2585#ifdef HAVE_STRING_H
2586# include <string.h>
2587#endif
2588#if STDC_HEADERS
2589# include <stdlib.h>
2590# include <stddef.h>
2591#endif
2592main()
2593{char *s; s=(char *)tgoto("%p1%d", 0, 1); exit(!strcmp(s==0 ? "" : s, "1")); }
2594    ]],[
2595      vim_cv_terminfo=no
2596    ],[
2597      vim_cv_terminfo=yes
2598    ],[
2599      AC_MSG_ERROR(cross-compiling: please set 'vim_cv_terminfo')
2600    ])
2601  ])
2602
2603if test "x$vim_cv_terminfo" = "xyes" ; then
2604  AC_DEFINE(TERMINFO)
2605fi
2606
2607if test "x$olibs" != "x$LIBS"; then
2608  AC_CACHE_CHECK([what tgetent() returns for an unknown terminal], [vim_cv_tgent],
2609    [
2610      AC_RUN_IFELSE([[
2611#include "confdefs.h"
2612#ifdef HAVE_TERMCAP_H
2613# include <termcap.h>
2614#endif
2615#if STDC_HEADERS
2616# include <stdlib.h>
2617# include <stddef.h>
2618#endif
2619main()
2620{char s[10000]; int res = tgetent(s, "thisterminaldoesnotexist"); exit(res != 0); }
2621      ]],[
2622	vim_cv_tgent=zero
2623      ],[
2624	vim_cv_tgent=non-zero
2625      ],[
2626	AC_MSG_ERROR(failed to compile test program.)
2627      ])
2628    ])
2629  
2630  if test "x$vim_cv_tgent" = "xzero" ; then
2631    AC_DEFINE(TGETENT_ZERO_ERR, 0)
2632  fi
2633fi
2634
2635AC_MSG_CHECKING(whether termcap.h contains ospeed)
2636AC_TRY_LINK([
2637#ifdef HAVE_TERMCAP_H
2638# include <termcap.h>
2639#endif
2640			], [ospeed = 20000],
2641	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_OSPEED),
2642	[AC_MSG_RESULT(no)
2643	AC_MSG_CHECKING(whether ospeed can be extern)
2644	AC_TRY_LINK([
2645#ifdef HAVE_TERMCAP_H
2646# include <termcap.h>
2647#endif
2648extern short ospeed;
2649			], [ospeed = 20000],
2650		AC_MSG_RESULT(yes); AC_DEFINE(OSPEED_EXTERN),
2651		AC_MSG_RESULT(no))]
2652	)
2653
2654AC_MSG_CHECKING([whether termcap.h contains UP, BC and PC])
2655AC_TRY_LINK([
2656#ifdef HAVE_TERMCAP_H
2657# include <termcap.h>
2658#endif
2659			], [if (UP == 0 && BC == 0) PC = 1],
2660	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_UP_BC_PC),
2661	[AC_MSG_RESULT(no)
2662	AC_MSG_CHECKING([whether UP, BC and PC can be extern])
2663	AC_TRY_LINK([
2664#ifdef HAVE_TERMCAP_H
2665# include <termcap.h>
2666#endif
2667extern char *UP, *BC, PC;
2668			], [if (UP == 0 && BC == 0) PC = 1],
2669		AC_MSG_RESULT(yes); AC_DEFINE(UP_BC_PC_EXTERN),
2670		AC_MSG_RESULT(no))]
2671	)
2672
2673AC_MSG_CHECKING(whether tputs() uses outfuntype)
2674AC_TRY_COMPILE([
2675#ifdef HAVE_TERMCAP_H
2676# include <termcap.h>
2677#endif
2678			], [extern int xx(); tputs("test", 1, (outfuntype)xx)],
2679	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_OUTFUNTYPE),
2680	AC_MSG_RESULT(no))
2681
2682dnl On some SCO machines sys/select redefines struct timeval
2683AC_MSG_CHECKING([whether sys/select.h and sys/time.h may both be included])
2684AC_TRY_COMPILE([
2685#include <sys/types.h>
2686#include <sys/time.h>
2687#include <sys/select.h>], ,
2688	  AC_MSG_RESULT(yes)
2689			AC_DEFINE(SYS_SELECT_WITH_SYS_TIME),
2690	  AC_MSG_RESULT(no))
2691
2692dnl AC_DECL_SYS_SIGLIST
2693
2694dnl Checks for pty.c (copied from screen) ==========================
2695AC_MSG_CHECKING(for /dev/ptc)
2696if test -r /dev/ptc; then
2697  AC_DEFINE(HAVE_DEV_PTC)
2698  AC_MSG_RESULT(yes)
2699else
2700  AC_MSG_RESULT(no)
2701fi
2702
2703AC_MSG_CHECKING(for SVR4 ptys)
2704if test -c /dev/ptmx ; then
2705  AC_TRY_LINK([], [ptsname(0);grantpt(0);unlockpt(0);],
2706	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SVR4_PTYS),
2707	AC_MSG_RESULT(no))
2708else
2709  AC_MSG_RESULT(no)
2710fi
2711
2712AC_MSG_CHECKING(for ptyranges)
2713if test -d /dev/ptym ; then
2714  pdir='/dev/ptym'
2715else
2716  pdir='/dev'
2717fi
2718dnl SCO uses ptyp%d
2719AC_EGREP_CPP(yes,
2720[#ifdef M_UNIX
2721   yes;
2722#endif
2723	], ptys=`echo /dev/ptyp??`, ptys=`echo $pdir/pty??`)
2724dnl if test -c /dev/ptyp19; then
2725dnl ptys=`echo /dev/ptyp??`
2726dnl else
2727dnl ptys=`echo $pdir/pty??`
2728dnl fi
2729if test "$ptys" != "$pdir/pty??" ; then
2730  p0=`echo $ptys | tr ' ' '\012' | sed -e 's/^.*\(.\).$/\1/g' | sort -u | tr -d '\012'`
2731  p1=`echo $ptys | tr ' ' '\012' | sed -e 's/^.*\(.\)$/\1/g'  | sort -u | tr -d '\012'`
2732  AC_DEFINE_UNQUOTED(PTYRANGE0,"$p0")
2733  AC_DEFINE_UNQUOTED(PTYRANGE1,"$p1")
2734  AC_MSG_RESULT([$p0 / $p1])
2735else
2736  AC_MSG_RESULT([don't know])
2737fi
2738
2739dnl    ****  pty mode/group handling ****
2740dnl
2741dnl support provided by Luke Mewburn <lm@rmit.edu.au>, 931222
2742rm -f conftest_grp
2743AC_CACHE_CHECK([default tty permissions/group], [vim_cv_tty_group],
2744  [
2745    AC_RUN_IFELSE([[
2746#include "confdefs.h"
2747#include <sys/types.h>
2748#if STDC_HEADERS
2749# include <stdlib.h>
2750# include <stddef.h>
2751#endif
2752#ifdef HAVE_UNISTD_H
2753#include <unistd.h>
2754#endif
2755#include <sys/stat.h>
2756#include <stdio.h>
2757main()
2758{
2759  struct stat sb;
2760  char *x,*ttyname();
2761  int om, m;
2762  FILE *fp;
2763
2764  if (!(x = ttyname(0))) exit(1);
2765  if (stat(x, &sb)) exit(1);
2766  om = sb.st_mode;
2767  if (om & 002) exit(0);
2768  m = system("mesg y");
2769  if (m == -1 || m == 127) exit(1);
2770  if (stat(x, &sb)) exit(1);
2771  m = sb.st_mode;
2772  if (chmod(x, om)) exit(1);
2773  if (m & 002) exit(0);
2774  if (sb.st_gid == getgid()) exit(1);
2775  if (!(fp=fopen("conftest_grp", "w")))
2776    exit(1);
2777  fprintf(fp, "%d\n", sb.st_gid);
2778  fclose(fp);
2779  exit(0);
2780}
2781    ]],[
2782      if test -f conftest_grp; then
2783	vim_cv_tty_group=`cat conftest_grp`
2784	if test "x$vim_cv_tty_mode" = "x" ; then
2785	  vim_cv_tty_mode=0620
2786	fi
2787	AC_MSG_RESULT([pty mode: $vim_cv_tty_mode, group: $vim_cv_tty_group])
2788      else
2789	vim_cv_tty_group=world
2790	AC_MSG_RESULT([ptys are world accessible])
2791      fi
2792    ],[
2793      vim_cv_tty_group=world
2794      AC_MSG_RESULT([can't determine - assume ptys are world accessible])
2795    ],[
2796      AC_MSG_ERROR(cross-compiling: please set 'vim_cv_tty_group' and 'vim_cv_tty_mode')
2797    ])
2798  ])
2799rm -f conftest_grp
2800
2801if test "x$vim_cv_tty_group" != "xworld" ; then
2802  AC_DEFINE_UNQUOTED(PTYGROUP,$vim_cv_tty_group)
2803  if test "x$vim_cv_tty_mode" = "x" ; then
2804    AC_MSG_ERROR([It seems you're cross compiling and have 'vim_cv_tty_group' set, please also set the environment variable 'vim_cv_tty_mode' to the correct mode (propably 0620)])
2805  else
2806    AC_DEFINE(PTYMODE, 0620)
2807  fi
2808fi
2809
2810dnl Checks for library functions. ===================================
2811
2812AC_TYPE_SIGNAL
2813
2814dnl find out what to use at the end of a signal function
2815if test $ac_cv_type_signal = void; then
2816  AC_DEFINE(SIGRETURN, [return])
2817else
2818  AC_DEFINE(SIGRETURN, [return 0])
2819fi
2820
2821dnl check if struct sigcontext is defined (used for SGI only)
2822AC_MSG_CHECKING(for struct sigcontext)
2823AC_TRY_COMPILE([
2824#include <signal.h>
2825test_sig()
2826{
2827    struct sigcontext *scont;
2828    scont = (struct sigcontext *)0;
2829    return 1;
2830} ], ,
2831	  AC_MSG_RESULT(yes)
2832		AC_DEFINE(HAVE_SIGCONTEXT),
2833	  AC_MSG_RESULT(no))
2834
2835dnl tricky stuff: try to find out if getcwd() is implemented with
2836dnl system("sh -c pwd")
2837AC_CACHE_CHECK([getcwd implementation is broken], [vim_cv_getcwd_broken],
2838  [
2839    AC_RUN_IFELSE([[
2840#include "confdefs.h"
2841#ifdef HAVE_UNISTD_H
2842#include <unistd.h>
2843#endif
2844char *dagger[] = { "IFS=pwd", 0 };
2845main()
2846{
2847  char buffer[500];
2848  extern char **environ;
2849  environ = dagger;
2850  return getcwd(buffer, 500) ? 0 : 1;
2851}
2852    ]],[
2853      vim_cv_getcwd_broken=no
2854    ],[
2855      vim_cv_getcwd_broken=yes
2856    ],[
2857      AC_MSG_ERROR(cross-compiling: please set 'vim_cv_getcwd_broken')
2858    ])
2859  ])
2860
2861if test "x$vim_cv_getcwd_broken" = "xyes" ; then
2862  AC_DEFINE(BAD_GETCWD)
2863fi
2864
2865dnl Check for functions in one big call, to reduce the size of configure.
2866dnl Can only be used for functions that do not require any include.
2867AC_CHECK_FUNCS(bcmp fchdir fchown fsync getcwd getpseudotty \
2868	getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \
2869	memset mkdtemp nanosleep opendir putenv qsort readlink select setenv \
2870	setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
2871	sigvec strcasecmp strerror strftime stricmp strncasecmp \
2872	strnicmp strpbrk strtol tgetent towlower towupper iswupper \
2873	usleep utime utimes)
2874AC_FUNC_FSEEKO
2875
2876dnl define _LARGE_FILES, _FILE_OFFSET_BITS and _LARGEFILE_SOURCE when
2877dnl appropriate, so that off_t is 64 bits when needed.
2878AC_SYS_LARGEFILE
2879
2880dnl fstatfs() can take 2 to 4 arguments, try to use st_blksize if possible
2881AC_MSG_CHECKING(for st_blksize)
2882AC_TRY_COMPILE(
2883[#include <sys/types.h>
2884#include <sys/stat.h>],
2885[	struct stat st;
2886	int n;
2887
2888	stat("/", &st);
2889	n = (int)st.st_blksize;],
2890	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_ST_BLKSIZE),
2891	AC_MSG_RESULT(no))
2892
2893AC_CACHE_CHECK([whether stat() ignores a trailing slash], [vim_cv_stat_ignores_slash],
2894  [
2895    AC_RUN_IFELSE([[
2896#include "confdefs.h"
2897#if STDC_HEADERS
2898# include <stdlib.h>
2899# include <stddef.h>
2900#endif
2901#include <sys/types.h>
2902#include <sys/stat.h>
2903main() {struct stat st;  exit(stat("configure/", &st) != 0); }
2904    ]],[
2905      vim_cv_stat_ignores_slash=yes
2906    ],[
2907      vim_cv_stat_ignores_slash=no
2908    ],[
2909      AC_MSG_ERROR(cross-compiling: please set 'vim_cv_stat_ignores_slash')
2910    ])
2911  ])
2912
2913if test "x$vim_cv_stat_ignores_slash" = "xyes" ; then
2914  AC_DEFINE(STAT_IGNORES_SLASH)
2915fi
2916  
2917dnl Link with iconv for charset translation, if not found without library.
2918dnl check for iconv() requires including iconv.h
2919dnl Add "-liconv" when possible; Solaris has iconv but use GNU iconv when it
2920dnl has been installed.
2921AC_MSG_CHECKING(for iconv_open())
2922save_LIBS="$LIBS"
2923LIBS="$LIBS -liconv"
2924AC_TRY_LINK([
2925#ifdef HAVE_ICONV_H
2926# include <iconv.h>
2927#endif
2928    ], [iconv_open("fr", "to");],
2929    AC_MSG_RESULT(yes; with -liconv); AC_DEFINE(HAVE_ICONV),
2930    LIBS="$save_LIBS"
2931    AC_TRY_LINK([
2932#ifdef HAVE_ICONV_H
2933# include <iconv.h>
2934#endif
2935	], [iconv_open("fr", "to");],
2936	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_ICONV),
2937	AC_MSG_RESULT(no)))
2938
2939
2940AC_MSG_CHECKING(for nl_langinfo(CODESET))
2941AC_TRY_LINK([
2942#ifdef HAVE_LANGINFO_H
2943# include <langinfo.h>
2944#endif
2945], [char *cs = nl_langinfo(CODESET);],
2946	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_NL_LANGINFO_CODESET),
2947	AC_MSG_RESULT(no))
2948
2949dnl Need various functions for floating point support.  Only enable
2950dnl floating point when they are all present.
2951AC_CHECK_LIB(m, strtod)
2952AC_MSG_CHECKING([for strtod() and other floating point functions])
2953AC_TRY_LINK([
2954#ifdef HAVE_MATH_H
2955# include <math.h>
2956#endif
2957#if STDC_HEADERS
2958# include <stdlib.h>
2959# include <stddef.h>
2960#endif
2961], [char *s; double d;
2962    d = strtod("1.1", &s);
2963    d = fabs(1.11);
2964    d = ceil(1.11);
2965    d = floor(1.11);
2966    d = log10(1.11);
2967    d = pow(1.11, 2.22);
2968    d = sqrt(1.11);
2969    d = sin(1.11);
2970    d = cos(1.11);
2971    d = atan(1.11);
2972    ],
2973	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_FLOAT_FUNCS),
2974	AC_MSG_RESULT(no))
2975
2976dnl Link with -lposix1e for ACL stuff; if not found, try -lacl for SGI
2977dnl when -lacl works, also try to use -lattr (required for Debian).
2978AC_MSG_CHECKING(--disable-acl argument)
2979AC_ARG_ENABLE(acl,
2980	[  --disable-acl           Don't check for ACL support.],
2981	, [enable_acl="yes"])
2982if test "$enable_acl" = "yes"; then
2983AC_MSG_RESULT(no)
2984AC_CHECK_LIB(posix1e, acl_get_file, [LIBS="$LIBS -lposix1e"],
2985	AC_CHECK_LIB(acl, acl_get_file, [LIBS="$LIBS -lacl"
2986		  AC_CHECK_LIB(attr, fgetxattr, LIBS="$LIBS -lattr",,)],,),)
2987
2988AC_MSG_CHECKING(for POSIX ACL support)
2989AC_TRY_LINK([
2990#include <sys/types.h>
2991#ifdef HAVE_SYS_ACL_H
2992# include <sys/acl.h>
2993#endif
2994acl_t acl;], [acl = acl_get_file("foo", ACL_TYPE_ACCESS);
2995	acl_set_file("foo", ACL_TYPE_ACCESS, acl);
2996	acl_free(acl);],
2997	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_POSIX_ACL),
2998	AC_MSG_RESULT(no))
2999
3000AC_MSG_CHECKING(for Solaris ACL support)
3001AC_TRY_LINK([
3002#ifdef HAVE_SYS_ACL_H
3003# include <sys/acl.h>
3004#endif], [acl("foo", GETACLCNT, 0, NULL);
3005	],
3006	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SOLARIS_ACL),
3007	AC_MSG_RESULT(no))
3008
3009AC_MSG_CHECKING(for AIX ACL support)
3010AC_TRY_LINK([
3011#if STDC_HEADERS
3012# include <stdlib.h>
3013# include <stddef.h>
3014#endif
3015#ifdef HAVE_SYS_ACL_H
3016# include <sys/acl.h>
3017#endif
3018#ifdef HAVE_SYS_ACCESS_H
3019# include <sys/access.h>
3020#endif
3021#define _ALL_SOURCE
3022
3023#include <sys/stat.h>
3024
3025int aclsize;
3026struct acl *aclent;], [aclsize = sizeof(struct acl);
3027	aclent = (void *)malloc(aclsize);
3028	statacl("foo", STX_NORMAL, aclent, aclsize);
3029	],
3030	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_AIX_ACL),
3031	AC_MSG_RESULT(no))
3032else
3033  AC_MSG_RESULT(yes)
3034fi
3035
3036AC_MSG_CHECKING(--disable-gpm argument)
3037AC_ARG_ENABLE(gpm,
3038	[  --disable-gpm           Don't use gpm (Linux mouse daemon).], ,
3039	[enable_gpm="yes"])
3040
3041if test "$enable_gpm" = "yes"; then
3042  AC_MSG_RESULT(no)
3043  dnl Checking if gpm support can be compiled
3044  AC_CACHE_CHECK([for gpm], vi_cv_have_gpm,
3045	[olibs="$LIBS" ; LIBS="-lgpm"]
3046	AC_TRY_LINK(
3047	    [#include <gpm.h>
3048	    #include <linux/keyboard.h>],
3049	    [Gpm_GetLibVersion(NULL);],
3050	    dnl Configure defines HAVE_GPM, if it is defined feature.h defines
3051	    dnl FEAT_MOUSE_GPM if mouse support is included
3052	    [vi_cv_have_gpm=yes],
3053	    [vi_cv_have_gpm=no])
3054	[LIBS="$olibs"]
3055    )
3056  if test $vi_cv_have_gpm = yes; then
3057    LIBS="$LIBS -lgpm"
3058    AC_DEFINE(HAVE_GPM)
3059  fi
3060else
3061  AC_MSG_RESULT(yes)
3062fi
3063
3064AC_MSG_CHECKING(--disable-sysmouse argument)
3065AC_ARG_ENABLE(sysmouse,
3066	[  --disable-sysmouse    Don't use sysmouse (mouse in *BSD console).], ,
3067	[enable_sysmouse="yes"])
3068
3069if test "$enable_sysmouse" = "yes"; then
3070  AC_MSG_RESULT(no)
3071  dnl Checking if sysmouse support can be compiled
3072  dnl Configure defines HAVE_SYSMOUSE, if it is defined feature.h
3073  dnl defines FEAT_SYSMOUSE if mouse support is included
3074  AC_CACHE_CHECK([for sysmouse], vi_cv_have_sysmouse,
3075	AC_TRY_LINK(
3076	    [#include <sys/consio.h>
3077	     #include <signal.h>
3078	     #include <sys/fbio.h>],
3079	    [struct mouse_info   mouse;
3080	     mouse.operation = MOUSE_MODE;
3081	     mouse.operation = MOUSE_SHOW;
3082	     mouse.u.mode.mode = 0;
3083	     mouse.u.mode.signal = SIGUSR2;],
3084	    [vi_cv_have_sysmouse=yes],
3085	    [vi_cv_have_sysmouse=no])
3086    )
3087  if test $vi_cv_have_sysmouse = yes; then
3088    AC_DEFINE(HAVE_SYSMOUSE)
3089  fi
3090else
3091  AC_MSG_RESULT(yes)
3092fi
3093
3094dnl make sure the FD_CLOEXEC flag for fcntl()'s F_SETFD command is known
3095AC_MSG_CHECKING(for FD_CLOEXEC)
3096AC_TRY_COMPILE(
3097[#if HAVE_FCNTL_H
3098# include <fcntl.h>
3099#endif],
3100[	int flag = FD_CLOEXEC;],
3101	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_FD_CLOEXEC),
3102	AC_MSG_RESULT(not usable))
3103
3104dnl rename needs to be checked separately to work on Nextstep with cc
3105AC_MSG_CHECKING(for rename)
3106AC_TRY_LINK([#include <stdio.h>], [rename("this", "that")],
3107	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_RENAME),
3108	AC_MSG_RESULT(no))
3109
3110dnl sysctl() may exist but not the arguments we use
3111AC_MSG_CHECKING(for sysctl)
3112AC_TRY_COMPILE(
3113[#include <sys/types.h>
3114#include <sys/sysctl.h>],
3115[	int mib[2], r;
3116	size_t len;
3117
3118	mib[0] = CTL_HW;
3119	mib[1] = HW_USERMEM;
3120	len = sizeof(r);
3121	(void)sysctl(mib, 2, &r, &len, (void *)0, (size_t)0);
3122	],
3123	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSCTL),
3124	AC_MSG_RESULT(not usable))
3125
3126dnl sysinfo() may exist but not be Linux compatible
3127AC_MSG_CHECKING(for sysinfo)
3128AC_TRY_COMPILE(
3129[#include <sys/types.h>
3130#include <sys/sysinfo.h>],
3131[	struct sysinfo sinfo;
3132	int t;
3133
3134	(void)sysinfo(&sinfo);
3135	t = sinfo.totalram;
3136	],
3137	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSINFO),
3138	AC_MSG_RESULT(not usable))
3139
3140dnl struct sysinfo may have the mem_unit field or not
3141AC_MSG_CHECKING(for sysinfo.mem_unit)
3142AC_TRY_COMPILE(
3143[#include <sys/types.h>
3144#include <sys/sysinfo.h>],
3145[	struct sysinfo sinfo;
3146 	sinfo.mem_unit = 1;
3147	],
3148	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSINFO_MEM_UNIT),
3149	AC_MSG_RESULT(no))
3150
3151dnl sysconf() may exist but not support what we want to use
3152AC_MSG_CHECKING(for sysconf)
3153AC_TRY_COMPILE(
3154[#include <unistd.h>],
3155[	(void)sysconf(_SC_PAGESIZE);
3156	(void)sysconf(_SC_PHYS_PAGES);
3157	],
3158	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSCONF),
3159	AC_MSG_RESULT(not usable))
3160
3161AC_CHECK_SIZEOF([int])
3162AC_CHECK_SIZEOF([long])
3163AC_CHECK_SIZEOF([time_t])
3164AC_CHECK_SIZEOF([off_t])
3165
3166dnl Make sure that uint32_t is really 32 bits unsigned.
3167AC_MSG_CHECKING([uint32_t is 32 bits])
3168AC_TRY_RUN([
3169#ifdef HAVE_STDINT_H
3170# include <stdint.h>
3171#endif
3172#ifdef HAVE_INTTYPES_H
3173# include <inttypes.h>
3174#endif
3175main() {
3176  uint32_t nr1 = (uint32_t)-1;
3177  uint32_t nr2 = (uint32_t)0xffffffffUL;
3178  if (sizeof(uint32_t) != 4 || nr1 != 0xffffffffUL || nr2 + 1 != 0) exit(1);
3179  exit(0);
3180}],
3181AC_MSG_RESULT(ok),
3182AC_MSG_ERROR([WRONG!  uint32_t not defined correctly.]),
3183AC_MSG_ERROR([could not compile program using uint32_t.]))
3184
3185dnl Check for memmove() before bcopy(), makes memmove() be used when both are
3186dnl present, fixes problem with incompatibility between Solaris 2.4 and 2.5.
3187
3188[bcopy_test_prog='
3189#include "confdefs.h"
3190#ifdef HAVE_STRING_H
3191# include <string.h>
3192#endif
3193#if STDC_HEADERS
3194# include <stdlib.h>
3195# include <stddef.h>
3196#endif
3197main() {
3198  char buf[10];
3199  strcpy(buf, "abcdefghi");
3200  mch_memmove(buf, buf + 2, 3);
3201  if (strncmp(buf, "ababcf", 6))
3202    exit(1);
3203  strcpy(buf, "abcdefghi");
3204  mch_memmove(buf + 2, buf, 3);
3205  if (strncmp(buf, "cdedef", 6))
3206    exit(1);
3207  exit(0); /* libc version works properly.  */
3208}']
3209
3210AC_CACHE_CHECK([whether memmove handles overlaps],[vim_cv_memmove_handles_overlap],
3211  [
3212    AC_RUN_IFELSE([[#define mch_memmove(s,d,l) memmove(d,s,l) $bcopy_test_prog]],
3213      [
3214	vim_cv_memmove_handles_overlap=yes
3215      ],[
3216	vim_cv_memmove_handles_overlap=no
3217      ],[
3218	AC_MSG_ERROR(cross-compiling: please set 'vim_cv_memmove_handles_overlap')
3219      ])
3220  ])
3221
3222if test "x$vim_cv_memmove_handles_overlap" = "xyes" ; then
3223  AC_DEFINE(USEMEMMOVE)
3224else
3225  AC_CACHE_CHECK([whether bcopy handles overlaps],[vim_cv_bcopy_handles_overlap],
3226    [
3227      AC_RUN_IFELSE([[#define mch_bcopy(s,d,l) bcopy(d,s,l) $bcopy_test_prog]],
3228      [
3229	vim_cv_bcopy_handles_overlap=yes
3230      ],[
3231	vim_cv_bcopy_handles_overlap=no
3232      ],[
3233	AC_MSG_ERROR(cross-compiling: please set 'vim_cv_bcopy_handles_overlap')
3234      ])
3235    ])
3236
3237  if test "x$vim_cv_bcopy_handles_overlap" = "xyes" ; then
3238    AC_DEFINE(USEBCOPY)
3239  else
3240    AC_CACHE_CHECK([whether memcpy handles overlaps],[vim_cv_memcpy_handles_overlap],
3241      [
3242	AC_RUN_IFELSE([[#define mch_memcpy(s,d,l) memcpy(d,s,l) $bcopy_test_prog]],
3243	  [
3244	    vim_cv_memcpy_handles_overlap=yes
3245	  ],[
3246	    vim_cv_memcpy_handles_overlap=no
3247	  ],[
3248	    AC_MSG_ERROR(cross-compiling: please set 'vim_cv_memcpy_handles_overlap')
3249	  ])
3250      ])
3251
3252    if test "x$vim_cv_memcpy_handles_overlap" = "xyes" ; then
3253      AC_DEFINE(USEMEMCPY)
3254    fi
3255  fi
3256fi
3257
3258
3259dnl Check for multibyte locale functions
3260dnl Find out if _Xsetlocale() is supported by libX11.
3261dnl Check if X_LOCALE should be defined.
3262
3263if test "$enable_multibyte" = "yes"; then
3264  cflags_save=$CFLAGS
3265  ldflags_save=$LDFLAGS
3266  if test "x$x_includes" != "xNONE" ; then
3267    CFLAGS="$CFLAGS -I$x_includes"
3268    LDFLAGS="$X_LIBS $LDFLAGS -lX11"
3269    AC_MSG_CHECKING(whether X_LOCALE needed)
3270    AC_TRY_COMPILE([#include <X11/Xlocale.h>],,
3271	AC_TRY_LINK_FUNC([_Xsetlocale], [AC_MSG_RESULT(yes)
3272		AC_DEFINE(X_LOCALE)], AC_MSG_RESULT(no)),
3273	AC_MSG_RESULT(no))
3274  fi
3275  CFLAGS=$cflags_save
3276  LDFLAGS=$ldflags_save
3277fi
3278
3279dnl Link with xpg4, it is said to make Korean locale working
3280AC_CHECK_LIB(xpg4, _xpg4_setrunelocale, [LIBS="$LIBS -lxpg4"],,)
3281
3282dnl Check how we can run ctags.  Default to "ctags" when nothing works.
3283dnl --version for Exuberant ctags (preferred)
3284dnl       Add --fields=+S to get function signatures for omni completion.
3285dnl -t for typedefs (many ctags have this)
3286dnl -s for static functions (Elvis ctags only?)
3287dnl -v for variables. Dangerous, most ctags take this for 'vgrind style'.
3288dnl -i+m to test for older Exuberant ctags
3289AC_MSG_CHECKING(how to create tags)
3290test -f tags && mv tags tags.save
3291if (eval ctags --version /dev/null | grep Exuberant) < /dev/null 1>&AC_FD_CC 2>&1; then
3292  TAGPRG="ctags -I INIT+ --fields=+S"
3293else
3294  TAGPRG="ctags"
3295  (eval etags	   /dev/null) < /dev/null 1>&AC_FD_CC 2>&1 && TAGPRG="etags"
3296  (eval etags -c   /dev/null) < /dev/null 1>&AC_FD_CC 2>&1 && TAGPRG="etags -c"
3297  (eval ctags	   /dev/null) < /dev/null 1>&AC_FD_CC 2>&1 && TAGPRG="ctags"
3298  (eval ctags -t   /dev/null) < /dev/null 1>&AC_FD_CC 2>&1 && TAGPRG="ctags -t"
3299  (eval ctags -ts  /dev/null) < /dev/null 1>&AC_FD_CC 2>&1 && TAGPRG="ctags -ts"
3300  (eval ctags -tvs /dev/null) < /dev/null 1>&AC_FD_CC 2>&1 && TAGPRG="ctags -tvs"
3301  (eval ctags -i+m /dev/null) < /dev/null 1>&AC_FD_CC 2>&1 && TAGPRG="ctags -i+m"
3302fi
3303test -f tags.save && mv tags.save tags
3304AC_MSG_RESULT($TAGPRG) AC_SUBST(TAGPRG)
3305
3306dnl Check how we can run man with a section number
3307AC_MSG_CHECKING(how to run man with a section nr)
3308MANDEF="man"
3309(eval MANPAGER=cat PAGER=cat man -s 2 read) < /dev/null > /dev/null 2>&AC_FD_CC && MANDEF="man -s"
3310AC_MSG_RESULT($MANDEF)
3311if test "$MANDEF" = "man -s"; then
3312  AC_DEFINE(USEMAN_S)
3313fi
3314
3315dnl Check if gettext() is working and if it needs -lintl
3316AC_MSG_CHECKING(--disable-nls argument)
3317AC_ARG_ENABLE(nls,
3318	[  --disable-nls           Don't support NLS (gettext()).], ,
3319	[enable_nls="yes"])
3320
3321if test "$enable_nls" = "yes"; then
3322  AC_MSG_RESULT(no)
3323
3324  INSTALL_LANGS=install-languages
3325  AC_SUBST(INSTALL_LANGS)
3326  INSTALL_TOOL_LANGS=install-tool-languages
3327  AC_SUBST(INSTALL_TOOL_LANGS)
3328
3329  AC_CHECK_PROG(MSGFMT, msgfmt, msgfmt, )
3330  AC_MSG_CHECKING([for NLS])
3331  if test -f po/Makefile; then
3332    have_gettext="no"
3333    if test -n "$MSGFMT"; then
3334      AC_TRY_LINK(
3335	[#include <libintl.h>],
3336	[gettext("Test");],
3337	AC_MSG_RESULT([gettext() works]); have_gettext="yes",
3338	  olibs=$LIBS
3339	  LIBS="$LIBS -lintl"
3340	  AC_TRY_LINK(
3341	      [#include <libintl.h>],
3342	      [gettext("Test");],
3343	      AC_MSG_RESULT([gettext() works with -lintl]); have_gettext="yes",
3344	      AC_MSG_RESULT([gettext() doesn't work]);
3345	      LIBS=$olibs))
3346    else
3347      AC_MSG_RESULT([msgfmt not found - disabled]);
3348    fi
3349    if test $have_gettext = "yes"; then
3350      AC_DEFINE(HAVE_GETTEXT)
3351      MAKEMO=yes
3352      AC_SUBST(MAKEMO)
3353      dnl this was added in GNU gettext 0.10.36
3354      AC_CHECK_FUNCS(bind_textdomain_codeset)
3355      dnl _nl_msg_cat_cntr is required for GNU gettext
3356      AC_MSG_CHECKING([for _nl_msg_cat_cntr])
3357      AC_TRY_LINK(
3358		[#include <libintl.h>
3359		extern int _nl_msg_cat_cntr;],
3360		[++_nl_msg_cat_cntr;],
3361		AC_MSG_RESULT([yes]); AC_DEFINE(HAVE_NL_MSG_CAT_CNTR),
3362		AC_MSG_RESULT([no]))
3363    fi
3364  else
3365    AC_MSG_RESULT([no "po/Makefile" - disabled]);
3366  fi
3367else
3368  AC_MSG_RESULT(yes)
3369fi
3370
3371dnl Check for dynamic linking loader
3372AC_CHECK_HEADER(dlfcn.h, DLL=dlfcn.h, [AC_CHECK_HEADER(dl.h, DLL=dl.h)])
3373if test x${DLL} = xdlfcn.h; then
3374  AC_DEFINE(HAVE_DLFCN_H, 1, [ Define if we have dlfcn.h. ])
3375  AC_MSG_CHECKING([for dlopen()])
3376  AC_TRY_LINK(,[
3377		extern void* dlopen();
3378		dlopen();
3379      ],
3380      AC_MSG_RESULT(yes);
3381	      AC_DEFINE(HAVE_DLOPEN, 1, [ Define if we have dlopen() ]),
3382      AC_MSG_RESULT(no);
3383	      AC_MSG_CHECKING([for dlopen() in -ldl])
3384	      olibs=$LIBS
3385	      LIBS="$LIBS -ldl"
3386	      AC_TRY_LINK(,[
3387				extern void* dlopen();
3388				dlopen();
3389		 ],
3390		 AC_MSG_RESULT(yes);
3391			  AC_DEFINE(HAVE_DLOPEN, 1, [ Define if we have dlopen() ]),
3392		 AC_MSG_RESULT(no);
3393			  LIBS=$olibs))
3394  dnl ReliantUNIX has dlopen() in libc but everything else in libdl
3395  dnl ick :-)
3396  AC_MSG_CHECKING([for dlsym()])
3397  AC_TRY_LINK(,[
3398		extern void* dlsym();
3399		dlsym();
3400      ],
3401      AC_MSG_RESULT(yes);
3402	      AC_DEFINE(HAVE_DLSYM, 1, [ Define if we have dlsym() ]),
3403      AC_MSG_RESULT(no);
3404	      AC_MSG_CHECKING([for dlsym() in -ldl])
3405	      olibs=$LIBS
3406	      LIBS="$LIBS -ldl"
3407	      AC_TRY_LINK(,[
3408				extern void* dlsym();
3409				dlsym();
3410		 ],
3411		 AC_MSG_RESULT(yes);
3412			  AC_DEFINE(HAVE_DLSYM, 1, [ Define if we have dlsym() ]),
3413		 AC_MSG_RESULT(no);
3414			  LIBS=$olibs))
3415elif test x${DLL} = xdl.h; then
3416  AC_DEFINE(HAVE_DL_H, 1, [ Define if we have dl.h. ])
3417  AC_MSG_CHECKING([for shl_load()])
3418  AC_TRY_LINK(,[
3419		extern void* shl_load();
3420		shl_load();
3421     ],
3422     AC_MSG_RESULT(yes);
3423	  AC_DEFINE(HAVE_SHL_LOAD, 1, [ Define if we have shl_load() ]),
3424     AC_MSG_RESULT(no);
3425	  AC_MSG_CHECKING([for shl_load() in -ldld])
3426	  olibs=$LIBS
3427	  LIBS="$LIBS -ldld"
3428	  AC_TRY_LINK(,[
3429			extern void* shl_load();
3430			shl_load();
3431	     ],
3432	     AC_MSG_RESULT(yes);
3433		  AC_DEFINE(HAVE_SHL_LOAD, 1, [ Define if we have shl_load() ]),
3434	     AC_MSG_RESULT(no);
3435		  LIBS=$olibs))
3436fi
3437AC_CHECK_HEADERS(setjmp.h)
3438
3439if test "x$MACOSX" = "xyes" -a -n "$PERL"; then
3440  dnl -ldl must come after DynaLoader.a
3441  if echo $LIBS | grep -e '-ldl' >/dev/null; then
3442    LIBS=`echo $LIBS | sed s/-ldl//`
3443    PERL_LIBS="$PERL_LIBS -ldl"
3444  fi
3445fi
3446
3447if test "x$MACOSX" = "xyes"; then
3448  AC_MSG_CHECKING(whether we need -framework Cocoa)
3449  dnl Cocoa is needed with FEAT_CLIPBOARD or FEAT_MBYTE (the former is
3450  dnl disabled during tiny build)
3451  if test "x$features" != "xtiny" || test "x$enable_multibyte" = "xyes"; then
3452    LIBS=$"$LIBS -framework Cocoa"
3453    AC_MSG_RESULT(yes)
3454  else
3455    AC_MSG_RESULT(no)
3456  fi
3457fi
3458if test "x$MACARCH" = "xboth" && test "x$GUITYPE" = "xCARBONGUI"; then
3459  LDFLAGS="$LDFLAGS -isysroot $DEVELOPER_DIR/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
3460fi
3461
3462dnl gcc 3.1 changed the meaning of -MM.  The only solution appears to be to
3463dnl use "-isystem" instead of "-I" for all non-Vim include dirs.
3464dnl But only when making dependencies, cproto and lint don't take "-isystem".
3465dnl Mac gcc returns "powerpc-apple-darwin8-gcc-4.0.1 (GCC)...", need to allow
3466dnl the number before the version number.
3467DEPEND_CFLAGS_FILTER=
3468if test "$GCC" = yes; then
3469  AC_MSG_CHECKING(for GCC 3 or later)
3470  gccmajor=`echo "$gccversion" | sed -e 's/^\([[1-9]]\)\..*$/\1/g'`
3471  if test "$gccmajor" -gt "2"; then
3472    DEPEND_CFLAGS_FILTER="| sed 's+-I */+-isystem /+g'"
3473    AC_MSG_RESULT(yes)
3474  else
3475    AC_MSG_RESULT(no)
3476  fi
3477  dnl -D_FORTIFY_SOURCE=2 crashes Vim on strcpy(buf, "000") when buf is
3478  dnl declared as char x[1] but actually longer.  Introduced in gcc 4.0.
3479  dnl Also remove duplicate _FORTIFY_SOURCE arguments.
3480  AC_MSG_CHECKING(whether we need -D_FORTIFY_SOURCE=1)
3481  if test "$gccmajor" -gt "3"; then
3482    CFLAGS=`echo "$CFLAGS" | sed -e 's/-Wp,-D_FORTIFY_SOURCE=.//g' -e 's/-D_FORTIFY_SOURCE=.//g' -e 's/$/ -D_FORTIFY_SOURCE=1/'`
3483    AC_MSG_RESULT(yes)
3484  else
3485    AC_MSG_RESULT(no)
3486  fi
3487fi
3488AC_SUBST(DEPEND_CFLAGS_FILTER)
3489
3490dnl write output files
3491AC_OUTPUT(auto/config.mk:config.mk.in)
3492
3493dnl vim: set sw=2 tw=78 fo+=l:
3494