llvm.org GIT mirror llvm / 8d8bdff
Target a minimal terminfo library rather than necessarily a full curses library for color support detection. This still will use a curses library if that is all we have available on the system. This change tries to use a smaller subset of the curses library, specifically the subset that is on some systems split off into a separate library. For example, if you install ncurses configured --with-tinfo, a 'libtinfo' is install that provides just the terminfo querying functionality. That library is now used instead of curses when it is available. This happens to fix a build error on systems with that library because when we tried to link ncurses into the binary, we didn't pull tinfo in as well. =] It should also provide an easy path for supporting the NetBSD libterminfo library, but as I don't have access to a NetBSD system I'm leaving adding that support to those folks. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188160 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 7 years ago
9 changed file(s) with 106 addition(s) and 86 deletion(s). Raw diff Collapse all Expand all
122122 set(LLVM_TARGET_ARCH "host"
123123 CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
124124
125 option(LLVM_ENABLE_CURSES "Use curses to detect terminal info if available." ON)
125 option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)
126126
127127 option(LLVM_ENABLE_THREADS "Use threads if available." ON)
128128
10711071 AC_DEFINE_UNQUOTED(BUG_REPORT_URL,"$withval",
10721072 [Bug report URL.])
10731073
1074 dnl --enable-curses: check whether the user wants to control use of curses:
1075 AC_ARG_ENABLE(curses,AS_HELP_STRING(
1076 [--enable-curses],
1077 [Use curses for querying terminal infomation if available (default is YES)]),
1074 dnl --enable-terminfo: check whether the user wants to control use of terminfo:
1075 AC_ARG_ENABLE(terminfo,AS_HELP_STRING(
1076 [--enable-terminfo],
1077 [Query the terminfo database if available (default is YES)]),
10781078 [case "$enableval" in
1079 yes) llvm_cv_enable_curses="yes" ;;
1080 no) llvm_cv_enable_curses="no" ;;
1081 *) AC_MSG_ERROR([Invalid setting for --enable-curses. Use "yes" or "no"]) ;;
1079 yes) llvm_cv_enable_terminfo="yes" ;;
1080 no) llvm_cv_enable_terminfo="no" ;;
1081 *) AC_MSG_ERROR([Invalid setting for --enable-terminfo. Use "yes" or "no"]) ;;
10821082 esac],
1083 llvm_cv_enable_curses="yes")
1083 llvm_cv_enable_terminfo="yes")
10841084
10851085 dnl --enable-libffi : check whether the user wants to turn off libffi:
10861086 AC_ARG_ENABLE(libffi,AS_HELP_STRING(
13891389 AC_SEARCH_LIBS(clock_gettime,rt)
13901390
13911391 dnl The curses library is optional; used for querying terminal info
1392 if test "$llvm_cv_enable_curses" = "yes" ; then
1392 if test "$llvm_cv_enable_terminfo" = "yes" ; then
13931393 dnl We need the has_color functionality in curses for it to be useful.
1394 AC_SEARCH_LIBS(has_colors,curses ncurses ncursesw,
1395 AC_DEFINE([HAVE_CURSES],[1],
1396 [Define if curses provides the has_color() function on this platform.]))
1394 AC_SEARCH_LIBS(setupterm,tinfo curses ncurses ncursesw,
1395 AC_DEFINE([HAVE_TERMINFO],[1],
1396 [Define if the setupterm() function is supported this platform.]))
13971397 fi
13981398
13991399 dnl libffi is optional; used to call external functions from the interpreter
15731573 fi
15741574
15751575 dnl Try to find a suitable curses header.
1576 if test "$llvm_cv_enable_curses" = "yes" ; then
1577 AC_CHECK_HEADERS([curses.h ncurses.h ncursesw.h ncurses/curses.h ncursesw/curses.h])
1576 if test "$llvm_cv_enable_terminfo" = "yes" ; then
1577 AC_CHECK_HEADERS([term.h curses.h ncurses.h ncursesw.h ncurses/curses.h ncursesw/curses.h])
15781578 fi
15791579
15801580 dnl Try to find ffi.h.
7373 check_include_file(mach/mach.h HAVE_MACH_MACH_H)
7474 check_include_file(mach-o/dyld.h HAVE_MACH_O_DYLD_H)
7575
76 check_include_file(term.h HAVE_TERM_H)
7677 check_include_file(curses.h HAVE_CURSES_H)
7778 check_include_file(ncurses.h HAVE_NCURSES_H)
7879 check_include_file(ncursesw.h HAVE_NCURSESW_H)
102103 else()
103104 set(HAVE_LIBZ 0)
104105 endif()
105 if(LLVM_ENABLE_CURSES)
106 check_library_exists(curses has_colors "" HAVE_CURSES)
107 if(NOT HAVE_CURSES)
108 check_library_exists(ncurses has_colors "" HAVE_NCURSES)
109 set(HAVE_CURSES ${HAVE_NCURSES})
110 if(NOT HAVE_CURSES)
111 check_library_exists(ncursesw has_colors "" HAVE_NCURSESW)
112 set(HAVE_CURSES ${HAVE_NCURSESW})
106 if(LLVM_ENABLE_TERMINFO AND
107 (HAVE_TERM_H OR HAVE_CURSES_H OR HAVE_NCURSES_H OR HAVE_NCURSESW_H OR
108 HAVE_NCURSES_CURSES_H OR HAVE_NCURSESW_CURSES_H))
109 set(HAVE_TERMINFO 0)
110 foreach(library tinfo curses ncurses ncursesw)
111 string(TOUPPER ${library} library_suffix)
112 check_library_exists(${library} setupterm "" HAVE_TERMINFO_${library_suffix})
113 if(HAVE_TERMINFO_${library_suffix})
114 set(HAVE_TERMINFO 1)
115 set(TERMINFO_LIBS "${library}")
116 break()
113117 endif()
114 endif()
115 else()
116 set(HAVE_CURSES 0)
118 endforeach()
119 else()
120 set(HAVE_TERMINFO 0)
117121 endif()
118122 endif()
119123
99 if( HAVE_LIBDL )
1010 set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
1111 endif()
12 if(LLVM_ENABLE_CURSES)
13 if(HAVE_NCURSESW)
14 set(system_libs ${system_libs} ncursesw)
15 elseif(HAVE_NCURSES)
16 set(system_libs ${system_libs} ncurses)
17 elseif(HAVE_CURSES)
18 set(system_libs ${system_libs} curses)
12 if(LLVM_ENABLE_TERMINFO)
13 if(HAVE_TERMINFO)
14 set(system_libs ${system_libs} ${TERMINFO_LIBS})
1915 endif()
2016 endif()
2117 if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD )
1919
2020 set(LLVM_TOOLS_BINARY_DIR @LLVM_TOOLS_BINARY_DIR@)
2121
22 set(LLVM_ENABLE_CURSES @LLVM_ENABLE_CURSES@)
22 set(LLVM_ENABLE_TERMINFO @LLVM_ENABLE_TERMINFO@)
2323
2424 set(LLVM_ENABLE_THREADS @LLVM_ENABLE_THREADS@)
2525
2929
3030 set(LLVM_ENABLE_PIC @LLVM_ENABLE_PIC@)
3131
32 set(HAVE_CURSES @HAVE_CURSES@)
33 set(HAVE_NCURSES @HAVE_NCURSES@)
34 set(HAVE_NCURSESW @HAVE_NCURSESW@)
32 set(HAVE_TERMINFO @HAVE_TERMINFO@)
33 set(TERMINFO_LIBS @TERMINFO_LIBS@)
3534 set(HAVE_LIBDL @HAVE_LIBDL@)
3635 set(HAVE_LIBPTHREAD @HAVE_LIBPTHREAD@)
3736 set(HAVE_LIBZ @HAVE_LIBZ@)
14521452 target1,target2,... (default=disable)
14531453 --enable-bindings Build specific language bindings:
14541454 all,auto,none,{binding-name} (default=auto)
1455 --enable-curses Use curses for querying terminal infomation if
1456 available (default is YES)
1455 --enable-terminfo Query the terminfo database if available (default is
1456 YES)
14571457 --enable-libffi Check for the presence of libffi (default is NO)
14581458 --enable-ltdl-install install libltdl
14591459
60056005 _ACEOF
60066006
60076007
6008 # Check whether --enable-curses was given.
6009 if test "${enable_curses+set}" = set; then
6010 enableval=$enable_curses; case "$enableval" in
6011 yes) llvm_cv_enable_curses="yes" ;;
6012 no) llvm_cv_enable_curses="no" ;;
6013 *) { { echo "$as_me:$LINENO: error: Invalid setting for --enable-curses. Use \"yes\" or \"no\"" >&5
6014 echo "$as_me: error: Invalid setting for --enable-curses. Use \"yes\" or \"no\"" >&2;}
6008 # Check whether --enable-terminfo was given.
6009 if test "${enable_terminfo+set}" = set; then
6010 enableval=$enable_terminfo; case "$enableval" in
6011 yes) llvm_cv_enable_terminfo="yes" ;;
6012 no) llvm_cv_enable_terminfo="no" ;;
6013 *) { { echo "$as_me:$LINENO: error: Invalid setting for --enable-terminfo. Use \"yes\" or \"no\"" >&5
6014 echo "$as_me: error: Invalid setting for --enable-terminfo. Use \"yes\" or \"no\"" >&2;}
60156015 { (exit 1); exit 1; }; } ;;
60166016 esac
60176017 else
6018 llvm_cv_enable_curses="yes"
6018 llvm_cv_enable_terminfo="yes"
60196019 fi
60206020
60216021
1226712267 fi
1226812268
1226912269
12270 if test "$llvm_cv_enable_curses" = "yes" ; then
12271 { echo "$as_me:$LINENO: checking for library containing has_colors" >&5
12272 echo $ECHO_N "checking for library containing has_colors... $ECHO_C" >&6; }
12273 if test "${ac_cv_search_has_colors+set}" = set; then
12270 if test "$llvm_cv_enable_terminfo" = "yes" ; then
12271 { echo "$as_me:$LINENO: checking for library containing setupterm" >&5
12272 echo $ECHO_N "checking for library containing setupterm... $ECHO_C" >&6; }
12273 if test "${ac_cv_search_setupterm+set}" = set; then
1227412274 echo $ECHO_N "(cached) $ECHO_C" >&6
1227512275 else
1227612276 ac_func_search_save_LIBS=$LIBS
1228712287 #ifdef __cplusplus
1228812288 extern "C"
1228912289 #endif
12290 char has_colors ();
12290 char setupterm ();
1229112291 int
1229212292 main ()
1229312293 {
12294 return has_colors ();
12294 return setupterm ();
1229512295 ;
1229612296 return 0;
1229712297 }
1229812298 _ACEOF
12299 for ac_lib in '' curses ncurses ncursesw; do
12299 for ac_lib in '' tinfo curses ncurses ncursesw; do
1230012300 if test -z "$ac_lib"; then
1230112301 ac_res="none required"
1230212302 else
1233712337 ac_status=$?
1233812338 echo "$as_me:$LINENO: \$? = $ac_status" >&5
1233912339 (exit $ac_status); }; }; then
12340 ac_cv_search_has_colors=$ac_res
12340 ac_cv_search_setupterm=$ac_res
1234112341 else
1234212342 echo "$as_me: failed program was:" >&5
1234312343 sed 's/^/| /' conftest.$ac_ext >&5
1234712347
1234812348 rm -f core conftest.err conftest.$ac_objext \
1234912349 conftest$ac_exeext
12350 if test "${ac_cv_search_has_colors+set}" = set; then
12350 if test "${ac_cv_search_setupterm+set}" = set; then
1235112351 break
1235212352 fi
1235312353 done
12354 if test "${ac_cv_search_has_colors+set}" = set; then
12354 if test "${ac_cv_search_setupterm+set}" = set; then
1235512355 :
1235612356 else
12357 ac_cv_search_has_colors=no
12357 ac_cv_search_setupterm=no
1235812358 fi
1235912359 rm conftest.$ac_ext
1236012360 LIBS=$ac_func_search_save_LIBS
1236112361 fi
12362 { echo "$as_me:$LINENO: result: $ac_cv_search_has_colors" >&5
12363 echo "${ECHO_T}$ac_cv_search_has_colors" >&6; }
12364 ac_res=$ac_cv_search_has_colors
12362 { echo "$as_me:$LINENO: result: $ac_cv_search_setupterm" >&5
12363 echo "${ECHO_T}$ac_cv_search_setupterm" >&6; }
12364 ac_res=$ac_cv_search_setupterm
1236512365 if test "$ac_res" != no; then
1236612366 test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
1236712367
1236812368 cat >>confdefs.h <<\_ACEOF
12369 #define HAVE_CURSES 1
12369 #define HAVE_TERMINFO 1
1237012370 _ACEOF
1237112371
1237212372 fi
1654216542
1654316543 fi
1654416544
16545 if test "$llvm_cv_enable_curses" = "yes" ; then
16546
16547
16548
16549
16550
16551 for ac_header in curses.h ncurses.h ncursesw.h ncurses/curses.h ncursesw/curses.h
16545 if test "$llvm_cv_enable_terminfo" = "yes" ; then
16546
16547
16548
16549
16550
16551
16552 for ac_header in term.h curses.h ncurses.h ncursesw.h ncurses/curses.h ncursesw/curses.h
1655216553 do
1655316554 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
1655416555 if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
4646
4747 /* Define to 1 if you have the `closedir' function. */
4848 #cmakedefine HAVE_CLOSEDIR ${HAVE_CLOSEDIR}
49
50 /* Define if curses provides the has_color() function on this platform. */
51 #cmakedefine HAVE_CURSES
5249
5350 /* Define to 1 if you have the header file. */
5451 #cmakedefine HAVE_CURSES_H
419416 /* Define to 1 if you have that is POSIX.1 compatible. */
420417 #cmakedefine HAVE_SYS_WAIT_H ${HAVE_SYS_WAIT_H}
421418
419 /* Define if the setupterm() function is supported this platform. */
420 #cmakedefine HAVE_TERMINFO ${HAVE_TERMINFO}
421
422422 /* Define to 1 if you have the header file. */
423423 #cmakedefine HAVE_TERMIOS_H ${HAVE_TERMIOS_H}
424
425 /* Define to 1 if you have the header file. */
426 #cmakedefine HAVE_TERM_H
424427
425428 /* Define if the neat program is available */
426429 #cmakedefine HAVE_TWOPI ${HAVE_TWOPI}
6767
6868 /* can use __crashreporter_info__ */
6969 #undef HAVE_CRASHREPORTER_INFO
70
71 /* Define if curses provides the has_color() function on this platform. */
72 #undef HAVE_CURSES
7370
7471 /* Define to 1 if you have the header file. */
7572 #undef HAVE_CURSES_H
454451 /* Define to 1 if you have that is POSIX.1 compatible. */
455452 #undef HAVE_SYS_WAIT_H
456453
454 /* Define if the setupterm() function is supported this platform. */
455 #undef HAVE_TERMINFO
456
457457 /* Define to 1 if you have the header file. */
458458 #undef HAVE_TERMIOS_H
459
460 /* Define to 1 if you have the header file. */
461 #undef HAVE_TERM_H
459462
460463 /* Define if the neat program is available */
461464 #undef HAVE_TWOPI
3737 # include
3838 #endif
3939
40 // See if we can use curses to detect information about a terminal when
41 // connected to one.
42 #ifdef HAVE_CURSES
40 // Pull in the headers we found to go with the terminfo reading library (tinfo,
41 // curses, whatever it may be). We have to pull in the 'curses.h' header as the
42 // SysV spec only provides certain values and defines from that header even
43 // though we work hard to not link against all of the curses implementation
44 // when avoidable.
45 #ifdef HAVE_TERMINFO
4346 # if defined(HAVE_CURSES_H)
4447 # include
4548 # elif defined(HAVE_NCURSES_H)
5053 # include
5154 # elif defined(HAVE_NCURSESW_CURSES_H)
5255 # include
53 # else
54 # error Have a curses library but unable to find a curses header!
5556 # endif
56 # include
57 # if defined(HAVE_TERM_H)
58 # include
59 # endif
5760 #endif
5861
5962 //===----------------------------------------------------------------------===//
266269 }
267270
268271 static bool terminalHasColors(int fd) {
269 #ifdef HAVE_CURSES
270 // First, acquire a global lock because the curses C routines are thread
271 // hostile.
272 #ifdef HAVE_TERMINFO
273 // First, acquire a global lock because these C routines are thread hostile.
272274 static sys::Mutex M;
273275 MutexGuard G(M);
274276
278280 // colors.
279281 return false;
280282
281 // Test whether the terminal as set up supports color output.
282 if (has_colors() == TRUE)
283 // Test whether the terminal as set up supports color output. How to do this
284 // isn't entirely obvious. We can use the curses routine 'has_colors' but it
285 // would be nice to avoid a dependency on curses proper when we can make do
286 // with a minimal terminfo parsing library. Also, we don't really care whether
287 // the terminal supports the curses-specific color changing routines, merely
288 // if it will interpret ANSI color escape codes in a reasonable way. Thus, the
289 // strategy here is just to query the baseline colors capability and if it
290 // supports colors at all to assume it will translate the escape codes into
291 // whatever range of colors it does support. We can add more detailed tests
292 // here if users report them as necessary.
293 //
294 // The 'tigetnum' routine returns -2 or -1 on errors, and might return 0 if
295 // the terminfo says that no colors are supported.
296 if (tigetnum("colors") > 0)
283297 return true;
284298 #endif
285299