1# configure.ac 2 3AC_INIT([tmux], 3.1c) 4AC_PREREQ([2.60]) 5 6AC_CONFIG_AUX_DIR(etc) 7AC_CONFIG_LIBOBJ_DIR(compat) 8AM_INIT_AUTOMAKE([foreign subdir-objects]) 9 10AC_CANONICAL_HOST 11 12# When CFLAGS isn't set at this stage and gcc is detected by the macro below, 13# autoconf will automatically use CFLAGS="-O2 -g". Prevent that by using an 14# empty default. 15: ${CFLAGS=""} 16 17# Save user CPPFLAGS, CFLAGS and LDFLAGS. We need to change them because 18# AC_CHECK_HEADER doesn't give us any other way to update the include 19# paths. But for Makefile.am we want to use AM_CPPFLAGS and friends. 20SAVED_CFLAGS="$CFLAGS" 21SAVED_CPPFLAGS="$CPPFLAGS" 22SAVED_LDFLAGS="$LDFLAGS" 23 24# Set up the compiler in two different ways and say yes we may want to install. 25AC_PROG_CC 26AM_PROG_CC_C_O 27AC_PROG_CC_C99 28AC_PROG_CPP 29AC_PROG_EGREP 30AC_PROG_INSTALL 31AC_PROG_YACC 32PKG_PROG_PKG_CONFIG 33AC_USE_SYSTEM_EXTENSIONS 34 35# Default tmux.conf goes in /etc not ${prefix}/etc. 36test "$sysconfdir" = '${prefix}/etc' && sysconfdir=/etc 37 38# Is this --enable-debug? 39case "x$VERSION" in xnext*) enable_debug=yes;; esac 40AC_ARG_ENABLE( 41 debug, 42 AC_HELP_STRING(--enable-debug, enable debug build flags), 43) 44AM_CONDITIONAL(IS_DEBUG, test "x$enable_debug" = xyes) 45 46# Is this a static build? 47AC_ARG_ENABLE( 48 static, 49 AC_HELP_STRING(--enable-static, create a static build) 50) 51if test "x$enable_static" = xyes; then 52 test "x$PKG_CONFIG" != x && PKG_CONFIG="$PKG_CONFIG --static" 53 AM_LDFLAGS="-static $AM_LDFLAGS" 54 LDFLAGS="$AM_LDFLAGS $SAVED_LDFLAGS" 55fi 56 57# Is this gcc? 58AM_CONDITIONAL(IS_GCC, test "x$GCC" = xyes) 59 60# Is this Sun CC? 61AC_EGREP_CPP( 62 yes, 63 [ 64 #ifdef __SUNPRO_C 65 yes 66 #endif 67 ], 68 found_suncc=yes, 69 found_suncc=no 70) 71AM_CONDITIONAL(IS_SUNCC, test "x$found_suncc" = xyes) 72 73# Check for various headers. Alternatives included from compat.h. 74AC_CHECK_HEADERS([ \ 75 bitstring.h \ 76 dirent.h \ 77 fcntl.h \ 78 inttypes.h \ 79 libutil.h \ 80 ndir.h \ 81 paths.h \ 82 pty.h \ 83 stdint.h \ 84 sys/dir.h \ 85 sys/ndir.h \ 86 sys/tree.h \ 87 util.h \ 88]) 89 90# Look for library needed for flock. 91AC_SEARCH_LIBS(flock, bsd) 92 93# Check for functions that are replaced or omitted. 94AC_CHECK_FUNCS([ \ 95 dirfd \ 96 flock \ 97 prctl \ 98 sysconf \ 99]) 100 101# Check for functions with a compatibility implementation. 102AC_REPLACE_FUNCS([ \ 103 asprintf \ 104 cfmakeraw \ 105 closefrom \ 106 explicit_bzero \ 107 fgetln \ 108 freezero \ 109 getdtablecount \ 110 getprogname \ 111 memmem \ 112 recallocarray \ 113 reallocarray \ 114 setenv \ 115 setproctitle \ 116 strcasestr \ 117 strlcat \ 118 strlcpy \ 119 strndup \ 120 strsep \ 121 strtonum \ 122]) 123AC_FUNC_STRNLEN 124 125# Look for clock_gettime. Must come before event_init. 126AC_SEARCH_LIBS(clock_gettime, rt) 127 128# Always use our getopt because 1) glibc's doesn't enforce argument order 2) 129# musl does not set optarg to NULL for flags without arguments (although it is 130# not required to, but it is helpful) 3) there are probably other weird 131# implementations. 132AC_LIBOBJ(getopt) 133 134# Look for libevent. 135PKG_CHECK_MODULES( 136 LIBEVENT, 137 libevent, 138 [ 139 AM_CFLAGS="$LIBEVENT_CFLAGS $AM_CFLAGS" 140 CFLAGS="$AM_CFLAGS $SAVED_CFLAGS" 141 LIBS="$LIBEVENT_LIBS $LIBS" 142 found_libevent=yes 143 ], 144 [ 145 AC_SEARCH_LIBS( 146 event_init, 147 [event event-1.4 event2], 148 found_libevent=yes, 149 found_libevent=no 150 ) 151 ] 152) 153AC_CHECK_HEADER( 154 event.h, 155 , 156 found_libevent=no 157) 158if test "x$found_libevent" = xno; then 159 AC_MSG_ERROR("libevent not found") 160fi 161 162# Look for ncurses. 163PKG_CHECK_MODULES( 164 LIBTINFO, 165 tinfo, 166 found_ncurses=yes, 167 found_ncurses=no 168) 169if test "x$found_ncurses" = xno; then 170 PKG_CHECK_MODULES( 171 LIBNCURSES, 172 ncurses, 173 found_ncurses=yes, 174 found_ncurses=no 175 ) 176fi 177if test "x$found_ncurses" = xno; then 178 PKG_CHECK_MODULES( 179 LIBNCURSES, 180 ncursesw, 181 found_ncurses=yes, 182 found_ncurses=no 183 ) 184fi 185if test "x$found_ncurses" = xyes; then 186 AM_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $AM_CFLAGS" 187 CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $CFLAGS" 188 LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBS" 189else 190 # pkg-config didn't work, try ncurses. 191 AC_CHECK_LIB( 192 tinfo, 193 setupterm, 194 found_ncurses=yes, 195 found_ncurses=no 196 ) 197 if test "x$found_ncurses" = xno; then 198 AC_CHECK_LIB( 199 ncurses, 200 setupterm, 201 found_ncurses=yes, 202 found_ncurses=no 203 ) 204 fi 205 if test "x$found_ncurses" = xyes; then 206 AC_CHECK_HEADER( 207 ncurses.h, 208 LIBS="$LIBS -lncurses", 209 found_ncurses=no) 210 fi 211fi 212if test "x$found_ncurses" = xyes; then 213 AC_DEFINE(HAVE_NCURSES_H) 214else 215 # No ncurses, try curses. 216 AC_CHECK_LIB( 217 curses, 218 setupterm, 219 found_curses=yes, 220 found_curses=no 221 ) 222 AC_CHECK_HEADER( 223 curses.h, 224 , 225 found_curses=no) 226 if test "x$found_curses" = xyes; then 227 LIBS="$LIBS -lcurses" 228 AC_DEFINE(HAVE_CURSES_H) 229 else 230 AC_MSG_ERROR("curses not found") 231 fi 232fi 233 234# Look for utempter. 235AC_ARG_ENABLE( 236 utempter, 237 AC_HELP_STRING(--enable-utempter, use utempter if it is installed) 238) 239if test "x$enable_utempter" = xyes; then 240 AC_CHECK_HEADER(utempter.h, enable_utempter=yes, enable_utempter=no) 241 if test "x$enable_utempter" = xyes; then 242 AC_SEARCH_LIBS( 243 utempter_add_record, 244 utempter, 245 enable_utempter=yes, 246 enable_utempter=no 247 ) 248 fi 249 if test "x$enable_utempter" = xyes; then 250 AC_DEFINE(HAVE_UTEMPTER) 251 else 252 AC_MSG_ERROR("utempter not found") 253 fi 254fi 255 256# Look for utf8proc. 257AC_ARG_ENABLE( 258 utf8proc, 259 AC_HELP_STRING(--enable-utf8proc, use utf8proc if it is installed) 260) 261if test "x$enable_utf8proc" = xyes; then 262 AC_CHECK_HEADER(utf8proc.h, enable_utf8proc=yes, enable_utf8proc=no) 263 if test "x$enable_utf8proc" = xyes; then 264 AC_SEARCH_LIBS( 265 utf8proc_charwidth, 266 utf8proc, 267 enable_utf8proc=yes, 268 enable_utf8proc=no 269 ) 270 fi 271 if test "x$enable_utf8proc" = xyes; then 272 AC_DEFINE(HAVE_UTF8PROC) 273 else 274 AC_MSG_ERROR("utf8proc not found") 275 fi 276fi 277AM_CONDITIONAL(HAVE_UTF8PROC, [test "x$enable_utf8proc" = xyes]) 278 279# Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well. 280AC_MSG_CHECKING(for b64_ntop) 281AC_TRY_LINK( 282 [ 283 #include <sys/types.h> 284 #include <netinet/in.h> 285 #include <resolv.h> 286 ], 287 [b64_ntop(NULL, 0, NULL, 0);], 288 found_b64_ntop=yes, 289 found_b64_ntop=no 290) 291if test "x$found_b64_ntop" = xno; then 292 AC_MSG_RESULT(no) 293 294 AC_MSG_CHECKING(for b64_ntop with -lresolv) 295 OLD_LIBS="$LIBS" 296 LIBS="$LIBS -lresolv" 297 AC_TRY_LINK( 298 [ 299 #include <sys/types.h> 300 #include <netinet/in.h> 301 #include <resolv.h> 302 ], 303 [b64_ntop(NULL, 0, NULL, 0);], 304 found_b64_ntop=yes, 305 found_b64_ntop=no 306 ) 307 if test "x$found_b64_ntop" = xno; then 308 LIBS="$OLD_LIBS" 309 AC_MSG_RESULT(no) 310 fi 311fi 312if test "x$found_b64_ntop" = xyes; then 313 AC_DEFINE(HAVE_B64_NTOP) 314 AC_MSG_RESULT(yes) 315else 316 AC_LIBOBJ(base64) 317fi 318 319# Look for networking libraries. 320AC_SEARCH_LIBS(inet_ntoa, nsl) 321AC_SEARCH_LIBS(socket, socket) 322AC_CHECK_LIB(xnet, socket) 323 324# Check for CMSG_DATA. Some platforms require _XOPEN_SOURCE_EXTENDED (for 325# example see xopen_networking(7) on HP-UX). 326XOPEN_DEFINES= 327AC_MSG_CHECKING(for CMSG_DATA) 328AC_EGREP_CPP( 329 yes, 330 [ 331 #include <sys/socket.h> 332 #ifdef CMSG_DATA 333 yes 334 #endif 335 ], 336 found_cmsg_data=yes, 337 found_cmsg_data=no 338) 339AC_MSG_RESULT($found_cmsg_data) 340if test "x$found_cmsg_data" = xno; then 341 AC_MSG_CHECKING(if CMSG_DATA needs _XOPEN_SOURCE_EXTENDED) 342 AC_EGREP_CPP( 343 yes, 344 [ 345 #define _XOPEN_SOURCE 1 346 #define _XOPEN_SOURCE_EXTENDED 1 347 #include <sys/socket.h> 348 #ifdef CMSG_DATA 349 yes 350 #endif 351 ], 352 found_cmsg_data=yes, 353 found_cmsg_data=no 354 ) 355 AC_MSG_RESULT($found_cmsg_data) 356 if test "x$found_cmsg_data" = xyes; then 357 XOPEN_DEFINES="-D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED" 358 else 359 AC_MSG_ERROR("CMSG_DATA not found") 360 fi 361fi 362AC_SUBST(XOPEN_DEFINES) 363 364# Look for err and friends in err.h. 365AC_CHECK_FUNC(err, found_err_h=yes, found_err_h=no) 366AC_CHECK_FUNC(errx, , found_err_h=no) 367AC_CHECK_FUNC(warn, , found_err_h=no) 368AC_CHECK_FUNC(warnx, , found_err_h=no) 369if test "x$found_err_h" = xyes; then 370 AC_CHECK_HEADER(err.h, , found_err_h=no) 371else 372 AC_LIBOBJ(err) 373fi 374 375# Look for imsg_init in libutil. 376AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no) 377if test "x$found_imsg_init" = xyes; then 378 AC_DEFINE(HAVE_IMSG) 379else 380 AC_LIBOBJ(imsg) 381 AC_LIBOBJ(imsg-buffer) 382fi 383 384# Look for daemon, compat/daemon.c used if missing. Solaris 10 has it in 385# libresolv, but no declaration anywhere, so check for declaration as well as 386# function. 387AC_CHECK_FUNC(daemon, found_daemon=yes, found_daemon=no) 388AC_CHECK_DECL( 389 daemon, 390 , 391 found_daemon=no, 392 [ 393 #include <stdlib.h> 394 #include <unistd.h> 395 ] 396) 397if test "x$found_daemon" = xyes; then 398 AC_DEFINE(HAVE_DAEMON) 399else 400 AC_LIBOBJ(daemon) 401fi 402 403# Look for stravis, compat/{vis,unvis}.c used if missing. 404AC_CHECK_FUNC(stravis, found_stravis=yes, found_stravis=no) 405if test "x$found_stravis" = xyes; then 406 AC_MSG_CHECKING(if strnvis is broken) 407 AC_EGREP_HEADER([strnvis\(char \*, const char \*, size_t, int\)], 408 vis.h, 409 AC_MSG_RESULT(no), 410 [found_stravis=no]) 411 if test "x$found_stravis" = xno; then 412 AC_MSG_RESULT(yes) 413 fi 414fi 415if test "x$found_stravis" = xyes; then 416 AC_CHECK_DECL( 417 VIS_DQ, 418 , 419 found_stravis=no, 420 [ 421 #include <stdlib.h> 422 #include <vis.h> 423 ] 424) 425fi 426if test "x$found_stravis" = xyes; then 427 AC_DEFINE(HAVE_VIS) 428else 429 AC_LIBOBJ(vis) 430 AC_LIBOBJ(unvis) 431fi 432 433# Look for fdforkpty and forkpty in libutil. 434AC_SEARCH_LIBS(fdforkpty, util, found_fdforkpty=yes, found_fdforkpty=no) 435if test "x$found_fdforkpty" = xyes; then 436 AC_DEFINE(HAVE_FDFORKPTY) 437else 438 AC_LIBOBJ(fdforkpty) 439fi 440AC_SEARCH_LIBS(forkpty, util, found_forkpty=yes, found_forkpty=no) 441if test "x$found_forkpty" = xyes; then 442 AC_DEFINE(HAVE_FORKPTY) 443fi 444AM_CONDITIONAL(NEED_FORKPTY, test "x$found_forkpty" = xno) 445 446# Look for kinfo_getfile in libutil. 447AC_SEARCH_LIBS(kinfo_getfile, [util util-freebsd]) 448 449# Look for a suitable queue.h. 450AC_CHECK_DECL( 451 TAILQ_CONCAT, 452 found_queue_h=yes, 453 found_queue_h=no, 454 [#include <sys/queue.h>] 455) 456AC_CHECK_DECL( 457 TAILQ_PREV, 458 found_queue_h=yes, 459 found_queue_h=no, 460 [#include <sys/queue.h>] 461) 462AC_CHECK_DECL( 463 TAILQ_REPLACE, 464 , 465 found_queue_h=no, 466 [#include <sys/queue.h>] 467) 468if test "x$found_queue_h" = xyes; then 469 AC_DEFINE(HAVE_QUEUE_H) 470fi 471 472# Look for __progname. 473AC_MSG_CHECKING(for __progname) 474AC_LINK_IFELSE([AC_LANG_SOURCE( 475 [ 476 #include <stdio.h> 477 #include <stdlib.h> 478 extern char *__progname; 479 int main(void) { 480 const char *cp = __progname; 481 printf("%s\n", cp); 482 exit(0); 483 } 484 ])], 485 [AC_DEFINE(HAVE___PROGNAME) AC_MSG_RESULT(yes)], 486 AC_MSG_RESULT(no) 487) 488 489# Look for program_invocation_short_name. 490AC_MSG_CHECKING(for program_invocation_short_name) 491AC_LINK_IFELSE([AC_LANG_SOURCE( 492 [ 493 #include <errno.h> 494 #include <stdio.h> 495 #include <stdlib.h> 496 int main(void) { 497 const char *cp = program_invocation_short_name; 498 printf("%s\n", cp); 499 exit(0); 500 } 501 ])], 502 [AC_DEFINE(HAVE_PROGRAM_INVOCATION_SHORT_NAME) AC_MSG_RESULT(yes)], 503 AC_MSG_RESULT(no) 504) 505 506# Look for prctl(PR_SET_NAME). 507AC_CHECK_DECL( 508 PR_SET_NAME, 509 AC_DEFINE(HAVE_PR_SET_NAME), 510 , 511 [#include <sys/prctl.h>] 512) 513 514# Look for fcntl(F_CLOSEM). 515AC_CHECK_DECL( 516 F_CLOSEM, 517 AC_DEFINE(HAVE_FCNTL_CLOSEM), 518 , 519 [#include <fcntl.h>] 520) 521 522# Look for /proc/$$. 523AC_MSG_CHECKING(for /proc/\$\$) 524if test -d /proc/$$; then 525 AC_DEFINE(HAVE_PROC_PID) 526 AC_MSG_RESULT(yes) 527else 528 AC_MSG_RESULT(no) 529fi 530 531# Man page defaults to mdoc. 532MANFORMAT=mdoc 533AC_SUBST(MANFORMAT) 534 535# Figure out the platform. 536AC_MSG_CHECKING(platform) 537case "$host_os" in 538 *aix*) 539 AC_MSG_RESULT(aix) 540 PLATFORM=aix 541 ;; 542 *darwin*) 543 AC_MSG_RESULT(darwin) 544 PLATFORM=darwin 545 # 546 # OS X CMSG_FIRSTHDR is broken, so redefine it with a working 547 # one. daemon works but has some stupid side effects, so use 548 # our internal version which has a workaround. 549 # 550 AC_DEFINE(BROKEN_CMSG_FIRSTHDR) 551 AC_LIBOBJ(daemon) 552 AC_LIBOBJ(daemon-darwin) 553 ;; 554 *dragonfly*) 555 AC_MSG_RESULT(dragonfly) 556 PLATFORM=dragonfly 557 ;; 558 *linux*) 559 AC_MSG_RESULT(linux) 560 PLATFORM=linux 561 ;; 562 *freebsd*) 563 AC_MSG_RESULT(freebsd) 564 PLATFORM=freebsd 565 ;; 566 *netbsd*) 567 AC_MSG_RESULT(netbsd) 568 PLATFORM=netbsd 569 ;; 570 *openbsd*) 571 AC_MSG_RESULT(openbsd) 572 PLATFORM=openbsd 573 ;; 574 *sunos*) 575 AC_MSG_RESULT(sunos) 576 PLATFORM=sunos 577 ;; 578 *solaris*) 579 AC_MSG_RESULT(sunos) 580 PLATFORM=sunos 581 case `/usr/bin/nroff --version 2>&1` in 582 *GNU*) 583 # Solaris 11.4 and later use GNU groff. 584 MANFORMAT=mdoc 585 ;; 586 *) 587 # Solaris 2.0 to 11.3 use AT&T nroff. 588 MANFORMAT=man 589 ;; 590 esac 591 ;; 592 *hpux*) 593 AC_MSG_RESULT(hpux) 594 PLATFORM=hpux 595 ;; 596 *cygwin*|*msys*) 597 AC_MSG_RESULT(cygwin) 598 PLATFORM=cygwin 599 ;; 600 *) 601 AC_MSG_RESULT(unknown) 602 PLATFORM=unknown 603 ;; 604esac 605AC_SUBST(PLATFORM) 606AM_CONDITIONAL(IS_AIX, test "x$PLATFORM" = xaix) 607AM_CONDITIONAL(IS_DARWIN, test "x$PLATFORM" = xdarwin) 608AM_CONDITIONAL(IS_DRAGONFLY, test "x$PLATFORM" = xdragonfly) 609AM_CONDITIONAL(IS_LINUX, test "x$PLATFORM" = xlinux) 610AM_CONDITIONAL(IS_FREEBSD, test "x$PLATFORM" = xfreebsd) 611AM_CONDITIONAL(IS_NETBSD, test "x$PLATFORM" = xnetbsd) 612AM_CONDITIONAL(IS_OPENBSD, test "x$PLATFORM" = xopenbsd) 613AM_CONDITIONAL(IS_SUNOS, test "x$PLATFORM" = xsunos) 614AM_CONDITIONAL(IS_HPUX, test "x$PLATFORM" = xhpux) 615AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown) 616 617# Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user 618# variables. 619AC_SUBST(AM_CPPFLAGS) 620CPPFLAGS="$SAVED_CPPFLAGS" 621AC_SUBST(AM_CFLAGS) 622CFLAGS="$SAVED_CFLAGS" 623AC_SUBST(AM_LDFLAGS) 624LDFLAGS="$SAVED_LDFLAGS" 625 626# autoconf should create a Makefile. 627AC_OUTPUT(Makefile) 628