1###############################################################################
2# ConMan AutoConf Configuration
3#   Process this file with autoconf to produce a configure script.
4###############################################################################
5# Written by Chris Dunlap <cdunlap@llnl.gov>.
6# Copyright (C) 2007-2018 Lawrence Livermore National Security, LLC.
7# Copyright (C) 2001-2007 The Regents of the University of California.
8# UCRL-CODE-2002-009.
9#
10# This file is part of ConMan: The Console Manager.
11# For details, see <https://dun.github.io/conman/>.
12#
13# ConMan is free software: you can redistribute it and/or modify it under
14# the terms of the GNU General Public License as published by the Free
15# Software Foundation, either version 3 of the License, or (at your option)
16# any later version.
17#
18# ConMan is distributed in the hope that it will be useful, but WITHOUT
19# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21# for more details.
22#
23# You should have received a copy of the GNU General Public License along
24# with ConMan.  If not, see <http://www.gnu.org/licenses/>.
25###############################################################################
26
27
28dnl Prologue.
29dnl
30AC_INIT(common.h)
31AC_CONFIG_AUX_DIR(auxdir)
32AC_CONFIG_HEADER(config.h)
33
34
35dnl Read package and version info from VERSION.
36dnl
37PROJECT="`perl -ne 'print,exit if s/^\s*NAME:\s*(\S*).*/\1/i' $srcdir/META`"
38AC_DEFINE_UNQUOTED(PROJECT, "$PROJECT", [Define the project's name.])
39AC_SUBST(PROJECT)
40VERSION="`perl -ne 'print,exit if s/^\s*VERSION:\s*(\S*).*/\1/i' $srcdir/META`"
41AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Define the project's version.])
42AC_SUBST(VERSION)
43DATE="`perl -ne 'print,exit if s/^\s*DATE:\s*(\S*).*/\1/i' $srcdir/META`"
44test -z "$DATE" && DATE="`date +%Y-%m-%d`"
45AC_DEFINE_UNQUOTED(DATE, "$DATE", [Define the build date.])
46AC_SUBST(DATE)
47
48
49dnl Determine the system type.
50dnl
51AC_CANONICAL_HOST
52AC_SUBST(host_cpu)
53AC_DEFINE_UNQUOTED(HOST_CPU, "$host_cpu",
54  [Define the canonical host CPU type.]
55)
56AC_SUBST(host_os)
57AC_DEFINE_UNQUOTED(HOST_OS, "$host_os",
58  [Define the canonical host OS type.]
59)
60AC_SUBST(host_vendor)
61AC_DEFINE_UNQUOTED(HOST_VENDOR, "$host_vendor",
62  [Define the canonical host vendor type.]
63)
64
65
66dnl Check for programs.
67dnl
68AC_PROG_CC
69AC_PROG_INSTALL
70AC_PROG_LN_S
71AC_PROG_MAKE_SET
72AC_PROG_RANLIB
73
74
75dnl Check for libraries.
76dnl
77AC_CHECK_LIB(socket, socket)
78dnl
79dnl libnsl is only needed if libsocket is required; this test prevents it
80dnl   from being linked into the Linux executable when it is not needed.
81dnl
82if test "$ac_cv_lib_socket_socket" = yes; then
83  AC_CHECK_LIB(nsl, inet_addr)
84fi
85
86
87dnl Check for header files.
88dnl
89AC_CHECK_HEADERS( \
90  paths.h \
91  sys/inotify.h \
92)
93
94
95dnl Check for typedefs.
96dnl
97AC_CHECK_TYPES(socklen_t, [], [], [
98#include <sys/types.h>
99#include <sys/socket.h>])
100
101
102dnl Check for structures.
103dnl
104
105
106dnl Check for compiler characteristics.
107dnl
108AC_C_BIGENDIAN
109
110
111dnl Check for library functions.
112dnl
113AC_CHECK_FUNCS( \
114  inet_aton \
115  inet_ntop \
116  inet_pton \
117  localtime_r \
118  strcasecmp \
119  strncasecmp \
120  toint \
121)
122AC_REPLACE_FUNCS( \
123  strlcat \
124  strlcpy \
125)
126
127
128dnl Check for system services.
129dnl
130
131
132dnl Check for system-specific stuff.
133dnl
134
135
136dnl Check for broken <stdbool.h>.
137dnl
138AC_MSG_CHECKING(whether stdbool.h is broken)
139AC_COMPILE_IFELSE(AC_LANG_PROGRAM([#include <stdbool.h>]),
140  [ broken_stdbool=no ],
141  [ broken_stdbool=yes
142    AC_DEFINE(BROKEN_STDBOOL, 1,
143      [Define if your <stdbool.h> header file generates an error directive.])
144  ]
145)
146AC_MSG_RESULT(${broken_stdbool=no})
147
148
149dnl Check for debug vs. production compilation.
150dnl
151AC_MSG_CHECKING(whether debugging is enabled)
152AC_ARG_ENABLE(debug,
153  AS_HELP_STRING([--enable-debug], [enable debugging for development work]),
154  [ case "$enableval" in
155      yes) debug=yes ;;
156      no)  debug=no ;;
157      *)   AC_MSG_RESULT(doh!)
158           AC_MSG_ERROR([bad value "$enableval" for --enable-debug]) ;;
159    esac
160  ]
161)
162if test "$debug" = yes; then
163  test -z "$ac_test_CFLAGS" && CFLAGS=
164  test "$ac_cv_prog_cc_g" = yes && DEBUG_CFLAGS="-g"
165  test "$GCC" = yes && DEBUG_CFLAGS="$DEBUG_CFLAGS -Wall -Wsign-compare"
166else
167  AC_DEFINE(NDEBUG, 1, [Define if you are building a production release.])
168fi
169AC_SUBST(DEBUG_CFLAGS)
170AC_MSG_RESULT(${debug=no})
171
172
173dnl Check for Gray Watson's Debug Malloc Library <http://dmalloc.com/>.
174dnl
175AC_MSG_CHECKING(whether to use the Debug Malloc Library)
176AC_ARG_WITH(dmalloc,
177  AS_HELP_STRING([--with-dmalloc], [use Gray Watson's dmalloc library]),
178  [ case "$withval" in
179      yes) dmalloc=yes ;;
180      no)  dmalloc=no ;;
181      *)   AC_MSG_RESULT(doh!)
182           AC_MSG_ERROR([bad value "$withval" for --with-dmalloc]) ;;
183    esac
184  ]
185)
186AC_MSG_RESULT(${dmalloc=no})
187if test "$dmalloc" = yes; then
188  AC_HAVE_LIBRARY(dmalloc,
189    [ AC_DEFINE_UNQUOTED(WITH_DMALLOC, 1,
190        [Define if using the debug malloc library.]
191      )
192      LIBS="-ldmalloc $LIBS"
193    ], [dmalloc=no]
194  )
195fi
196dnl
197dnl Note that <stdlib.h> must be included before <dmalloc.h>.
198dnl Since it's ok to include it more than once, we do so here.
199dnl
200AH_BOTTOM(
201[#ifdef WITH_DMALLOC
202#  include <stdlib.h>
203#  include <dmalloc.h>
204#endif /* WITH_DMALLOC */]
205)
206
207
208dnl Check for TCP Wrappers.
209dnl
210AC_ARG_WITH(tcp-wrappers,
211  AS_HELP_STRING([--with-tcp-wrappers], [use Wietse Venema's TCP Wrappers]),
212  [ case "$withval" in
213      yes) tcp_wrappers=yes ;;
214      no)  tcp_wrappers=no ;;
215      *)   AC_MSG_RESULT(doh!)
216           AC_MSG_ERROR([bad value "$withval" for --with-tcp-wrappers]) ;;
217    esac
218  ]
219)
220if test "$tcp_wrappers" != no; then
221  AC_CHECK_HEADER(tcpd.h, ac_have_tcpd_h=yes)
222  AC_CHECK_LIB(wrap, main, ac_have_libwrap=yes)
223  if test "$ac_have_tcpd_h" = yes -a "$ac_have_libwrap" = yes; then
224    AC_DEFINE_UNQUOTED(WITH_TCP_WRAPPERS, 1, [Define if using TCP Wrappers.])
225    LIBS="-lwrap $LIBS"
226    tcp_wrappers=yes
227  else
228    tcp_wrappers=no
229  fi
230  dnl
231  dnl If libnsl is already getting linked, there's no reason to do it again.
232  dnl
233  if test "$tcp_wrappers" = yes -a "$ac_cv_lib_nsl_inet_addr" != yes; then
234    AC_CHECK_LIB(nsl, yp_get_default_domain)
235  fi
236fi
237AC_MSG_CHECKING(whether to use TCP Wrappers)
238AC_MSG_RESULT(${tcp_wrappers=no})
239
240
241dnl Check for FreeIPMI libraries
242dnl
243AC_ARG_WITH(freeipmi,
244  AS_HELP_STRING([--with-freeipmi], [use FreeIPMI's Serial-Over-LAN console]),
245  [ case "$withval" in
246      yes) freeipmi=req ;;
247      no)  freeipmi=no ;;
248      *)   AC_MSG_RESULT(doh!)
249           AC_MSG_ERROR([bad value "$withval" for --with-freeipmi]) ;;
250    esac
251  ]
252)
253dnl Require FreeIPMI 1.0.4 or later for fixed behavior in
254dnl ipmiconsole_engine_submit() as well as the various
255dnl ipmiconsole_FOO_is_valid() functions.
256dnl
257dnl Note that ipmiconsole_workaround_flags_is_valid() was added in 1.0.4.
258dnl
259if test "$freeipmi" != no; then
260  ac_save_LIBS="$LIBS"
261  AC_CHECK_HEADERS(ipmiconsole.h)
262  AC_CHECK_LIB(ipmiconsole, ipmiconsole_workaround_flags_is_valid)
263  LIBS="$ac_save_LIBS"
264  if   test "$ac_cv_header_ipmiconsole_h" != yes; then : ;
265  elif test "$ac_cv_lib_ipmiconsole_ipmiconsole_workaround_flags_is_valid" != yes; then : ;
266  else
267    AC_DEFINE_UNQUOTED(WITH_FREEIPMI, 1,
268      [Define if using FreeIPMI's libipmiconsole.])
269    freeipmi=yes
270    IPMI_OBJS="server-ipmi.o"
271    IPMI_LIBS="-lipmiconsole"
272  fi
273  test "$freeipmi" = req && freeipmi=failed
274fi
275AC_MSG_CHECKING(whether to use FreeIPMI's libipmiconsole)
276AC_MSG_RESULT(${freeipmi=no})
277if test "$freeipmi" = failed; then
278  AC_MSG_ERROR([unable to locate FreeIPMI 1.0.4 or later])
279fi
280AC_SUBST(IPMI_OBJS)
281AC_SUBST(IPMI_LIBS)
282
283
284dnl Check for ConMan daemon conf file.
285dnl Force a double shell-expansion of the CONF var.
286dnl
287CONMAN_CONF_TMP1="`eval echo ${sysconfdir}/conman.conf`"
288CONMAN_CONF_TMP2="`echo $CONMAN_CONF_TMP1 | sed 's/^NONE/$ac_default_prefix/'`"
289CONMAN_CONF="`eval echo $CONMAN_CONF_TMP2`"
290AC_DEFINE_UNQUOTED(CONMAN_CONF, ["$CONMAN_CONF"],
291  [Define the default configuration file of the ConMan daemon])
292AC_SUBST(CONMAN_CONF)
293
294
295dnl Check for ConMan daemon host name.
296dnl
297AC_MSG_CHECKING(for ConMan daemon host name)
298AC_ARG_WITH(conman-host,
299  AS_HELP_STRING([--with-conman-host=HOST],
300    [default host name of daemon [127.0.0.1]]),
301  [ if test -n "$withval" -a "$withval" != yes -a "$withval" != no; then
302      CONMAN_HOST="$withval"
303    fi
304  ]
305)
306AC_MSG_RESULT(${CONMAN_HOST=127.0.0.1})
307AC_DEFINE_UNQUOTED(CONMAN_HOST, "$CONMAN_HOST",
308  [Define the default host name or IP address of the ConMan daemon])
309AC_SUBST(CONMAN_HOST)
310
311
312dnl Check for ConMan daemon port number.
313dnl
314AC_MSG_CHECKING(for ConMan daemon port number)
315AC_ARG_WITH(conman-port,
316  AS_HELP_STRING([--with-conman-port=PORT],
317    [default port number of daemon [7890]]),
318  [ if test `expr match "$withval" '[[0-9]]*$'` -gt 0; then
319      CONMAN_PORT="$withval"
320    fi
321  ]
322)
323AC_MSG_RESULT(${CONMAN_PORT=7890})
324AC_DEFINE_UNQUOTED(CONMAN_PORT, "$CONMAN_PORT",
325  [Define the default port number of the ConMan daemon])
326AC_SUBST(CONMAN_PORT)
327
328
329dnl Check how to link against Pthreads.
330dnl
331AC_MSG_CHECKING([how to link against pthreads])
332LIBPTHREAD=""
333ac_check_pthreads_libs_save="$LIBS"
334for flag in -lpthread -pthread; do
335  LIBS="$flag"
336  AC_LINK_IFELSE([
337    AC_LANG_PROGRAM(
338      [[#include <pthread.h>]],
339      [[pthread_join (0, 0);]]
340    )],
341    [ac_check_pthreads_libs="$flag"; break],
342    [ac_check_pthreads_libs=FAILED]
343  )
344done
345LIBS="$ac_check_pthreads_libs_save"
346AC_MSG_RESULT($ac_check_pthreads_libs)
347if test "$ac_check_pthreads_libs" = "FAILED"; then
348  AC_MSG_FAILURE([cannot link against pthreads])
349fi
350LIBPTHREAD="$ac_check_pthreads_libs"
351AC_SUBST(LIBPTHREAD)
352dnl
353AC_DEFINE([_REENTRANT], [1],
354  [Define to 1 if you plan to link against multithreaded code.]
355)
356AC_DEFINE([_THREAD_SAFE], [1],
357  [Define to 1 if you plan to link against multithreaded code.]
358)
359AC_DEFINE([WITH_PTHREADS], [1],
360  [Define to 1 if using Pthreads.]
361)
362
363
364dnl Check for random silliness.
365dnl
366AC_CACHE_CHECK([for a sense of humor], ac_cv_humor, ac_cv_humor=yes)
367
368
369dnl Epilogue.
370dnl
371AC_OUTPUT_COMMANDS(echo "creating dependencies"; make depend >/dev/null)
372AC_OUTPUT([
373  Makefile
374  etc/conman.init
375  man/conman.1
376  man/conman.conf.5
377  man/conmand.8
378])
379