UPS: apcupsd support with gui
[tomato.git] / release / src / router / apcupsd / autoconf / configure.in
blob2c162d45d76da3a4800dcb145559084e78546f08
1 dnl Autoconfigure input file for apcupsd (derived from fetchmail-4.7.4).
2 dnl
3 dnl Copyright (C) 1999-2000 Riccardo Facchetti <riccardo@master.oasi.gpa.it>
4 dnl
5 dnl Process this file with autoconf to produce a configure script.
6 dnl Process this file with autoheader to produce a config.h.in
7 dnl
9 dnl A distinctive file to look for in srcdir. 
10 AC_INIT(Developers)
12 dnl Config header file.
13 AC_CONFIG_HEADER(include/config.h:autoconf/config.h.in)
15 topdir=`pwd`
16 AC_CONFIG_AUX_DIR(${topdir}/autoconf)
18 dnl
19 dnl Absolute srcdir
20 ABSSRCDIR=`pwd`
21 AC_SUBST(ABSSRCDIR)
22 AC_SUBST(topdir)
24 dnl go up one more level
25 cd ..
26 TOP_DIR=`pwd`
27 cd ${topdir}
28 AC_SUBST(TOP_DIR)
30 VERSION=`sed -n -e 's/^.*VERSION.*"\(.*\)"$/\1/p' ${srcdir}/include/version.h`
31 AC_SUBST(VERSION)
33 DATE=`sed -n -e 's/^.*[ \t]*ADATE.*"\(.*\)"$/\1/p' ${srcdir}/include/version.h`
34 AC_SUBST(DATE)
36 dnl
37 dnl These need to be searched before.
38 dnl
39 AC_PATH_PROGS(TRUEPRG, true, :)
40 AC_PATH_PROGS(FALSEPRG, false, :)
42 dnl 
43 dnl Create a new path statement starting with what the user has and
44 dnl adding directories we might need.  
45 dnl
46 #PATH=$PATH:/bin:/sbin:/etc:/usr/bin:/usr/bin/X11:/usr/sbin:/usr/local/bin:/usr/local/sbin
47 #export PATH
50 dnl Interesting things are often in /usr/local
51 CPPFLAGS="${CPPFLAGS}"
52 LDFLAGS="${LDFLAGS}"
54 if test $HAVE_UNAME=yes -a x`uname -s` = xSunOS
55 then
56 dnl ----------------------------------------
57 dnl  SunOS defaults
58 dnl ----------------------------------------
59    AC_PREFIX_DEFAULT(/opt/apcupsd)
60 dnl --exec-prefix == eprefix == prefix
61 dnl --bindir == eprefix/bin
62 dnl --sbindir == eprefix/sbin
63 dnl
64 dnl If the user has not set -sysconfdir, we set our default as
65 dnl /etc/opt/apcupsd
66 dnl
67    if test x$sysconfdir = x'${prefix}/etc' ; then
68       sysconfdir='/etc/opt/apcupsd'
69    fi
70 dnl
71 dnl If the user has not set -sbindir, we set our default as /sbin
72 dnl
73    if test x$sbindir = x'${exec_prefix}/sbin' ; then
74       sbindir='/etc/opt/apcupsd/sbin'
75    fi
77    dnl Solaris often has interesting things in /usr/sfw
78    CPPFLAGS="${CPPFLAGS} -I/usr/sfw/include"
79    LDFLAGS="${LDFLAGS} -L/usr/sfw/lib"
80 else
81 dnl -------------------------------------------
82 dnl  non Sun defaults (i.e. all other platforms  
83 dnl -------------------------------------------
84    AC_PREFIX_DEFAULT(/usr)
85 dnl
86 dnl If the user has not set -sysconfdir, we set our default as /etc/apcupsd
87 dnl
88    if test x$sysconfdir = x'${prefix}/etc' ; then
89       sysconfdir='/etc/apcupsd'
90    fi
92 dnl
93 dnl If the user has not set -sbindir, we set our default as /sbin
94 dnl
95    if test x$sbindir = x'${exec_prefix}/sbin' ; then
96       sbindir='/sbin'
97    fi
101 dnl Sets `host_cpu', `host_vendor', and `host_os' to the current host type.
103 AC_CANONICAL_HOST
106 dnl Check for programs.
109 AC_PROG_CXX                dnl We require a C++ compiler now
110 AC_PROG_CC                 dnl Determine a C compiler to use.
111 AC_PROG_CPP                dnl Determine a C pre-processor to use.
112 AC_PROG_INSTALL            dnl Determine a BSD install program.
113 AC_PROG_AWK
114 AC_ISC_POSIX
116 if test x$GCC = xyes; then
117    AM_CONDITIONAL(HAVE_GCC, $TRUEPRG)
118    AC_DEFINE(HAVE_GCC)
119 else
120    AM_CONDITIONAL(HAVE_GCC, $FALSEPRG)
123 dnl Default linker is g++
124 #shibby
125 #if test x$LD = x ; then
126    LD="$CC"
129 AC_SUBST(DEBUG)
130 AC_SUBST(CFLAGS)
131 AC_SUBST(CPPFLAGS)
132 AC_SUBST(CXXFLAGS)
133 AC_SUBST(LDFLAGS)
134 AC_SUBST(LIBS)
135 AC_SUBST(DRVLIBS)
136 AC_SUBST(APCDRVLIBS)
138 dnl Initialize pthreads inclusion: warn PTHREAD_LFLAGS must contain only
139 dnl the pthreads libraries, if needed. For linker flags, add them to
140 dnl LDFLAGS.
141 PTHREAD_CFLAGS=""
142 PTHREAD_LFLAGS="-lpthread"
143 with_pthreads=yes
145 AC_DEFINE(HAVE_PTHREADS)
146 AC_SUBST(PTHREAD_CFLAGS)
147 AC_SUBST(PTHREAD_LFLAGS)
149 APCACCESS=apcaccess
150 SMTP=smtp
151 APCTEST=apctest
152 AC_SUBST(APCACCESS)
153 AC_SUBST(SMTP)
154 AC_SUBST(APCTEST)
156 dnl Now check for programs
157 AC_REQ_PATH_PROGS(SHUTDOWN, shutdown shutdown.bsd)
159 AC_PATH_PROGS(APCUPSD_MAIL, mail, no)
160 if test "$APCUPSD_MAIL" = "no"
161 then
162    AC_MSG_WARN([mail program not found !])
163    APCUPSD_MAIL=mail
165 dnl Arrmo, force APCUPSD_MAIL (mail command)
166 APCUPSD_MAIL="sendmail -S server.home -f root"
168 AC_REQ_PATH_PROGS(WALL, wall)
169 AC_REQ_PATH_PROGS(SCRIPTSHELL, sh bash)
171 AC_PROG_GMAKE
172 AC_REQ_PATH_PROGS(RANLIB, ranlib true)
173 AC_REQ_PATH_PROG(RM, rm)
174 AC_REQ_PATH_PROG(CP, cp)
175 AC_REQ_PATH_PROG(ECHO, echo)
176 AC_REQ_PATH_PROG(LN, ln)
177 AC_REQ_PATH_PROG(SED, sed)
178 AC_REQ_PATH_PROG(AR, ar)
179 AC_REQ_PATH_PROG(MV, mv)
181 AC_PATH_PROG(RST2HTML, rst2html.py,)
182 AC_PATH_PROG(RST2PDF, rst2pdf,)
184 # -------------------------------------------------------------------------
185 #  If the user has not set --mandir, we default to /usr/share/man
186 # -------------------------------------------------------------------------
187 if test x$mandir = x'${prefix}/man' ; then
188    mandir=/usr/share/man
192 dnl Check for library functions.
194 dnl for fopen and friends I check only for fprintf. If it is there I suppose
195 dnl all the other function should be there.
196 dnl The same for open and friends: checking only for open.
197 dnl and for all the other function groups.
199 AC_CHECK_FUNCS(
200    abort fork calloc getpid \
201    ioctl kill rewind select setsid signal strerror strncmp \
202    strncpy tcgetattr vfprintf setpgrp,,
203    [AC_MSG_ERROR([cannot find required function.])]
206 AC_CHECK_FUNCS(snprintf vsnprintf)
208 dnl Solaris hides nanosleep in one of two libraries depending on version
209 dnl If we can't find it at all we'll just use our own substitute.
210 AC_SEARCH_LIBS(nanosleep, [rt posix4], AC_DEFINE(HAVE_NANOSLEEP, 1,
211    [Define if you have the nanosleep function.]),
212    [LIBEXTRAOBJ="$LIBEXTRAOBJ sleep.o"
213     EXTRAOBJ="$EXTRAOBJ lib/sleep.o"])
215 AC_MSG_CHECKING([for syslog])
217 AC_TRY_LINK(
218    [#include <syslog.h>],
219    [syslog(0, "%s", "test");],
220    AC_MSG_RESULT([yes]),
221    AC_CHECK_LIB(socket, std_syslog,,
222       [AC_MSG_ERROR([cannot find required function.])])
223    AC_TRY_LINK(
224       [#include <syslog.h>],
225       [syslog(0, "%s", "test");], AC_MSG_RESULT([yes]),
226       [AC_MSG_ERROR([cannot find required function.])])
229 AC_FUNC_STRFTIME     dnl check for strftime.
230 dnl AC_FUNC_SETPGRP      dnl check for BSD setpgrp.
232 # Under sysV68, socket and friends are provided by the C library.
233 # -linet does not provide socket, but causes multiple definition
234 # errors at link-time.  It is thus better to only use the C library.
235 # So don't add -linet to the link list unless it's necessary
237 # With Solaris socket and friends seem not to be in C library.
238 # I hope that if socket is found, all the BSD friends are in the same library
240 # - RF
242 AC_SEARCH_LIBS(socket, [xnet socket inet])
243 AC_SEARCH_LIBS(gethostname, [xnet socket inet])
244 AC_SEARCH_LIBS(gethostbyname, [nsl resolv])
245 AC_SEARCH_LIBS(gethostbyname_r, [nsl resolv])
247 dnl --------------------------------------------------------------------------
248 dnl Check for socklen_t
249 dnl --------------------------------------------------------------------------
250 AC_CACHE_CHECK(for socklen_t, ba_cv_header_socklen_t,
251   [AC_TRY_COMPILE([
252 #include <sys/types.h>
253 #include <sys/socket.h>],
254   [socklen_t x],
255   ba_cv_header_socklen_t=yes, ba_cv_header_socklen_t=no)])
256 test $ba_cv_header_socklen_t = yes && AC_DEFINE(HAVE_SOCKLEN_T)
258 # The condition in this test copes with the presence of inet_addr in libc6.
259 AC_SEARCH_LIBS(inet_addr, nsl)
261 dnl Needed by Interactive UNIX System V/386 Release 3.2
262 AC_CHECK_FUNC(strchr,
263    AC_MSG_RESULT([using libc's strchr]),
264    AC_CHECK_LIB(cposix,strchr,
265    [EXTRADEFS="$EXTRADEFS -D_SYSV3"
266     LIBS="$LIBS -lcposix"]))
268 AC_CHECK_FUNC(strstr, AC_DEFINE(HAVE_STRSTR), 
269    [LIBEXTRAOBJ="$LIBEXTRAOBJ strstr.o"
270     EXTRAOBJ="$EXTRAOBJ lib/strstr.o"])
272 AC_CHECK_FUNC(strcasecmp, AC_DEFINE(HAVE_STRCASECMP), 
273    [LIBEXTRAOBJ="$LIBEXTRAOBJ strcasecmp.o"
274     EXTRAOBJ="$EXTRAOBJ lib/strcasecmp.o"])
275         
276 AC_CHECK_FUNC(memmove, AC_DEFINE(HAVE_MEMMOVE), 
277    [LIBEXTRAOBJ="$LIBEXTRAOBJ memmove.o"
278     EXTRAOBJ="$EXTRAOBJ lib/memmove.o"])
279         
280 AC_CHECK_FUNC(getopt_long, AC_DEFINE(HAVE_GETOPTLONG),
281    [LIBEXTRAOBJ="$LIBEXTRAOBJ getopt.o getopt1.o"
282     EXTRAOBJ="$EXTRAOBJ lib/getopt.o lib/getopt1.o"])
284 AC_CHECK_FUNC(inet_pton, AC_DEFINE(HAVE_INETPTON), 
285     [LIBEXTRAOBJ="$LIBEXTRAOBJ inet_pton.o"
286      EXTRAOBJ="$EXTRAOBJ lib/inet_pton.o"])
289 dnl Check for presence of localtime_r
291 AC_CHECK_FUNC(localtime_r, AC_DEFINE(HAVE_LOCALTIME_R),
292    [LIBEXTRAOBJ="$LIBEXTRAOBJ localtime_r.o"
293     EXTRAOBJ="$EXTRAOBJ lib/localtime_r.o"])
296 dnl   Check for header files.
298 AC_CHECK_HEADERS(
299    arpa/inet.h ctype.h errno.h fcntl.h \
300    limits.h netdb.h netinet/in.h pwd.h signal.h \
301    stdarg.h stdio.h stdlib.h string.h strings.h sys/ioctl.h \
302    sys/socket.h sys/types.h syslog.h termios.h \
303    unistd.h
304    ,,[AC_MSG_WARN([at least 1 header file is missing. This may not compile.])])
306 AC_CHECK_HEADERS(arpa/nameser.h,AC_DEFINE(HAVE_NAMESER_H))
308 AC_HEADER_STAT       dnl Check for S_ISDIR and S_ISREG macros.
309 AC_HEADER_TIME       dnl Check for time.h and sys/time.h.
310 AC_HEADER_SYS_WAIT      dnl Check for <sys/wait.h>
313 dnl   Check for structures.
315 AC_STRUCT_TM         dnl Check if time.h don't define struct tm.
316 AC_STRUCT_TIMEZONE      dnl Check how to have current timezone.
319 dnl Check for types.
321 AC_TYPE_GETGROUPS
322 AC_TYPE_MODE_T
323 AC_TYPE_OFF_T
324 AC_TYPE_PID_T
325 AC_TYPE_SIGNAL
326 AC_TYPE_SIZE_T
327 AC_TYPE_UID_T
328 AC_TYPE_SOCKETLEN_T
330 dnl Not always true, but close enough for the few platforms
331 dnl that are missing this (Solaris 2.5.1).
332 AC_CHECK_TYPE(int32_t, int)
335 dnl Check for system services.
337 AC_EXEEXT          dnl Check for EXE extension.
338 AC_PATH_XTRA       dnl Is X Window System interesting ?.  **GAPCMON**
339 AC_SYS_INTERPRETER dnl Check for '#!' in shell scripts.
342 dnl UNIX variants
344 AC_SUBST(EXEEXT)
345 AC_DEFINE_UNQUOTED(EXEEXT, "$EXEEXT")
347 case $host in
348    *-*-sunos*)   AC_DEFINE(HAVE_SUN_OS)     ;;
349    *-*-solaris*) AC_DEFINE(HAVE_SUN_OS)     ;;
350    *-*-osf*)     AC_DEFINE(HAVE_OSF1_OS)    ;;
351    *-*-aix*)     AC_DEFINE(HAVE_AIX_OS)     ;;
352    *-*-hpux*)    AC_DEFINE(HAVE_HPUX_OS)    ;;
353    *-*-linux*)   AC_DEFINE(HAVE_LINUX_OS)   ;;
354    *-*-freebsd*) AC_DEFINE(HAVE_FREEBSD_OS) ;;
355    *-*-netbsd*)  AC_DEFINE(HAVE_NETBSD_OS)  ;;
356    *-*-openbsd*) AC_DEFINE(HAVE_OPENBSD_OS) ;;
357    *-*-bsdi*)    AC_DEFINE(HAVE_BSDI_OS)    ;;
358    *-*-irix*)    AC_DEFINE(HAVE_SGI_OS)     ;;
359    *-*-darwin*)  AC_DEFINE(HAVE_DARWIN_OS)  ;;
360    *-*-nto*)     AC_DEFINE(HAVE_QNX_OS)     ;;
361 esac
364 dnl Check for enable particular features.
367 AC_ARG_ENABLE(all, [
368 AC_HELP_STRING([--enable-all], [Enable all optional modules])],
369    [ if test "$enableval" = "yes" ; then
370       enable_usb=yes
371       enable_net=yes
372       enable_snmp=yes
373       enable_net_snmp=yes
374       enable_test=yes
375       enable_pcnet=yes
376       enable_cgi=yes
377       enable_gapcmon=yes
378    fi], [])
381 dnl halpolicydir configuration
384 dnl Establish default
385 case $host in
386    *-*-linux*)
387       HALPOLICYDIR="/usr/share/hal/fdi/policy/20thirdparty"
388       ;;
389    *)
390       HALPOLICYDIR=""
391       ;;
392 esac
394 dnl Allow user override
395 AC_ARG_WITH(halpolicydir,
396    [AC_HELP_STRING([--with-halpolicydir=DIR], [HAL policy directory (default is platform dependent)])],
397    HALPOLICYDIR=$withval)
399 dnl Report result
400 if test "x$HALPOLICYDIR" != "x" ; then
401    AC_MSG_RESULT([Using halpolicydir=$HALPOLICYDIR])
402 else
403    AC_MSG_RESULT([Will not install HAL policy file])
405 AC_SUBST(HALPOLICYDIR)
407 #--------------------------------------------------------------------
408 # Check for TCP wrapper support, code taken from Bacula KES-7Nov03
409 #--------------------------------------------------------------------
411 AC_ARG_WITH(libwrap,
412    [AC_HELP_STRING([--with-libwrap=DIR], [Compile in libwrap (tcp_wrappers) support])],
413    [
414       if test "x$withval" != "xno" ; then
415          saved_LIBS="$LIBS"
416          LIBS="$saved_LIBS -lwrap"
417          AC_MSG_CHECKING([for libwrap])
418          AC_TRY_LINK(
419             [ #include <tcpd.h>
420               int deny_severity = 0;
421               int allow_severity = 0;
422               struct request_info *req; ],
423             [ hosts_access(req); ],
424             [ AC_MSG_RESULT([yes])
425               AC_DEFINE(HAVE_LIBWRAP)
426               TCPW_MSG="yes" ],
427             [ LIBS="$saved_LIBS -lwrap -lnsl"
428               AC_TRY_LINK(
429                  [ #include <tcpd.h>
430                    int deny_severity = 0;
431                    int allow_severity = 0;
432                    struct request_info *req; ],
433                  [ hosts_access(req); ],
434                  [ AC_MSG_RESULT([yes])
435                    AC_DEFINE(HAVE_LIBWRAP)
436                    TCPW_MSG="yes" ],
437                  [AC_MSG_ERROR([*** libwrap missing]) ] ]
438               )
439          )
440       fi
441    ]
445 dnl   
446 dnl Check for enable of cgi program builds
448 ENABLE_CGI="no"
449 CGI=
450 GD_LIBS=
451 SYS_GD_FOUND=no
452 SKIP_GDHDR_CHECK=no
453 AC_ARG_ENABLE(cgi,
454    [AC_HELP_STRING([--enable-cgi], [Compile CGI programs])],
455    [ if test "$enableval" = "yes"
456      then
457         ENABLE_CGI="yes"
458         CGI=cgi
460         dnl Check for GD Library check disable (disable called = "no")
461         AC_ARG_ENABLE(lgd,
462            [AC_HELP_STRING([--disable-lgd], [Disable GD Library])],
463            [ if test "$enableval" = "no"
464            then
465             AC_MSG_RESULT([Disabled GD Library (and associated checks).])
466             SKIP_GDHDR_CHECK=yes
467             SYS_GD_FOUND=yes
468            fi
469         ])
471         dnl
472         dnl First search for system library that defines gdImagePng
473         if test "${SYS_GD_FOUND}" = "no"
474         then
475             AC_CHECK_LIB(gd, gdImagePng,
476                [ AC_MSG_RESULT([using PNG file format (/usr/lib).])
477                  AC_DEFINE(SYS_IMGFMT_PNG)
478                  GD_LIBS="-lgd"
479                  SYS_GD_FOUND=yes ],
480                [],
481                [${X_LIBS}])
482         fi
484         dnl
485         dnl Second search for system library that defines gdImageGif
486         if test "${SYS_GD_FOUND}" = "no"
487         then
488            AC_CHECK_LIB(gd, gdImageGif,
489               [ AC_MSG_RESULT([using GIF file format (/usr/lib).])
490                 AC_DEFINE(SYS_IMGFMT_GIF)
491                 GD_LIBS="-lgd"
492                 SYS_GD_FOUND=yes ],
493               [],
494               [${X_LIBS}])
495         fi
497         dnl
498         dnl Third in /usr/local search for system library that defines gdImagePng
499         if test "${SYS_GD_FOUND}" = "no"
500         then
501            CPPFLAGS="${CPPFLAGS} -I/usr/local/include"
502            LDFLAGS="${LDFLAGS} -L/usr/local/lib"
504            dnl Destroy cached value
505            unset ac_cv_lib_gd_gdImagePng
506            AC_CHECK_LIB(gd, gdImagePng,
507               [ AC_MSG_RESULT([using PNG file format (/usr/local/lib).])
508                 AC_DEFINE(SYS_IMGFMT_PNG)
509                 GD_LIBS="-lgd"
510                 SYS_GD_FOUND=yes ],
511               [],
512               [${X_LIBS}])
513         fi
515         dnl
516         dnl Fourth in /usr/local search for system library that defines gdImageGif
517         if test "${SYS_GD_FOUND}" = "no"
518         then
519            dnl Destroy cached value
520            unset ac_cv_lib_gd_gdImageGif
521            AC_CHECK_LIB(gd, gdImageGif,
522               [ AC_MSG_RESULT([using GIF file format (/usr/local/lib).])
523                 AC_DEFINE(SYS_IMGFMT_GIF)
524                 GD_LIBS="-lgd"
525                 SYS_GD_FOUND=yes ],
526               [],
527               [${X_LIBS}])
528         fi
530         if test "${SYS_GD_FOUND}" = "no"
531         then
532            AC_MSG_ERROR([Your system lacks the GD library which is needed for
533                          compiling the apcupsd CGI programs. Please install 
534                          libgd and re-run the ./configure script.
535                          Alternatively you can disable the CGI support.])
536         fi
538         if test "${SKIP_GDHDR_CHECK}" = "no"
539         then
540             AC_CHECK_HEADER(gd.h, [ GDHEAD= ],
541                [ AC_CHECK_HEADER(gd/gd.h, [ GDHEAD="gd/" ],
542                   [ AC_CHECK_HEADER(gd2/gd.h, [ GDHEAD="gd2/" ],
543                      [ AC_MSG_ERROR([Found system GD library but no header file.
544                                      Please find the file gd.h in your system
545                                      include directories and report its location
546                                      to apcupsd-users@lists.sourceforge.net]) ])
547                   ])
548                ])
550              AC_SUBST(GDHEAD)
551         else
552             AC_MSG_RESULT([Not using GD Library - no check performed for header files.])
553         fi
554     fi
558 dnl   
559 dnl Check for enable of drivers
561 AC_ARG_ENABLE(apcsmart, [
562 AC_HELP_STRING([--enable-apcsmart], [Compile APC SmartUPS serial driver (default)])
563 AC_HELP_STRING([--disable-apcsmart], [No APC SmartUPS serial driver])],
564    [ if test "$enableval" = "yes" ; then
565        dnl This is for C code inclusion
566        AC_DEFINE(HAVE_APCSMART_DRIVER)
568        dnl This is for Makefile.in inside src/drivers/
569        APCSMART_DRIVER="apcsmart"
570        AC_SUBST(APCSMART_DRIVER)
571      fi ],
572    [ AC_DEFINE(HAVE_APCSMART_DRIVER)
573      APCSMART_DRIVER="apcsmart"
574      AC_SUBST(APCSMART_DRIVER) ])
576 AC_ARG_ENABLE(dumb, [
577 AC_HELP_STRING([--enable-dumb], [Compile dumb UPS driver (default)])
578 AC_HELP_STRING([--disable-dumb], [No dumb UPS driver])],
579    [ if test "$enableval" = "yes" ; then
580         AC_DEFINE(HAVE_DUMB_DRIVER)
581         DUMB_DRIVER="dumb"
582         AC_SUBST(DUMB_DRIVER)
583      fi],
584    [ AC_DEFINE(HAVE_DUMB_DRIVER)
585      DUMB_DRIVER="dumb"
586      AC_SUBST(DUMB_DRIVER) ])
588 dnl Allow user to force USB type to generic
589 GENERICUSB="no"
590 AC_ARG_WITH(generic-usb,
591 [AC_HELP_STRING([--with-generic-usb], [Force use of generic USB driver]) ],
592    [GENERICUSB="yes" ])
594 AC_ARG_ENABLE(usb, [
595 AC_HELP_STRING([--enable-usb], [Compile USB UPS code])
596 AC_HELP_STRING([--disable-usb], [No USB UPS code (default)])],
597    [ if test "$enableval" = "yes" ; then
598       dnl USB driver is usually determined by host system.
599       dnl But if user forces generic_usb then fake it out.
600       if test $GENERICUSB = "yes" ; then
601          usbhost=forcegeneric
602       else
603          usbhost=$host
604       fi
606       dnl Also force generic_usb if this is FreeBSD 8.0 or newer
607       case $usbhost in 
608          *-*-freebsd*)
609             tmp=`uname -r`
610             if test ${tmp%%.*} -ge 8 ; then
611                usbhost=forcegeneric
612             fi
613             ;;
614       esac
616       case $usbhost in
617          *-*-linux*)
618             USB_TYPE="linux"
619             AC_MSG_RESULT([Using Linux USB driver.])
620             ;;
621          *-*-freebsd* | *-*-openbsd* | *-*-netbsd*)
622             LIBUSBHIDINC="-I\$(topdir)/src/libusbhid"
623             LIBUSBHID=libusbhid
624             APCDRVLIBS="$APCDRVLIBS \$(topdir)/src/libusbhid/libusbhid.a"
625             AC_SUBST(LIBUSBHID)
626             AC_SUBST(LIBUSBHIDINC)
627             USB_TYPE="bsd"
628             AC_MSG_RESULT([Using BSD USB driver.])
629             ;;
630          *)
631             dnl Use libusb-config if found, otherwise fall back on AC_CHECK_LIB
632             AC_PATH_PROG(usbcfg, libusb-config)
633             if test x$usbcfg != x ; then
634                LIBUSB=`$usbcfg --libs`
635                LIBUSBH=`$usbcfg --prefix`/include/usb.h
636             else
637                AC_CHECK_LIB(usb, usb_init, 
638                             [LIBUSB=-lusb
639                              LIBUSBH=usb.h],
640                             [AC_MSG_ERROR(Unable to find libusb)], 
641                             [$DRVLIBS])
642             fi
644             AC_SUBST(LIBUSBH)
646             LIBUSBHIDINC="-I\$(topdir)/src/libusbhid"
647             LIBUSBHID=libusbhid
648             DRVLIBS="$DRVLIBS $LIBUSB"
649             APCDRVLIBS="$APCDRVLIBS \$(topdir)/src/libusbhid/libusbhid.a"
650             AC_SUBST(LIBUSBHID)
651             AC_SUBST(LIBUSBHIDINC)
652             USB_TYPE="generic"
653             AC_MSG_RESULT([Using generic libusb USB driver.])
654             ;;
655       esac
657       AC_DEFINE(HAVE_USB_DRIVER)
658       USB_DRIVER="usb"
659       AC_SUBST(USB_DRIVER)
660       AC_SUBST(USB_TYPE)
662       DISPLAY_USB_DRIVER=$USB_TYPE-$USB_DRIVER
663      fi ],
664     [])
666 AC_ARG_ENABLE(net, [
667 AC_HELP_STRING([--enable-net], [Compile networking driver for slaves (default)])
668 AC_HELP_STRING([--disable-net], [No network driver for slaves])],
669    [ if test "$enableval" = "yes" ; then
670         AC_DEFINE(HAVE_NET_DRIVER)
671         NET_DRIVER="net"
672         AC_SUBST(NET_DRIVER)
673      fi ],
674    [ AC_DEFINE(HAVE_NET_DRIVER)
675      NET_DRIVER="net"
676      AC_SUBST(NET_DRIVER) ])
678 AC_ARG_ENABLE(snmp, [
679 AC_HELP_STRING([--enable-snmp], [Compile SNMP driver (default)])
680 AC_HELP_STRING([--disable-snmp], [No SNMP driver])],
681    [ if test "$enableval" = "yes" ; then
682         AC_DEFINE(HAVE_SNMPLITE_DRIVER)
683         SNMPLITE_DRIVER="snmplite"
684         DISPLAY_SNMP_DRIVER="snmp"
685         AC_SUBST(SNMPLITE_DRIVER)        
686      fi ],
687    [ AC_DEFINE(HAVE_SNMPLITE_DRIVER)
688      SNMPLITE_DRIVER="snmplite"
689      DISPLAY_SNMP_DRIVER="snmp"
690      AC_SUBST(SNMPLITE_DRIVER) ])
692 AC_ARG_ENABLE(net-snmp, [
693 AC_HELP_STRING([--enable-net-snmp], [Compile NET-SNMP UPS code (OBSOLETE)])
694 AC_HELP_STRING([--disable-net-snmp], [No NET-SNMP UPS code (default)])],
695    [ if test "$enableval" = "yes" ; then
696         dnl Check for optional crypto lib
697         AC_CHECK_LIB(crypto, EVP_DigestInit,
698            [echo '   including crypto library for snmp.'
699             DRVLIBS="$DRVLIBS -lcrypto"],
700            [],
701            [])
703         SNMP_LIB_FOUND="no"
705         dnl libsnmp is often in /usr/local
706         CPPFLAGS="${CPPFLAGS} -I/usr/local/include"
707         LDFLAGS="${LDFLAGS} -L/usr/local/lib"
709         dnl Start by looking for libnetsnmp (net-snmp).
710         if test "$SNMP_LIB_FOUND" = "no" ; then
711            AC_CHECK_LIB(netsnmp, snmp_open,
712               [DRVLIBS="$DRVLIBS -lnetsnmp"
713                AC_DEFINE(HAVE_NET_SNMP)
714                SNMP_LIB_FOUND="yes"], [], [$DRVLIBS])
715         fi
717         dnl If no lib yet, fall back on libsnmp (ucd-snmp)
718         if test "$SNMP_LIB_FOUND" = "no" ; then
719            AC_CHECK_LIB(snmp, snmp_open,
720               [DRVLIBS="$DRVLIBS -lsnmp"
721                AC_DEFINE(HAVE_UCD_SNMP)
722                SNMP_LIB_FOUND="yes"], [], [$DRVLIBS])
723         fi
725         if test "$SNMP_LIB_FOUND" = "no" ; then
726            AC_MSG_ERROR([Cannot find SNMP libraries.])
727         fi
729         dnl If we get this far, we found a valid lib
730         AC_DEFINE(HAVE_SNMP_DRIVER)
731         DISPLAY_NETSNMP_DRIVER="net-snmp"
733         SNMP_DRIVER="snmp"
734         AC_SUBST(SNMP_DRIVER) 
735      fi ],
736    [])
738 dnl Enable test driver
739 AC_ARG_ENABLE(test, [
740 AC_HELP_STRING([--enable-test], [Compile TEST driver code])
741 AC_HELP_STRING([--disable-test], [No TEST driver (default)])],
742    [ if test "$enableval" = "yes" ; then
743         AC_DEFINE(HAVE_TEST_DRIVER)
744         TEST_DRIVER="test"
745         AC_SUBST(TEST_DRIVER)
746      fi],
747    [])
749 dnl Enable pcnet driver
750 AC_ARG_ENABLE(pcnet, [
751 AC_HELP_STRING([--enable-pcnet], [Compile PCNET driver code (default)])
752 AC_HELP_STRING([--disable-pcnet], [No PCNET driver])],
753    [ if test "$enableval" = "yes" ; then
754         AC_DEFINE(HAVE_PCNET_DRIVER)
755         PCNET_DRIVER="pcnet"
756         AC_SUBST(PCNET_DRIVER)
757      fi],
758    [ AC_DEFINE(HAVE_PCNET_DRIVER)
759      PCNET_DRIVER="pcnet"
760      AC_SUBST(PCNET_DRIVER) ])
762 dnl Force NIS to enabled since libnis is required by apcaccess.
763 dnl Users may still disable NIS at runtime in apcupsd.conf.
764 AC_DEFINE(HAVE_NISSERVER)
765 AC_DEFINE(HAVE_NISLIB)
766 NISSRV_ENABLED=yes
768 dnl Allow setting of NISIP value
769 NISIP="0.0.0.0"
770 AC_ARG_WITH(nisip,
771    [AC_HELP_STRING([--with-nisip=IP-ADDRESS], [Specify the IP address to bind to (default=0.0.0.0)])],
772    [NISIP="$withval";])
773 AC_SUBST(NISIP)
776 CGIBIN="/etc/apcupsd"
777 AC_ARG_WITH(cgi-bin,
778    [AC_HELP_STRING([--with-cgi-bin=DIR], [Specify cgi-bin directory (default=/etc/apcupsd)])],
779    [CGIBIN="$withval";])
782 dnl Check for enable of gapcmon
784 GAPCMON=
785 GAPCMON_ENABLED=no
786 AC_ARG_ENABLE(gapcmon, 
787    [AC_HELP_STRING([--enable-gapcmon], [Build GTK/GUI front-end to apcupsd (default=no)])],
788    [ if test "$enableval" = "yes" ; then
789       GAPCMON=gapcmon
790       GAPCMON_ENABLED=yes
792       dnl
793       dnl Check for Gnome packages
794       dnl
795       PKG_CHECK_MODULES(GAPCMON, gtk+-2.0 >= 2.4.0 glib-2.0 gthread-2.0 gconf-2.0)
796       GAPCMON_CFLAGS="$GAPCMON_CFLAGS -DVERSION=\\\"$VERSION\\\""
797    fi],
798   [])
799 AC_SUBST(GAPCMON)
802 dnl Check for enable of apcagent
804 APCAGENT=
805 APCAGENT_ENABLED=no
806 AC_ARG_ENABLE(apcagent, 
807    [AC_HELP_STRING([--enable-apcagent], [Build menubar app for Mac OS X (default=no)])],
808    [ if test "$enableval" = "yes" ; then
809       case $host in
810       *-*-darwin*)
811          APCAGENT=apcagent
812          APCAGENT_ENABLED=yes
813          ;;
814       *)
815          AC_MSG_ERROR([apcagent can only be built on Mac OS X])
816          ;;
817       esac
818    fi],
819   [case $host in
820    *-*-darwin*)
821       APCAGENT=apcagent
822       APCAGENT_ENABLED=yes
823       ;;
824    esac])
825 AC_SUBST(APCAGENT)
828 dnl Figure out which gethostbyname_r() variant we have
830 AX_FUNC_WHICH_GETHOSTBYNAME_R
831 case "$ac_cv_func_which_gethostbyname_r" in
832    three)
833    AC_DEFINE(HAVE_FUNC_GETHOSTBYNAME_R_3)
834    GAPCMON_CFLAGS="$GAPCMON_CFLAGS -DHAVE_FUNC_GETHOSTBYNAME_R_3"
835    ;;
837    five)
838    AC_DEFINE(HAVE_FUNC_GETHOSTBYNAME_R_5)
839    GAPCMON_CFLAGS="$GAPCMON_CFLAGS -DHAVE_FUNC_GETHOSTBYNAME_R_5"
840    ;;
842    six)
843    AC_DEFINE(HAVE_FUNC_GETHOSTBYNAME_R_6)
844    GAPCMON_CFLAGS="$GAPCMON_CFLAGS -DHAVE_FUNC_GETHOSTBYNAME_R_6"
845    ;;
847    no)
848    AC_DEFINE(HAVE_FUNC_GETHOSTBYNAME_R_0)
849    GAPCMON_CFLAGS="$GAPCMON_CFLAGS -DHAVE_FUNC_GETHOSTBYNAME_R_0"
850    ;;
852    *)
853    AC_MSG_ERROR([gethostbyname_r is required])
854    ;;
855 esac
857 if test -n "$GCC"; then
858    # Starting with GCC 3.0, you must link C++ programs against either
859    # libstdc++ (shared by default), or libsupc++ (always static).  If
860    # you care about binary portability between Linux distributions,
861    # you need to either 1) build your own GCC with static C++ libraries
862    # or 2) link using gcc and libsupc++.  We choose the latter since
863    # CUPS doesn't (currently) use any of the stdc++ library.
864    #
865    # Previous versions of GCC do not have the reliance on the stdc++
866    # or g++ libraries, so the extra supc++ library is not needed.
867    AC_MSG_CHECKING(if libsupc++ is required)
869    SUPC="`$CXX -print-file-name=libsupc++.a 2>/dev/null`"
870    case "$SUPC" in
871    libsupc++.a*)
872       # Library not found, so this is and older GCC...
873       AC_MSG_RESULT(no)
874       ;;
875    *)
876       # This is gcc 3.x, and it knows of libsupc++, so we need it
877       LIBS="$LIBS -lsupc++"
878       AC_MSG_RESULT(yes)
880       # See if this system has a broken libsupc++ that requires
881       # a workaround (FreeBSD 5.x, 6.x)
882       case $host in
883          *-*-freebsd*)
884             AC_MSG_CHECKING(if libsupc++ is missing __terminate_handler)
885             nm -C --defined-only "$SUPC" 2>/dev/null | grep __terminate_handler > /dev/null
886             if test $? -eq 0 ; then
887                AC_MSG_RESULT(no)
888             else
889                AC_MSG_RESULT(yes -- will attempt workaround)
890                CPPFLAGS="$CPPFLAGS -DFREEBSD_SUPCPP_FIX"
891             fi
892             ;;
893       esac
894       ;;
895    esac
897    # See if GCC supports -fno-exceptions...
898    AC_MSG_CHECKING(if GCC supports -fno-exceptions)
899    OLDCXXFLAGS="$CXXFLAGS"
900    CXXFLAGS="$CXXFLAGS -fno-exceptions"
901    AC_TRY_COMPILE(,,       
902       AC_MSG_RESULT(yes),
903       AC_MSG_RESULT(no)
904       CXXFLAGS="$OLDCXXFLAGS")
906    # See if GCC supports -fno-rtti...
907    AC_MSG_CHECKING(if GCC supports -fno-rtti)
908    OLDCXXFLAGS="$CXXFLAGS"
909    CXXFLAGS="$CXXFLAGS -fno-rtti"
910    AC_TRY_COMPILE(,,       
911       AC_MSG_RESULT(yes),
912       AC_MSG_RESULT(no)
913       CXXFLAGS="$OLDCXXFLAGS")
915    # Use -Wall on gcc only
916    CFLAGS="$CFLAGS -Wall"
917    CXXFLAGS="$CXXFLAGS -Wall"
920 AC_SUBST(POWERFLUTE)
921 AC_SUBST(POWERLIBS)
922 AC_SUBST(MAKE)
923 AC_SUBST(CP)
924 AC_SUBST(MV)
925 AC_SUBST(ECHO)
926 AC_SUBST(LN)
927 AC_SUBST(SED)
928 AC_SUBST(AR)
929 AC_SUBST(RM)
930 AC_SUBST(CC)
931 AC_SUBST(CXX)
932 AC_SUBST(LD)
933 AC_SUBST(CGI)
934 AC_SUBST(GD_LIBS)
935 AC_SUBST(CGIBIN)
936 AC_DEFINE_UNQUOTED(SYSCONFDIR, "$sysconfdir")
937 AC_SUBST(SYSCONFDIR)
938 AC_SUBST(RST2HTML)
939 AC_SUBST(RST2PDF)
941 dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we will probably
942 dnl find the mkinstalldirs script in another subdir than ($topdir).
943 dnl Try to locate it.
944 MKINSTALLDIRS=
945 if test -n "$ac_aux_dir"; then
946    MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
948 if test x$MKINSTALLDIRS = x ; then
949    MKINSTALLDIRS="\$(topdir)/autoconf/mkinstalldirs"
951 AC_SUBST(MKINSTALLDIRS)
954 dnl AC_CHECK_FUNC calls that might hack the Makefile must precede
955 dnl the following AC_SUBSTs
957 AC_SUBST(EXTRADEFS)
958 AC_SUBST(LIBEXTRAOBJ)
959 AC_SUBST(EXTRAOBJ)
961 dnl Check out the wait reality.  We have to assume sys/wait.h is present.
962 AC_CHECK_FUNCS(wait waitpid wait3)
963 AC_MSG_CHECKING([for union wait]);
964 AC_TRY_LINK([#include <sys/types.h>
965              #include <sys/wait.h>],
966             [union wait status; int pid; pid = wait (&status);
967              #ifdef WEXITSTATUS
968                 /* Some POSIXoid systems have both the new-style macros and the old
969                    union wait type, and they do not work together.  If union wait
970                    conflicts with WEXITSTATUS et al, we don't want to use it at all.  */
971                 if (WEXITSTATUS (status) != 0) pid = -1;
972              #endif
973              #ifdef HAVE_WAITPID
974                 /* Make sure union wait works with waitpid.  */
975                 pid = waitpid (-1, &status, 0);
976              #endif
977             ],
978    [AC_DEFINE(HAVE_UNION_WAIT) AC_MSG_RESULT([yes])],
979     AC_MSG_RESULT([no]))
981 if test "$ENABLE_CGI" = "yes"
982 then
983    AC_CHECK_FUNCS( snprintf,,
984       [AC_MSG_ERROR([cannot find required function.])])
985    echo 'Enabling cgi program support...'
986 else
987    echo 'Disabling cgi support...'
991 dnl Find out the distribution.   NOTE!!! Only determine the
992 dnl   distribution here.  Do all additional work below.
995 # now allow user to specify DISTNAME
996 AC_ARG_WITH(distname,
997    [AC_HELP_STRING([--with-distname=NAME], [Specify DISTNAME])],
998    [DISTNAME=$withval])
1000 if test "x$DISTNAME" != "x"
1001 then
1002    echo "distname set to $DISTNAME"
1003 elif test $HAVE_UNAME=yes -a x`uname -s` = xOSF1
1004 then
1005    DISTNAME=alpha
1006 elif test $HAVE_UNAME=yes -a x`uname -s` = xHP-UX
1007 then
1008    DISTNAME=hpux
1009 elif test $HAVE_UNAME=yes -a x`uname -s` = xSunOS
1010 then
1011    DISTNAME=sun
1012 elif test $HAVE_UNAME=yes -a x`uname -s` = xFreeBSD
1013 then
1014    DISTNAME=freebsd
1015 elif test $HAVE_UNAME=yes -a x`uname -s` = xNetBSD
1016 then
1017    DISTNAME=netbsd
1018 elif test $HAVE_UNAME=yes -a x`uname -s` = xOpenBSD
1019 then
1020    DISTNAME=openbsd
1021 elif test $HAVE_UNAME=yes -a x`uname -s` = xBSD/OS
1022 then
1023    DISTNAME=bsdi
1024 elif test $HAVE_UNAME=yes -a x`uname -s` = xDarwin
1025 then
1026     DISTNAME=darwin
1027 elif test $HAVE_UNAME=yes -a x`uname -s` = xQNX
1028 then
1029    DISTNAME=qnx
1030 elif test -f /etc/SuSE-release
1031 then
1032    DISTNAME=suse
1033 elif test -d /etc/SuSEconfig
1034 then
1035    DISTNAME=suse5
1036 elif test -f /etc/mandrake-release
1037 then
1038     DISTNAME=mandrake
1039 elif test -f /etc/whitebox-release
1040 then
1041    DISTNAME=redhat
1042 elif test -f /etc/redhat-release
1043 then
1044    DISTNAME=redhat
1045 elif test -f /etc/yellowdog-release
1046 then
1047    DISTNAME=yellowdog
1048 elif test -f /etc/debian_version
1049 then
1050    DISTNAME=debian
1051 elif test -f /etc/slackware-version
1052 then
1053    DISTNAME=slackware
1054 elif test -f /etc/gentoo-release
1055 then
1056    DISTNAME=gentoo
1057 elif test -f /etc/engarde-version
1058 then
1059    DISTNAME=engarde
1060 else
1061    DISTNAME=unknown
1064 dnl   
1065 dnl Check for enable install of distdir
1067 DISTDIR=$DISTNAME
1068 with_distdir="yes"
1069 AC_ARG_ENABLE(install-distdir,
1070    [AC_HELP_STRING([--enable-install-distdir], [Install distribution])],
1071    [ if test "$enableval" = "no" ; then
1072         DISTDIR=""
1073         with_distdir="no"
1074      fi ])
1075 AC_SUBST(DISTDIR)
1078 dnl At this point, we define the apcupsd defaults for a 
1079 dnl  number of different values (directories, ports, etc)
1080 dnl  When the distribution is determined a bit lower, the 
1081 dnl  default can be reset to correspond to the standard for
1082 dnl  that system.  
1083 dnl  Finally, after that any value that the user has set via
1084 dnl  command line options will apply.
1085 dnl  
1087 # Define the default UPS
1088 UPSTYPE=usb
1090 # Define the default Cable
1091 UPSCABLE=usb
1093 # set the default nologin directory
1094 nologdir=/etc
1096 # Find the default directory to put the root-mode PID file in
1097 for PIDDIR in "/var/run" "/etc/apcupsd"
1099    if test -d $PIDDIR 
1100    then
1101       break;
1102    fi
1103 done
1105 # Find the default directory to put the apcupsd.events and apcupsd.status files
1106 for LOGDIR in "/var/log" "/etc/apcupsd"
1108    if test -d $LOGDIR 
1109    then
1110       break;
1111    fi
1112 done
1114 # set the default serial port lock director
1115 for LOCKDIR in "/var/lock" "/var/spool/locks" "/etc/apcupsd"
1117    if test -d $LOCKDIR
1118    then
1119       break;
1120    fi
1121 done
1123 # set the default PWRFAILDIR
1124 PWRFAILDIR=${sysconfdir}
1126 # define the default serial port device
1127 SERIALDEV=/dev/ttyS0
1129 # define the default NIS (Network Information Server -- CGI) port
1130 NISPORT=3551
1133 # Now we set appropriate distribution specific
1134 #  variables and defaults
1136 case "$DISTNAME" in
1137 alpha)
1138    PTHREAD_LFLAGS="-lpthread -lexc"
1139    DISTVER=`uname -r`
1140    SERIALDEV=/dev/tty01
1141    LOCKDIR=/var/spool/locks
1142    LOGDIR=/etc/apcupsd
1143    DFILES="\
1144       platforms/alpha/apcupsd \
1145       platforms/alpha/awkhaltprog"
1146    ;;
1147 bsdi)
1148    DISTVER=`uname -a |awk '{print $3}'`
1149    ;;
1150 debian)
1151    DISTVER=`cat /etc/debian_version`
1152    DFILES="\
1153       platforms/debian/apcupsd \
1154       platforms/debian/ups-monitor"
1155    ;;
1156 freebsd)
1157    DISTVER=`uname -a |awk '{print $3}'`
1158    SERIALDEV=/dev/cuaa0
1159    nologdir=/var/run
1160    PWRFAILDIR=/var/run
1161    LOCKDIR=/var/spool/lock
1162    PTHREAD_CFLAGS="-pthread"
1163    PTHREAD_LFLAGS=""
1164    LDFLAGS="$LDFLAGS -pthread"
1165    DFILES="\
1166       platforms/freebsd/apcupsd \
1167       platforms/freebsd/apccontrol"
1168    ;;
1169 gentoo)
1170    DISTVER=`awk '/version / {print $5}' < /etc/gentoo-release`
1171    DFILES="\
1172       platforms/gentoo/apcupsd \
1173       platforms/gentoo/halt"
1174    ;;
1175 hpux)
1176    DISTVER=`uname -r`
1177    SERIALDEV=/dev/tty0p0
1178    PTHREAD_CFLAGS="-D_XOPEN_SOURCE_EXTENDED -D_REENTRANT"
1179    DFILES="\
1180       platforms/hpux/apcupsd \
1181       platforms/hpux/halt"
1182    ;;
1183 netbsd)
1184    DISTVER=`uname -a |awk '{print $3}'`
1185    SERIALDEV=/dev/cua01
1186    PTHREAD_CFLAGS="-pthread"
1187    PTHREAD_LFLAGS=""
1188    LDFLAGS="$LDFLAGS -pthread"
1189    DFILES="\
1190       platforms/netbsd/apcupsd"
1191    ;;
1192 openbsd)
1193    DISTVER=`uname -a |awk '{print $3}'`
1194    SERIALDEV=/dev/cua01
1195    LOCKDIR=/var/spool/lock
1196    PTHREAD_CFLAGS="-pthread"
1197    PTHREAD_LFLAGS=""
1198    LDFLAGS="$LDFLAGS -pthread"
1199    DFILES="\
1200       platforms/openbsd/apcupsd \
1201       platforms/openbsd/apccontrol"
1202   ;;
1203 mandrake)
1204    DISTVER=`cat /etc/mandrake-release | grep release | cut -f 5 -d ' '`
1205    DFILES="\
1206       platforms/mandrake/apcupsd \
1207       platforms/mandrake/apcupsd.spec \
1208       platforms/mandrake/awkhaltprog"
1209    ;;
1210 redhat)
1211    if test -f /etc/whitebox-release ; then
1212       f=/etc/whitebox-release
1213    else
1214       f=/etc/redhat-release
1215    fi
1216    if test `cat $f | grep release | cut -f 3 -d ' '`x = "Enterprise"x ; then
1217       DISTVER="Enterprise "`cat $f | grep release | cut -f 6 -d ' '`
1218    else
1219       DISTVER=`cat /etc/redhat-release | grep release | cut -f 5 -d ' '`
1220    fi
1221    DFILES="\
1222       platforms/redhat/apcupsd \
1223       platforms/redhat/apcupsd.spec \
1224       platforms/redhat/awkhaltprog"
1225    ;;
1226 yellowdog)
1227     if test `cat /etc/yellowdog-release | grep release | cut -f 3 -d ' '`x = "Enterprise"x ; then
1228        DISTVER="Enterprise "`cat /etc/yellowdog-release | grep release | cut -f 6 -d ' '`
1229     else
1230        DISTVER=`cat /etc/yellowdog-release | grep release | cut -f 5 -d ' '`
1231    fi
1232    DFILES="\
1233       platforms/yellowdog/apcupsd \
1234       platforms/yellowdog/apcupsd.spec \
1235       platforms/yellowdog/awkhaltprog"
1236    ;;
1237 engarde)
1238    DISTVER=`cat /etc/engarde-release | grep ersion | cut -f 5 -d ' '`
1239    DFILES="\
1240       platforms/engarde/apcupsd \
1241       platforms/engarde/apcupsd.spec \
1242       platforms/engarde/awkhaltprog"
1243    ;;
1244 slackware)
1245    DISTVER=`cat /etc/slackware-version`
1246    DFILES="\
1247       platforms/slackware/apcupsd \
1248       platforms/slackware/rc6.patch" 
1249    ;;
1250 sun)
1251    DISTVER=Solaris
1252    SERIALDEV=/dev/ttya
1253    PWRFAILDIR=/etc
1254    PIDDIR=/var/run
1255    LOCKDIR=/var/spool/locks
1256    LOGDIR=${sysconfdir}
1257    APCUPSD_MAIL=/usr/bin/mailx
1258    PTHREAD_CFLAGS="-D_POSIX_PTHREAD_SEMANTICS"
1259    DFILES="\
1260       platforms/sun/apcupsd \
1261       platforms/sun/rc0.solaris \
1262       platforms/sun/apccontrol"
1263    ;;
1264 suse)
1265    DISTVER=`cat /etc/SuSE-release |grep VERSION| cut -f 3 -d ' '`
1266    DFILES="\
1267       platforms/suse/apcupsd \
1268       platforms/suse/awkhaltprog"
1269    ;;
1270 suse5)
1271    DISTNAME=suse
1272    DISTVER=5.x
1273    DFILES="\
1274       platforms/suse/apcupsd \
1275       platforms/suse/halt-setup.sh \
1276       platforms/suse/halt"
1277    ;;
1278 darwin)
1279    DISTVER=`uname -r`
1280    SERIALDEV=
1281    UPSTYPE=usb
1282    UPSCABLE=usb
1283    PIDDIR=/var/run
1284    LOCKDIR=/var/tmp
1285    DFILES="\
1286       platforms/darwin/apcupsd \
1287       platforms/darwin/apccontrol"
1288    ;;
1289 qnx)
1290    PTHREAD_LFLAGS=""
1291    DISTVER=`uname -r`
1292    SERIALDEV=/dev/ser1
1293    DFILES="\
1294       platforms/qnx/apcupsd \
1295       platforms/qnx/apccontrol"
1296    ;;
1297 unknown)
1298    DISTVER=unknown
1299    DFILES="\
1300       platforms/unknown/apcupsd \
1301       platforms/unknown/halt"
1302   ;;
1304   AC_MSG_WARN([Something went wrong. Unknown DISTNAME $DISTNAME])
1305   ;;
1306 esac  
1309 dnl Allow user to set nologdir
1311 AC_ARG_WITH(nologin,
1312    [AC_HELP_STRING([--with-nologin=DIR], [Specify nologin file directory (default /etc)])],
1313    [ nologdir="$withval"; ])
1315 # now allow the user to specify the PID directory
1316 AC_ARG_WITH(pid-dir,
1317     [AC_HELP_STRING([--with-pid-dir=DIR], [Specify PIDDIR directory (default is OS dependent)])],
1318     [PIDDIR="$withval";])
1320 # now allow user to specify LOGDIR
1321 AC_ARG_WITH(log-dir,
1322     [AC_HELP_STRING([--with-log-dir=DIR], [Specify EVENTS and STATUS directory (default is OS dependent)])],
1323     [LOGDIR="$withval";])
1325 # now allow user to specify LOCKDIR
1326 AC_ARG_WITH(lock-dir,
1327     [AC_HELP_STRING([--with-lock-dir=DIR], [Specify serial port lock directory (default is OS dependent)])],
1328     [LOCKDIR="$withval";])
1330 # now allow user to specify PWRFAILDIR
1331 AC_ARG_WITH(pwrfail-dir,
1332     [AC_HELP_STRING([--with-pwrfail-dir=DIR], [Specify power failure file directory (default is OS dependent)])],
1333     [PWRFAILDIR="$withval";])
1335 # now allow user to specify SERIALDEV
1336 AC_ARG_WITH(serial-dev,
1337     [AC_HELP_STRING([--with-serial-dev=DEV], [Specify serial port device])],
1338     [SERIALDEV="$withval";])
1340 AC_ARG_WITH(dev,
1341     [AC_HELP_STRING([--with-dev=DEV], [Specify port or device])],
1342     [SERIALDEV="$withval";])
1344 # now allow user to specify NISPORT
1345 AC_ARG_WITH(nis-port,
1346     [AC_HELP_STRING([--with-nis-port=PORT], [Specify NIS (CGI) port (default 3551 except Debian)])],
1347     [NISPORT="$withval";])
1349 # now allow user to specify UPSTYPE
1350 AC_ARG_WITH(upstype,
1351     [AC_HELP_STRING([--with-upstype=TYPE], [Specify the UPS type])],
1352     [UPSTYPE="$withval";])
1354 # now allow user to specify UPSCABLE
1355 AC_ARG_WITH(upscable,
1356     [AC_HELP_STRING([--with-upscable=CABLE], [Specify the UPS cable])],
1357     [UPSCABLE="$withval";])
1359 AC_SUBST(DISTNAME)
1360 AC_SUBST(DISTVER)
1361 AC_SUBST(SERIALDEV)
1362 AC_DEFINE_UNQUOTED(PIDDIR, "$PIDDIR")
1363 AC_SUBST(PIDDIR)
1364 AC_DEFINE_UNQUOTED(LOGDIR, "$LOGDIR")
1365 AC_SUBST(LOGDIR)
1366 AC_DEFINE_UNQUOTED(NOLOGDIR, "$nologdir")
1367 AC_SUBST(nologdir)
1368 AC_DEFINE_UNQUOTED(PWRFAILDIR, "$PWRFAILDIR")
1369 AC_SUBST(PWRFAILDIR)
1370 AC_SUBST(LOCKDIR)
1371 AC_SUBST(NISPORT)
1372 AC_DEFINE_UNQUOTED(NISPORT, $NISPORT)
1373 AC_SUBST(UPSTYPE)
1374 AC_SUBST(UPSCABLE)
1376 HOST=$DISTNAME
1377 AC_DEFINE_UNQUOTED(HOST, "$HOST")
1378 AC_SUBST(HOST)
1381 dnl Find out gcc's installation directory and include files. Used in
1382 dnl configure.
1384 dnl Make sure a gccinclude variable exist.
1385 dnl '.' is innocuous.
1386 gccinclude="."
1388 if test "$CC" = "gcc"
1389 then
1390    rm -f $srcdir/gcc.v
1391    $CC -v 2> $srcdir/gcc.v
1392    gccinclude=`cat $srcdir/gcc.v|grep specs|awk '{print $4}'| \
1393       sed -e 's|specs|include|g'`
1394    echo "gcc private include directory found."
1395    rm -f $srcdir/gcc.v
1399 dnl First entry must always be "variables.mak"
1401 GENERATE_FILES="\
1402    autoconf/variables.mak \
1403    platforms/apccontrol \
1404    platforms/etc/changeme \
1405    platforms/etc/commfailure \
1406    platforms/etc/commok \
1407    platforms/etc/offbattery \
1408    platforms/etc/onbattery \
1409    platforms/etc/apcupsd.conf \
1410    examples/safe.apccontrol \
1411    src/win32/Makefile \
1412    $DFILES"
1414 if test "$USB_TYPE"x = "generic"x
1415 then
1416    GENERATE_FILES="$GENERATE_FILES \
1417    src/drivers/usb/generic/libusb.h"
1420 if test "$ENABLE_CGI" = "yes"
1421 then
1422    GENERATE_FILES="$GENERATE_FILES src/cgi/cgiconfig.h"
1425 AC_OUTPUT([ ${GENERATE_FILES} ], [])
1427 chmod 755 examples/safe.apccontrol
1428 $MAKE clean
1431 # A whole lot of hand springs to get the compiler version.
1432 #  This is because gcc changed the output in version 3.0
1434 CXXVERSION=`${CXX} --version | tr '\n' ' ' | cut -f 3 -d ' '`
1435 if test "x${CXXVERSION}" = "x" ; then
1436    CXXVERSION=`${CXX} --version | tr '\n' ' ' | cut -f 1 -d ' '`
1439 eval srcdir=${srcdir}
1440 eval sbindir=${sbindir}
1441 eval sysconfdir=${sysconfdir}
1442 eval mandir=${mandir}
1444 echo "
1446 Configuration on `date`:
1448   Host:                       $host -- ${DISTNAME} ${DISTVER} 
1449   Apcupsd version:            ${VERSION} (${DATE})
1450   Source code location:       ${srcdir}
1451   Install binaries:           ${sbindir}
1452   Install config files:       ${sysconfdir}
1453   Install man files:          ${mandir}
1454   Nologin file in:            ${nologdir}
1455   PID directory:              ${PIDDIR}
1456   LOG dir (events, status)    ${LOGDIR}
1457   LOCK dir (for serial port)  ${LOCKDIR}
1458   Power Fail dir              ${PWRFAILDIR}
1459   Compiler:                   ${CXX} ${CXXVERSION}
1460   Compiler flags:             ${CPPFLAGS} ${CXXFLAGS} ${PTHREAD_FLAGS}
1461   Linker:                     ${LD}
1462   Linker flags:               ${LDFLAGS}
1463   Host and version:           ${DISTNAME} ${DISTVER}
1464   Shutdown Program:           ${SHUTDOWN}
1465   Port/Device:                ${SERIALDEV}
1466   Network Info Port (CGI):    ${NISPORT}
1467   UPSTYPE                     ${UPSTYPE}
1468   UPSCABLE                    ${UPSCABLE}
1470   drivers (no-* are disabled): ${APCSMART_DRIVER:-no-apcsmart} ${DUMB_DRIVER:-no-dumb} ${NET_DRIVER:-no-net} ${DISPLAY_USB_DRIVER:-no-usb} ${DISPLAY_SNMP_DRIVER:-no-snmp} ${DISPLAY_NETSNMP_DRIVER:-no-net-snmp} ${PCNET_DRIVER:-no-pcnet} ${TEST_DRIVER:-no-test}
1472   enable-nis:                 ${NISSRV_ENABLED}
1473   with-nisip:                 ${NISIP}
1474   enable-cgi:                 ${ENABLE_CGI}
1475   disable-lgd:                ${SKIP_GDHDR_CHECK}
1476   with-cgi-bin:               ${CGIBIN}
1477   with-libwrap:               ${with_libwrap}
1478   enable-pthreads:            ${with_pthreads}
1479   enable-dist-install:        ${with_distdir}
1480   enable-gapcmon:             ${GAPCMON_ENABLED}
1481   enable-apcagent:            ${APCAGENT_ENABLED}
1482   " > config.out
1484 cat config.out
1486 echo Configuration complete: Run \'$MAKE\' to build apcuspd.
1487 echo
1489 echo $PATH | grep /usr/ucb >/dev/null
1490 if test $? = 0 ; then
1491    AC_MSG_WARN([ 
1492       WARNING! You have /usr/ucb on your path. We STRONGLY recommend
1493          that you remove it and rerun configure. Otherwise
1494          apcupsd may be unable to shutdown your system.
1495    ]);