1# Process this file with autoconf to produce a configure script. 2 3## 4# cdecl -- C gibberish translator 5# configure.ac 6# 7# Copyright (C) 2017-2021 Paul J. Lucas 8# 9# This program is free software: you can redistribute it and/or modify 10# it under the terms of the GNU General Public License as published by 11# the Free Software Foundation, either version 3 of the License, or 12# (at your option) any later version. 13# 14# This program is distributed in the hope that it will be useful, 15# but WITHOUT ANY WARRANTY; without even the implied warranty of 16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17# GNU General Public License for more details. 18# 19# You should have received a copy of the GNU General Public License 20# along with this program. If not, see <http://www.gnu.org/licenses/>. 21## 22 23AC_INIT([cdecl],[11.9],[https://github.com/paul-j-lucas/cdecl/issues],[],[https://github.com/paul-j-lucas/cdecl]) 24AC_CONFIG_MACRO_DIR([m4]) 25AM_INIT_AUTOMAKE([-Wall -Werror foreign]) 26AM_EXTRA_RECURSIVE_TARGETS([clean-coverage distclean-coverage]) 27 28# Testing feature: code coverage (disabled by default) 29AC_ARG_ENABLE([coverage], 30 AS_HELP_STRING([--enable-coverage], [enable code coverage]), 31 [], 32 [enable_coverage=no] 33) 34AS_IF([test x$enable_coverage = xyes], 35 # 36 # When code coverage is desired, we have to set CFLAGS so it doesn't include 37 # -O2 (so we can add -O0 later in src/Makefile.am) before AC_PROG_CC is 38 # called as directed by "Autconf 5.10.3: C Compiler Characteristics": 39 # 40 # If output variable CFLAGS was not already set, set it to -g -O2 for the 41 # GNU C compiler .... If your package does not like this default, then 42 # it is acceptable to insert the line ': ${CFLAGS=""}' after AC_INIT and 43 # before AC_PROG_CC to select an empty default instead. 44 # 45 # There's still more to do after AC_PROG_CC is called and sets $GCC. This is 46 # handed below in part 2. 47 # 48 [: ${CFLAGS=""}] 49) 50 51# Checks for programs. 52AC_LANG(C) 53AC_PROG_CC 54gl_EARLY 55AX_PROG_FLEX( 56 [AC_DEFINE([LEX], [flex], ["flex" found])], 57 AS_IF([test ! -f "$srcdir/src/lexer.c"], 58 [AC_MSG_ERROR([required program "flex" not found])]) 59) 60AX_PROG_BISON( 61 [AC_DEFINE([YACC], [bison], ["bison" found])], 62 AS_IF([test ! -f "$srcdir/src/parser.c"], 63 [AC_MSG_ERROR([required program "bison" not found])]) 64) 65AC_PROG_INSTALL 66AC_PROG_LN_S 67 68# External dependency: readline (enabled by default) 69AC_ARG_WITH([readline], 70 AS_HELP_STRING([--without-readline], [disable readline]), 71 [], 72 [with_readline=yes] 73) 74AS_IF([test x$with_readline != xno], 75 [ 76 AC_DEFINE([WITH_READLINE], [1], 77 [Define to 1 if readline support is enabled.]) 78 AS_IF([test x$withval != xyes], 79 [ 80 CPPFLAGS="-I${withval}/include ${CPPFLAGS}" 81 LDFLAGS="-L${withval}/lib ${LDFLAGS}" 82 ] 83 ) 84 ] 85) 86 87# Checks for libraries. 88 89# Checks for header files. 90AC_HEADER_ASSERT 91AC_CHECK_HEADERS([curses.h ncurses.h]) 92AC_CHECK_HEADERS([fnmatch.h]) 93AC_CHECK_HEADERS([getopt.h]) 94AC_HEADER_STDBOOL 95AC_CHECK_HEADERS([pwd.h]) 96AC_CHECK_HEADERS([sysexits.h]) 97AC_CHECK_HEADERS([readline/readline.h readline/history.h]) 98AC_CHECK_HEADERS([term.h], [], [], 99[#if defined(HAVE_CURSES_H) 100#include <curses.h> 101#elif defined(HAVE_NCURSES_H) 102#include <ncurses.h> 103#endif 104]) 105gl_INIT 106 107# Checks for typedefs, structures, and compiler characteristics. 108AC_C_INLINE 109AC_TYPE_SIZE_T 110AC_TYPE_SSIZE_T 111AC_TYPE_UINT32_T 112AC_TYPE_UINT64_T 113AC_CHECK_MEMBERS([struct passwd.pw_dir],[],[],[[#include <pwd.h>]]) 114PJL_COMPILE([__typeof__],[],[__typeof__(1) x __attribute((unused)) = 1;]) 115 116# Checks for library functions. 117AC_FUNC_REALLOC 118AC_CHECK_DECLS([rl_completion_matches],[],[], 119[#include <stdio.h> 120#include <readline/readline.h> 121]) 122AC_CHECK_DECLS([RL_PROMPT_START_IGNORE],[],[], 123[#include <stdio.h> 124#include <readline/readline.h> 125]) 126AC_CHECK_DECLS([rl_gnu_readline_p],[],[], 127[#include <stdio.h> 128#include <readline/readline.h> 129]) 130AC_CHECK_FUNCS([geteuid getpwuid fmemopen strsep]) 131AC_SEARCH_LIBS([endwin],[curses ncurses]) 132AC_SEARCH_LIBS([readline],[readline]) 133AC_SEARCH_LIBS([add_history],[readline history]) 134AC_SEARCH_LIBS([tigetnum],[curses ncurses tinfo]) 135 136# If readline wasn't disabled by the user, does it actually exist and is it a 137# proper readline? 138AS_IF([test x$with_readline != xno -a x$ac_cv_search_readline = xno], 139 [AC_MSG_ERROR([readline library not found; use --without-readline])] 140) 141 142# Program feature: cdecl-debug (enabled by default) 143AC_ARG_ENABLE([cdecl-debug], 144 AS_HELP_STRING([--disable-cdecl-debug], [disable cdecl debugging]), 145 [], 146 [enable_cdecl_debug=yes] 147) 148AS_IF([test x$enable_cdecl_debug = xyes], 149 [AC_DEFINE([ENABLE_CDECL_DEBUG], [1], 150 [Define to 1 if cdecl debugging is enabled.])] 151) 152 153# Program feature: term-size (enabled by default) 154AC_ARG_ENABLE([term-size], 155 AS_HELP_STRING([--disable-term-size], [disable terminal size]), 156 [], 157 [enable_term_size=yes] 158) 159AS_IF([test x$enable_term_size = xyes -a x$ac_cv_search_endwin = xno], 160 [AC_MSG_ERROR([curses library for term-size not found; use --disable-term-size])] 161) 162AS_IF([test x$enable_term_size = xyes], 163 [AC_DEFINE([ENABLE_TERM_SIZE], [1], 164 [Define to 1 if term-size is enabled.])] 165) 166 167# Testing feature: Address Sanitizer 168AC_ARG_ENABLE([address-sanitizer], 169 AS_HELP_STRING([--enable-address-sanitizer], 170 [enable Address Sanitizer for debugging]), 171 [], 172 [enable_address_sanitizer=no] 173) 174AS_IF([test x$enable_address_sanitizer = xyes], 175 [AC_DEFINE([ENABLE_ADDRESS_SANITIZER], [1], 176 [Define to 1 if Address Sanitizer is enabled.])] 177) 178 179# Program feature: Flex debug (disabled by default) 180AC_ARG_ENABLE([flex-debug], 181 AS_HELP_STRING([--enable-flex-debug], [enable Flex debugging]), 182 [], 183 [enable_flex_debug=no] 184) 185AS_IF([test x$enable_flex_debug = xyes], 186 [AC_DEFINE([ENABLE_FLEX_DEBUG], [1], 187 [Define to 1 if Flex debugging is enabled.])] 188) 189 190# Program feature: Bison debug (disabled by default) 191AC_ARG_ENABLE([bison-debug], 192 AS_HELP_STRING([--enable-bison-debug], [enable for Bison debugging]), 193 [], 194 [enable_bison_debug=no] 195) 196AS_IF([test x$enable_bison_debug = xyes], 197 [AC_DEFINE([YYDEBUG], [1], 198 [Define to 1 if Bison debugging is enabled.])] 199) 200 201# Testing feature: code coverage, part 2 202AS_IF([test x$enable_coverage = xyes], 203 [ 204 AS_IF([test x$GCC != xyes], 205 [AC_MSG_ERROR([gcc is required for code coverage])]) 206 AC_CHECK_TOOL([GCOV], [gcov], [gcov]) 207 AS_IF([test x$GCOV = "x:"], 208 [AC_MSG_ERROR([required program "gcov" for code coverage not found])]) 209 AC_CHECK_PROG([LCOV], [lcov], [lcov]) 210 AS_IF([test x$LCOV = x], 211 [AC_MSG_ERROR([required program "lcov" for code coverage not found])]) 212 AC_CHECK_PROG([GENHTML], [genhtml], [genhtml]) 213 AS_IF([test x$GENHTML = x], 214 [AC_MSG_ERROR([required program "genhtml" for code coverage not found])]) 215 AC_DEFINE([ENABLE_COVERAGE], [1], 216 [Define to 1 if code coverage is enabled.]) 217 ] 218) 219 220# Makefile conditionals. 221AM_CONDITIONAL([ENABLE_ADDRESS_SANITIZER], 222 [test x$enable_address_sanitizer = xyes]) 223AM_CONDITIONAL([ENABLE_CDECL_DEBUG], [test x$enable_cdecl_debug = xyes]) 224AM_CONDITIONAL([ENABLE_COVERAGE], [test x$enable_coverage = xyes]) 225AM_CONDITIONAL([ENABLE_BISON_DEBUG], [test x$enable_bison_debug = xyes]) 226AM_CONDITIONAL([ENABLE_FLEX_DEBUG], [test x$enable_flex_debug = xyes]) 227AM_CONDITIONAL([WITH_READLINE], [test x$with_readline != xno]) 228 229# Miscellaneous. 230AX_C___ATTRIBUTE__ 231 232# Compiler warnings. 233AX_CFLAGS_WARN_ALL 234AX_CHECK_COMPILE_FLAG([-Wcast-align], [CFLAGS="$CFLAGS -Wcast-align"], [], [-Werror]) 235AX_CHECK_COMPILE_FLAG([-Wcomma], [CFLAGS="$CFLAGS -Wcomma"], [], [-Werror]) 236AX_CHECK_COMPILE_FLAG([-Wconditional-type-mismatch], [CFLAGS="$CFLAGS -Wconditional-type-mismatch"], [], [-Werror]) 237AX_CHECK_COMPILE_FLAG([-Wconditional-uninitialized], [CFLAGS="$CFLAGS -Wconditional-uninitialized"], [], [-Werror]) 238AX_CHECK_COMPILE_FLAG([-Wconversion], [CFLAGS="$CFLAGS -Wconversion"], [], [-Werror]) 239AX_CHECK_COMPILE_FLAG([-Wextra], [CFLAGS="$CFLAGS -Wextra"], [], [-Werror]) 240AX_CHECK_COMPILE_FLAG([-Wfloat-equal], [CFLAGS="$CFLAGS -Wfloat-equal"], [], [-Werror]) 241AX_CHECK_COMPILE_FLAG([-Wfor-loop-analysis], [CFLAGS="$CFLAGS -Wfor-loop-analysis"], [], [-Werror]) 242AX_CHECK_COMPILE_FLAG([-Widiomatic-parentheses], [CFLAGS="$CFLAGS -Widiomatic-parentheses"], [], [-Werror]) 243AX_CHECK_COMPILE_FLAG([-Wimplicit-fallthrough], [CFLAGS="$CFLAGS -Wimplicit-fallthrough"], [], [-Werror]) 244AX_CHECK_COMPILE_FLAG([-Wlogical-op-parentheses], [CFLAGS="$CFLAGS -Wlogical-op-parentheses"], [], [-Werror]) 245AX_CHECK_COMPILE_FLAG([-Wnewline-eof], [CFLAGS="$CFLAGS -Wnewline-eof"], [], [-Werror]) 246AX_CHECK_COMPILE_FLAG([-Wredundant-decls], [CFLAGS="$CFLAGS -Wredundant-decls"], [], [-Werror]) 247AX_CHECK_COMPILE_FLAG([-Wshadow], [CFLAGS="$CFLAGS -Wshadow"], [], [-Werror]) 248AX_CHECK_COMPILE_FLAG([-Wshift-sign-overflow], [CFLAGS="$CFLAGS -Wshift-sign-overflow"], [], [-Werror]) 249AX_CHECK_COMPILE_FLAG([-Wsign-compare], [CFLAGS="$CFLAGS -Wsign-compare"], [], [-Werror]) 250AX_CHECK_COMPILE_FLAG([-Wsign-conversion], [CFLAGS="$CFLAGS -Wsign-conversion"], [], [-Werror]) 251AX_CHECK_COMPILE_FLAG([-Wsometimes-uninitialized], [CFLAGS="$CFLAGS -Wsometimes-uninitialized"], [], [-Werror]) 252AX_CHECK_COMPILE_FLAG([-Wstring-conversion], [CFLAGS="$CFLAGS -Wstring-conversion"], [], [-Werror]) 253AX_CHECK_COMPILE_FLAG([-Wuninitialized], [CFLAGS="$CFLAGS -Wuninitialized"], [], [-Werror]) 254AX_CHECK_COMPILE_FLAG([-Wunreachable-code-break], [CFLAGS="$CFLAGS -Wunreachable-code-break"], [], [-Werror]) 255AX_CHECK_COMPILE_FLAG([-Wunreachable-code], [CFLAGS="$CFLAGS -Wunreachable-code"], [], [-Werror]) 256AX_CHECK_COMPILE_FLAG([-Wunused], [CFLAGS="$CFLAGS -Wunused"], [], [-Werror]) 257AX_CHECK_COMPILE_FLAG([-Wwrite-strings], [CFLAGS="$CFLAGS -Wwrite-strings"], [], [-Werror]) 258 259# Generate files. 260AH_TOP([#ifndef cdecl_config_H 261#define cdecl_config_H]) 262AH_BOTTOM([#endif /* cdecl_config_H */]) 263AC_CONFIG_HEADERS([src/config.h]) 264AC_CONFIG_FILES([ 265 Makefile 266 lib/Makefile 267 src/Makefile 268 test/Makefile 269 man/Makefile 270 man/man1/Makefile 271]) 272AC_OUTPUT 273 274# vim:set et sw=2 ts=2: 275