]> git.proxmox.com Git - mirror_smartmontools-debian.git/blame - configure.ac
New upstream version 6.6
[mirror_smartmontools-debian.git] / configure.ac
CommitLineData
832b75ed 1#
f9e10201 2# $Id: configure.ac 4594 2017-11-05 15:21:35Z chrfranke $
832b75ed
GG
3#
4dnl Process this file with autoconf to produce a configure script.
a86ec89e 5AC_PREREQ([2.60])
f9e10201 6AC_INIT(smartmontools, 6.6, smartmontools-support@listi.jpberlin.de)
a86ec89e 7AM_INIT_AUTOMAKE([1.10 foreign])
832b75ed 8
f9e10201
JD
9smartmontools_cvs_tag=`echo '$Id: configure.ac 4594 2017-11-05 15:21:35Z chrfranke $'`
10smartmontools_release_date=2017-11-05
11smartmontools_release_time="15:20:58 UTC"
832b75ed
GG
12
13AC_DEFINE_UNQUOTED(SMARTMONTOOLS_CONFIGURE_ARGS, "$ac_configure_args", [smartmontools Configure Arguments])
832b75ed
GG
14AC_DEFINE_UNQUOTED(SMARTMONTOOLS_RELEASE_DATE, "$smartmontools_release_date", [smartmontools Release Date])
15AC_DEFINE_UNQUOTED(SMARTMONTOOLS_RELEASE_TIME, "$smartmontools_release_time", [smartmontools Release Time])
16AC_DEFINE_UNQUOTED(CONFIG_H_CVSID, "$smartmontools_cvs_tag", [smartmontools CVS Tag])
a86ec89e 17AC_DEFINE_UNQUOTED(PACKAGE_HOMEPAGE, "http://www.smartmontools.org/", [smartmontools Home Page])
832b75ed 18
a86ec89e 19AC_CONFIG_SRCDIR([smartctl.cpp])
d2e702cf 20AC_CONFIG_HEADER([config.h])
832b75ed 21
832b75ed
GG
22AM_MAINTAINER_MODE
23
d2e702cf 24AC_LANG([C++])
832b75ed 25dnl Checks for programs.
4d59bff9 26AC_PROG_CXX
832b75ed
GG
27AM_PROG_AS
28AC_PROG_INSTALL
d008864d
GI
29
30m4_pattern_forbid([^PKG_PROG_])
31if test "$cross_compiling" = "no"; then
32 m4_ifdef([PKG_PROG_PKG_CONFIG], [PKG_PROG_PKG_CONFIG],
33 [AC_MSG_WARN([m4/pkg.m4 missing, systemd detection disabled])])
34fi
832b75ed 35
cfbba5b9
GI
36AC_ARG_VAR(WINDMC, [Windows message compiler command])
37AC_ARG_VAR(WINDRES, [Windows resource compiler command])
38AC_ARG_VAR(MAKENSIS, [NSIS compiler command])
39
832b75ed 40AC_CANONICAL_HOST
832b75ed 41case "${host}" in
cfbba5b9 42 *-*-mingw*)
ee38a438
GI
43 AC_CHECK_TOOL(WINDMC, [windmc])
44 AC_CHECK_TOOL(WINDRES, [windres])
cfbba5b9 45
d2e702cf 46 AC_MSG_CHECKING([for makensis])
cfbba5b9
GI
47 if test -z "$MAKENSIS"; then
48 if test -n "$PROGRAMFILES" && "$PROGRAMFILES/NSIS/makensis" -VERSION >/dev/null 2>&1; then
49 MAKENSIS="$PROGRAMFILES/NSIS/makensis"
50 elif makensis -VERSION >/dev/null 2>&1; then
51 MAKENSIS=makensis
52 fi
53 fi
54 AC_MSG_RESULT([${MAKENSIS:-no}])
cfbba5b9 55 ;;
832b75ed
GG
56esac
57
2127e193
GI
58# Check for SVN.
59AC_MSG_CHECKING([whether this is a build from SVN])
60is_svn_build=no
e165493d 61svn_deps=
3d17a85c
GI
62if test -f "$srcdir/.svn/wc.db"; then
63 # SVN 1.7, 1.8 working copy
64 svn_deps='${srcdir}/.svn/wc.db'
65elif test -f "${srcdir}/.svn/entries"; then
66 # SVN <= 1.6 working copy (SVN 1.7 has empty entries file)
67 svn_deps='${srcdir}/.svn/entries'
68fi
69if test -n "$svn_deps"; then
2127e193
GI
70 is_svn_build=unknown
71 if (cd "$srcdir" && svn --version && svnversion && svn info) >/dev/null 2>&1; then
72 is_svn_build=yes
73 fi
74fi
e165493d 75AC_SUBST([svn_deps])
2127e193
GI
76AM_CONDITIONAL(IS_SVN_BUILD, [test "$is_svn_build" = "yes"])
77AC_MSG_RESULT([$is_svn_build])
78
e165493d
GI
79# Note: On Linux, clock_gettime() requires -lrt which implies -lpthreads
80# Check ommitted for now, gettimeofday() provides reasonable precision
81# AC_SEARCH_LIBS(clock_gettime, rt)
82
832b75ed
GG
83dnl Checks for header files.
84AC_CHECK_HEADERS([locale.h])
832b75ed 85AC_CHECK_HEADERS([dev/ata/atavar.h])
832b75ed
GG
86dnl we need [u]int64_t and friends.
87AC_CHECK_HEADERS([inttypes.h]) dnl C99, UNIX98, solaris 2.6+
88AC_CHECK_HEADERS([stdint.h]) dnl C99
89AC_CHECK_HEADERS([sys/inttypes.h]) dnl pre-UNIX98
90AC_CHECK_HEADERS([sys/int_types.h]) dnl pre-UNIX98, solaris 2.6+
91dnl Check for FreeBSD twe include files...currently missing on 5.2, but should be there
92AC_CHECK_HEADERS([sys/tweio.h])
93AC_CHECK_HEADERS([sys/twereg.h])
94dnl Check for FreeBSD twa include files...
95AC_CHECK_HEADERS([sys/tw_osl_ioctl.h])
1953ff6d 96dnl This header file is needed for cciss_ioctl.h at least on SuSE LINUX
ba59cff1 97AC_CHECK_HEADERS([linux/compiler.h])
d008864d
GI
98dnl Check for the FreeBSD CCISS system header and use internal one if not found
99AC_CHECK_HEADERS([dev/ciss/cissio.h],
100 [AC_DEFINE([CISS_LOCATION],[<dev/ciss/cissio.h>],[freebsd ciss header location])],
101 [AC_DEFINE([CISS_LOCATION],["cissio_freebsd.h"],[freebsd ciss header location])]
102 )
1953ff6d
GG
103dnl Check for Linux CCISS include file
104AC_CHECK_HEADERS([linux/cciss_ioctl.h], [], [], [AC_INCLUDES_DEFAULT
105#ifdef HAVE_LINUX_COMPILER_H
106# include <linux/compiler.h>
107#endif
108])
cfbba5b9
GI
109dnl Check for Windows DDK and WMI header files
110AC_CHECK_HEADERS([ntdddisk.h ddk/ntdddisk.h], [], [], [AC_INCLUDES_DEFAULT
111#include <windows.h>
112])
113AC_CHECK_HEADERS([wbemcli.h])
832b75ed
GG
114
115dnl Checks for typedefs, structures, and compiler characteristics.
116AC_CHECK_TYPES([int64_t, uint64_t])
117
118dnl Checks for library functions.
e9583e0c
GI
119AC_CHECK_FUNCS([getopt_long], [need_getopt_long=no], [need_getopt_long=yes])
120AM_CONDITIONAL(NEED_GETOPT_LONG, [test "$need_getopt_long" = "yes"])
121AC_CHECK_FUNCS([regcomp], [need_regex=no], [need_regex=yes])
122AM_CONDITIONAL(NEED_REGEX, [test "$need_regex" = "yes"])
2127e193 123
832b75ed
GG
124AC_CHECK_FUNCS([sigset])
125AC_CHECK_FUNCS([strtoull])
126AC_CHECK_FUNCS([uname])
e165493d 127AC_CHECK_FUNCS([clock_gettime ftime gettimeofday])
832b75ed 128
e9583e0c
GI
129# Check byte ordering (defines WORDS_BIGENDIAN)
130AC_C_BIGENDIAN
131
832b75ed 132# check for __attribute__((packed))
d008864d
GI
133# (sizeof() check is required to avoid false positives if other
134# __attribute__((x)) are supported)
7f0798ef 135AC_MSG_CHECKING([whether $CXX supports __attribute__((packed))])
d008864d
GI
136AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [[
137 struct s { char a; short b; } __attribute__((packed));
138 typedef char t[sizeof(struct s) == 3 ? 1 : -1];]])],
139 [gcc_have_attr_packed=yes], [gcc_have_attr_packed=no])
832b75ed
GG
140AC_SUBST(gcc_have_attr_packed)
141if test "$gcc_have_attr_packed" = "yes"; then
cfbba5b9 142 AC_DEFINE(HAVE_ATTR_PACKED, 1, [Define to 1 if C++ compiler supports __attribute__((packed))])
832b75ed
GG
143fi
144AC_MSG_RESULT([$gcc_have_attr_packed])
145
146AC_SUBST(CPPFLAGS)
147AC_SUBST(LDFLAGS)
148AC_SUBST(ASFLAGS)
149
a7e8ffec
GI
150AC_ARG_WITH(systemdsystemunitdir,
151 [AS_HELP_STRING([--with-systemdsystemunitdir@<:@=DIR|auto|yes|no@:>@], [Location of systemd service files [auto]])],
a86ec89e 152 [], [with_systemdsystemunitdir=auto])
a7e8ffec
GI
153
154systemdsystemunitdir=
155case "$with_systemdsystemunitdir" in
156 auto|yes)
d008864d
GI
157 if test -n "$PKG_CONFIG"; then
158 AC_MSG_CHECKING([for systemdsystemunitdir])
d2e702cf 159 systemdsystemunitdir=`$PKG_CONFIG --variable=systemdsystemunitdir systemd 2>/dev/null`
d008864d
GI
160 AC_MSG_RESULT([${systemdsystemunitdir:-no}])
161 fi
a7e8ffec
GI
162 case "$with_systemdsystemunitdir:$sysconfdir:$systemdsystemunitdir" in
163 yes:*:) AC_MSG_ERROR([Location of systemd service files not found]) ;;
164 yes:*:*|auto:*:|auto:/etc:*) ;;
165 *) systemdsystemunitdir='${prefix}'$systemdsystemunitdir ;;
166 esac ;;
167 no) ;;
168 *) systemdsystemunitdir="$with_systemdsystemunitdir" ;;
169esac
170AC_SUBST(systemdsystemunitdir)
171AM_CONDITIONAL(INSTALL_SYSTEMDUNIT, [test -n "$systemdsystemunitdir"])
172
a86ec89e
GI
173AC_ARG_WITH(systemdenvfile,
174 [AS_HELP_STRING([--with-systemdenvfile@<:@=FILE|auto|yes|no@:>@], [Path of systemd EnvironmentFile [auto]])],
175 [], [with_systemdenvfile=auto])
176
177systemdenvfile=
178case "$with_systemdenvfile:$cross_compiling:$systemdsystemunitdir" in
179 auto:no:?*|yes:*:?*)
180 AC_MSG_CHECKING([for path of systemd EnvironmentFile])
181 for dir in sysconfig default; do
182 if test -d /etc/$dir; then
183 systemdenvfile='${sysconfdir}'/$dir/smartmontools
184 break
185 fi
186 done
187 AC_MSG_RESULT([${systemdenvfile:-no}])
188 case "$with_systemdenvfile:$systemdenvfile" in
189 yes:) AC_MSG_ERROR([Path of systemd EnvironmentFile not found]) ;;
190 esac ;;
191 auto:*|no:*) ;;
192 *:*:) AC_MSG_ERROR([Location of systemd service files not found]) ;;
193 *) systemdenvfile="$with_systemdenvfile"
194esac
195AC_SUBST(systemdenvfile)
196
a23d5117 197AC_ARG_WITH(initscriptdir,
d2e702cf 198 [AS_HELP_STRING([--with-initscriptdir@<:@=DIR|auto|yes|no@:>@], [Location of init scripts [auto]])],
a7e8ffec
GI
199 [], [with_initscriptdir=auto])
200
d008864d
GI
201initddir=
202case "$with_initscriptdir:$cross_compiling:$systemdsystemunitdir" in
203 auto:no:|yes:*)
204 AC_MSG_CHECKING([for init (rc) directory])
205 for dir in rc.d/init.d init.d rc.d; do
206 if test -d /etc/$dir; then
207 initddir='${sysconfdir}'/$dir
208 break
209 fi
210 done
211 AC_MSG_RESULT([${initddir:-no}])
212 case "$with_initscriptdir:$initddir" in
213 yes:) AC_MSG_ERROR([Location of init scripts not found]) ;;
214 esac ;;
215 auto:*|no:*) ;;
a7e8ffec
GI
216 *) initddir="$with_initscriptdir" ;;
217esac
832b75ed 218AC_SUBST(initddir)
a7e8ffec
GI
219AM_CONDITIONAL(INSTALL_INITSCRIPT, [test -n "$initddir"])
220
221# use different init script templates for different OS
222case "${host}" in
223 *-*-freebsd*)
224 initdfile="smartd.freebsd.initd"
225 ;;
a86ec89e
GI
226 *-apple-darwin*)
227 initdfile="com.smartmontools.smartd.plist"
228 ;;
a7e8ffec
GI
229 *)
230 initdfile="smartd.initd"
231 ;;
232esac
233AC_SUBST(initdfile)
832b75ed 234
cfbba5b9 235AC_ARG_WITH(exampledir,
d2e702cf 236 [AS_HELP_STRING([--with-exampledir=DIR], [Location of example scripts [DOCDIR/examplescripts]])],
cfbba5b9
GI
237 [exampledir="$withval"], [exampledir='${docdir}/examplescripts'])
238AC_SUBST(exampledir)
239
a86ec89e 240drivedbdir='${datadir}/${PACKAGE}'
2127e193 241AC_ARG_WITH(drivedbdir,
a86ec89e
GI
242 [AS_HELP_STRING([--with-drivedbdir@<:@=DIR|yes|no@:>@], [Location of drive database file [DATADIR/smartmontools]])],
243 [case "$withval" in yes) ;; no) drivedbdir= ;; *) drivedbdir="$withval" ;; esac])
2127e193 244AC_SUBST(drivedbdir)
a86ec89e
GI
245AM_CONDITIONAL(ENABLE_DRIVEDB, [test -n "$drivedbdir"])
246
f9e10201 247drivedb_version=$VERSION
a86ec89e 248AC_ARG_WITH(update-smart_drivedb,
f9e10201
JD
249 [AS_HELP_STRING([--with-update-smart-drivedb@<:@=yes|no|X.Y@:>@],
250 [Install update-smart-drivedb script (and backport it to branches/RELEASE_X_Y_DRIVEDB) [yes]])],
251 [ case "$withval" in
252 yes|no) ;;
253 5.4[[0-3]]|6.[[0-9]]) drivedb_version=$withval; with_update_smart_drivedb=yes ;;
254 *) AC_MSG_ERROR([Invalid drivedb branch version: $withval]) ;;
255 esac
256 ],
257 [with_update_smart_drivedb=yes])
a86ec89e
GI
258test -n "$drivedbdir" || with_update_smart_drivedb=no
259AC_SUBST(with_update_smart_drivedb)
260AM_CONDITIONAL(ENABLE_UPDATE_SMART_DRIVEDB, [test "$with_update_smart_drivedb" = "yes"])
2127e193 261
f9e10201
JD
262gnupg="gpg"
263# Also check for '--with-gnupg[=yes]' because 'yes' is a valid command with infinite output
264AC_ARG_WITH(gnupg,
265 [AS_HELP_STRING([--with-gnupg@<:@=FILE|yes|no@:>@], [GnuPG used to verify drivedb.h [gpg]])],
266 [case "$withval" in yes) ;; no) gnupg= ;; *) gnupg="$withval" ;; esac], [])
267AC_SUBST(gnupg)
268
269case "$with_update_smart_drivedb:$gnupg" in
270 no:?*)
271 AC_MSG_ERROR([
272'--without-update-smart-drivedb' now requires '--without-gnupg'.
273NEWS: update-smart-drivedb now verifies the downloaded drivedb.h file with GnuPG.])
274 ;;
275esac
276
d2e702cf
GI
277AC_ARG_WITH(smartdscriptdir,
278 [AS_HELP_STRING([--with-smartdscriptdir=DIR], [Location of smartd_warning.sh script [SYSCONFDIR]])],
279 [smartdscriptdir="$withval"], [smartdscriptdir='${sysconfdir}'])
280AC_SUBST(smartdscriptdir)
281
282AC_ARG_WITH(smartdplugindir,
283 [AS_HELP_STRING([--with-smartdplugindir=@<:@DIR|no@:>@],
284 [Location of smartd_warning.sh plugin scripts [SMARTDSCRIPTDIR/smartd_warning.d]])],
285 [smartdplugindir=; test "$withval" != "no" && smartdplugindir="$withval"],
286 [smartdplugindir='${smartdscriptdir}/smartd_warning.d'])
287AC_SUBST(smartdplugindir)
288
f9e10201
JD
289AC_ARG_WITH(scriptpath,
290 [AS_HELP_STRING([--with-scriptpath=@<:@PATH|no@:>@],
291 [PATH variable set within scripts [/usr/bin:/bin]])],
292 [scriptpath=; test "$withval" != "no" && scriptpath="$withval"],
293 [scriptpath="/usr/bin:/bin"])
294AC_SUBST(scriptpath)
295AM_CONDITIONAL(ENABLE_SCRIPTPATH, [test -n "$scriptpath"])
296
a86ec89e 297savestates=
2127e193 298AC_ARG_WITH(savestates,
a86ec89e
GI
299 [AS_HELP_STRING([--with-savestates@<:@=PREFIX|yes|no@:>@],
300 [Enable default smartd state files [no] (yes=LOCALSTATEDIR/lib/smartmontools/smartd.)])],
301 [case "$withval" in yes) savestates='${localstatedir}/lib/${PACKAGE}/smartd.' ;;
302 no) ;; *) savestates="$withval" ;; esac])
2127e193
GI
303savestatesdir="${savestates%/*}"
304AC_SUBST(savestates)
305AC_SUBST(savestatesdir)
a86ec89e 306AM_CONDITIONAL(ENABLE_SAVESTATES, [test -n "$savestates"])
2127e193 307
a86ec89e 308attributelog=
2127e193 309AC_ARG_WITH(attributelog,
a86ec89e
GI
310 [AS_HELP_STRING([--with-attributelog@<:@=PREFIX|yes|no@:>@],
311 [Enable default smartd attribute log files [no] (yes=LOCALSTATEDIR/lib/smartmontools/attrlog.)])],
312 [case "$withval" in yes) attributelog='${localstatedir}/lib/${PACKAGE}/attrlog.' ;;
313 no) ;; *) attributelog="$withval" ;; esac])
2127e193
GI
314attributelogdir="${attributelog%/*}"
315AC_SUBST(attributelog)
316AC_SUBST(attributelogdir)
a86ec89e 317AM_CONDITIONAL(ENABLE_ATTRIBUTELOG, [test -n "$attributelog"])
2127e193 318
cfbba5b9 319AC_ARG_ENABLE(sample,
d2e702cf 320 [AS_HELP_STRING([--enable-sample], [Enables appending .sample to the installed smartd rc script and configuration file])],
cfbba5b9
GI
321 [smartd_suffix=; test "$enableval" = "yes" && smartd_suffix=".sample"],
322 [smartd_suffix=;])
832b75ed 323AC_SUBST(smartd_suffix)
832b75ed 324
2127e193 325AC_ARG_WITH(os-deps,
d2e702cf 326 [AS_HELP_STRING([--with-os-deps='os_module.o ...'], [Specify OS dependent module(s) [guessed]])],
2127e193
GI
327 [ for x in $with_os_deps; do
328 case $x in
329 *.o) ;;
330 *) AC_MSG_ERROR([non-object file specified by --with-os-deps]) ;;
331 esac
332 done
333 ],[])
334
cfbba5b9 335AC_ARG_WITH(selinux,
d2e702cf 336 [AS_HELP_STRING([--with-selinux@<:@=yes|no@:>@], [Enables SELinux support [no]])],
cfbba5b9
GI
337 [ if test "$withval" = "yes"; then
338 AC_CHECK_HEADERS([selinux/selinux.h], [], [AC_MSG_ERROR([Missing SELinux header files])])
339 AC_CHECK_LIB(selinux, matchpathcon, [], [AC_MSG_ERROR([Missing or incorrect SELinux library files])])
340 fi
341 ],[])
2127e193
GI
342AC_SUBST(with_selinux)
343if test "$with_selinux" = "yes"; then
cfbba5b9 344 AC_DEFINE(WITH_SELINUX, 1, [Define to 1 if SELinux support is enabled])
2127e193
GI
345fi
346
a23d5117 347AC_ARG_WITH(libcap-ng,
d2e702cf 348 [AS_HELP_STRING([--with-libcap-ng@<:@=auto|yes|no@:>@], [Add Libcap-ng support to smartd [auto]])],
a7e8ffec 349 [], [with_libcap_ng=auto])
a23d5117
GI
350
351use_libcap_ng=no
352if test "$with_libcap_ng" != "no"; then
353 AC_CHECK_LIB(cap-ng, capng_clear,
a86ec89e 354 [AC_DEFINE(HAVE_LIBCAP_NG, 1, [Define to 1 if you have the `cap-ng' library (-lcap-ng).]) dnl `vim syntax
a23d5117
GI
355 CAPNG_LDADD="-lcap-ng"; use_libcap_ng=yes])
356
357 if test "$use_libcap_ng" = "yes"; then
358 AC_CHECK_HEADER(cap-ng.h, [], [AC_MSG_ERROR([libcap-ng libraries found but headers are missing])])
359 elif test "$with_libcap_ng" = "yes"; then
360 AC_MSG_ERROR([libcap-ng support was requested but the library was not found])
361 fi
362fi
363
364AC_MSG_CHECKING([whether to use libcap-ng])
365AC_SUBST(CAPNG_LDADD)
a23d5117
GI
366AC_MSG_RESULT([$use_libcap_ng])
367
a86ec89e
GI
368# TODO: Remove when NVMe support is no longer EXPERIMENTAL
369AC_ARG_WITH(nvme-devicescan,
370 [AS_HELP_STRING([--with-nvme-devicescan@<:@=yes|no@:>@],
371 [Include NVMe devices in smartd DEVICESCAN [no]])])
372AC_SUBST(with_nvme_devicescan)
373if test "$with_nvme_devicescan" = "yes"; then
374 AC_DEFINE(WITH_NVME_DEVICESCAN, 1, [Define to 1 to include NVMe devices in smartd DEVICESCAN.])
375fi
376
377AC_ARG_WITH(solaris-sparc-ata,
378 [AS_HELP_STRING([--with-solaris-sparc-ata@<:@=yes|no@:>@],
379 [Enable legacy ATA support on Solaris SPARC (requires os_solaris_ata.s from SVN repository) [no]])])
380
381case "$host:$with_solaris_sparc_ata" in
382 sparc-*-solaris*:yes)
383 if test ! -f "$srcdir/os_solaris_ata.s"; then
384 AC_MSG_ERROR([Missing source file: $srcdir/os_solaris_ata.s
385This file is no longer included in the source tarball but still
386available in the SVN repository.])
387 fi
388 AC_DEFINE(WITH_SOLARIS_SPARC_ATA, 1, [Define to 1 to enable legacy ATA support on Solaris SPARC.])
389 ;;
390esac
391
d2e702cf
GI
392# Assume broken snprintf only on Windows with MSVCRT (MinGW without ANSI stdio support)
393libc_have_working_snprintf=yes
394
395case "$host" in
396 *-*-mingw*)
397 case " $CPPFLAGS $CXXFLAGS" in
398 *\ -[[DU]]__USE_MINGW_ANSI_STDIO*)
399 ;;
400 *)
401 # Older MinGW do not properly define PRI?64 if __USE_MINGW_ANSI_STDIO is set
402 # Newer MinGW set __USE_MINGW_ANSI_STDIO in first C++ include which may be too late
403 AC_MSG_CHECKING([whether __USE_MINGW_ANSI_STDIO is defined by C++ includes])
404 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
405 #undef __USE_MINGW_ANSI_STDIO
406 #include <iostream>
407 #ifndef __USE_MINGW_ANSI_STDIO
408 #error false
409 #endif]])],
410 [CXXFLAGS="-D__USE_MINGW_ANSI_STDIO $CXXFLAGS"],
411 [libc_have_working_snprintf=no])
412 AC_MSG_RESULT([$libc_have_working_snprintf])
413 ;;
414 esac ;;
415esac
416
417AC_ARG_WITH(working-snprintf,
418 [AS_HELP_STRING([--with-working-snprintf@<:@=yes|no@:>@],
419 [Function snprintf() handles output truncation as specified by C99 [MinGW:guessed,others:yes]])],
420 [libc_have_working_snprintf=$withval])
421
422if test "$libc_have_working_snprintf" = "yes"; then
a86ec89e 423 AC_DEFINE(HAVE_WORKING_SNPRINTF, 1, [Define to 1 if the `snprintf' function is sane.]) dnl `vim syntax
d2e702cf
GI
424fi
425
f9e10201
JD
426AC_ARG_WITH(mingw-aslr,
427 [AS_HELP_STRING([--with-mingw-aslr@<:@=auto|yes|low|no@:>@], [Enable ASLR for MinGW executables [auto]])],
428 [], [with_mingw_aslr=auto])
429
430case "$host:${LDFLAGS+set}" in
431 *-*-mingw*:) # MinGW defaults: link statically and indicate DEP and TS compatibility
432 LDFLAGS="-static -Wl,--nxcompat,--tsaware" ;;
433esac
434
435case "$host:$with_mingw_aslr" in
436 x86_64-*-mingw*:auto)
437 AC_MSG_CHECKING([whether $CXX supports --high-entropy-va])
438 save_LDFLAGS=$LDFLAGS
439 LDFLAGS="$LDFLAGS -pie -Wl,--dynamicbase,-emainCRTStartup,--high-entropy-va,--image-base,0x140000000"
440 # Link libstdc++ to detect MinGW 6.3.0 problems with high --image-base
441 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
442 #include <string>
443 std::string s(42, '.');]])],
444 [with_mingw_aslr=yes], [with_mingw_aslr=no])
445 LDFLAGS=$save_LDFLAGS
446 AC_MSG_RESULT([$with_mingw_aslr])
447 test "$with_mingw_aslr" = "yes" || with_mingw_aslr=low
448 ;;
449esac
450
451case "$host:$with_mingw_aslr" in
452 x86_64-*-mingw*:yes)
453 LDFLAGS="$LDFLAGS -pie -Wl,--dynamicbase,-emainCRTStartup,--high-entropy-va,--image-base,0x140000000" ;;
454 x86_64-*-mingw*:low)
455 LDFLAGS="$LDFLAGS -pie -Wl,--dynamicbase,-emainCRTStartup" ;;
456 *-*-mingw*:auto|*-*-mingw*:yes|*-*-mingw*:low)
457 LDFLAGS="$LDFLAGS -pie -Wl,--dynamicbase,-e_mainCRTStartup" ;;
458esac
459
a86ec89e
GI
460os_win32_manifest=
461case "$host" in
462 *-*-mingw*)
463 # Newer MinGW may add a default manifest
f9e10201 464 AC_MSG_CHECKING([whether $CXX adds an application manifest])
a86ec89e
GI
465 cc_adds_manifest=no
466 AC_LINK_IFELSE([AC_LANG_PROGRAM()], [
467 if "$WINDRES" -O rc conftest.exe 2>/dev/null | grep '^1.*RT_MANIFEST' >/dev/null 2>&1; then
468 cc_adds_manifest=incomplete
469 # Manifest must provide a Win 10 compatibility ID
470 if "$WINDRES" -O rc conftest.exe 2>/dev/null | grep '{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}' >/dev/null 2>&1; then
471 cc_adds_manifest=yes
472 fi
473 fi],
474 [AC_MSG_ERROR([test compile failed])])
475 AC_MSG_RESULT([$cc_adds_manifest])
f9e10201 476 test "$cc_adds_manifest" = "yes" || os_win32_manifest='os_win32/default.manifest'
a86ec89e
GI
477 ;;
478esac
479
f9e10201
JD
480AC_ARG_WITH(cxx11-option,
481 [AS_HELP_STRING([--with-cxx11-option@<:@=OPTION|auto|no@:>@],
482 [Compiler option to enable C++11 support for future versions of smartmontools, 'no' if unsupported [auto]])],
483 [], [with_cxx11_option=auto])
484
485check_cxx11_support()
486{
487 save_CXXFLAGS=$CXXFLAGS
488 CXXFLAGS=$1
489 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
490 #if __cplusplus < 201103L
491 #error false
492 #endif
493 // use some C++11 features (and return v * 42 :-)
494 auto cxx11(long v) noexcept -> decltype(v) {
495 typedef decltype(v) t; t r = v;
496 static const t a[] = { -7, -1, 1, 2, 3 };
497 static_assert(sizeof(r) == sizeof(a[0]), "fail");
498 auto f = [](t x, t y){ return x * y; };
499 for (const auto & e : a) r = f(r, e);
500 return r;
501 }]])],
502 [CXXFLAGS=$save_CXXFLAGS; return 0], [CXXFLAGS=$save_CXXFLAGS; return 1])
503}
504
505case "$with_cxx11_option" in
506 no) ;;
507 auto)
508 AC_MSG_CHECKING([for $CXX option to accept C++11])
509 with_cxx11_option=unknown
510 for option in "" "-std=gnu++11" "-std=gnu++0x" "-std=c++11" "-std=c++0x"; do
511 if check_cxx11_support "$option"; then with_cxx11_option=$option; break; fi
512 done
513 AC_MSG_RESULT([${with_cxx11_option:-none needed}])
514 test "$with_cxx11_option" != "unknown" || AC_MSG_ERROR([
515This version of smartmontools does not use C++11 features, but future
516versions possibly will.
517This script was unable to determine a compiler option to enable C++11.
518Use option '--with-cxx11-option=OPTION' to specify the compiler option
519(it will be checked, but not used in the actual build).
520Use option '--without-cxx11-option' to suppress this error message if the
521compiler lacks C++11 support.
522In both cases, please send info about compiler and platform to
523$PACKAGE_BUGREPORT - Thanks!])
524 ;;
525 *)
526 AC_MSG_CHECKING([whether $CXX $with_cxx11_option accepts C++11])
527 res=no; check_cxx11_support "$with_cxx11_option" && res=yes
528 AC_MSG_RESULT([$res])
529 test "$res" = "yes" || AC_MSG_ERROR([$CXX $with_cxx11_option does not accept C++11])
530 ;;
531esac
832b75ed 532
a86ec89e 533
832b75ed
GG
534AC_SUBST(releaseversion,['${PACKAGE}-${VERSION}'])
535AC_SUBST(smartmontools_release_date)
536AC_SUBST(smartmontools_release_time)
537
cfbba5b9
GI
538# Set platform-specific modules and symbols
539os_libs=
a86ec89e 540os_dltools='curl wget lynx svn'
ee38a438
GI
541os_mailer=mail
542os_hostname="'hostname'"
543os_dnsdomainname=
544os_nisdomainname="'domainname'"
cfbba5b9
GI
545os_darwin=no
546os_solaris=no
547os_win32=no
548os_win32_mingw=no
7f0798ef 549os_win64=no
d008864d 550os_man_filter=
832b75ed 551case "${host}" in
cfbba5b9 552 *-*-linux*)
ee38a438
GI
553 os_deps='os_linux.o cciss.o dev_areca.o'
554 os_dnsdomainname="'dnsdomainname' 'hostname -d'"
555 os_nisdomainname="'nisdomainname' 'hostname -y' 'domainname'"
d008864d 556 os_man_filter=Linux
cfbba5b9
GI
557 ;;
558 *-*-freebsd*|*-*-dragonfly*|*-*-kfreebsd*-gnu*)
ee38a438 559 os_deps='os_freebsd.o cciss.o dev_areca.o'
cfbba5b9 560 os_libs='-lcam'
a86ec89e 561 os_dltools='curl wget lynx fetch svn'
cfbba5b9 562 AC_CHECK_LIB(usb, libusb20_dev_get_device_desc)
d008864d 563 os_man_filter=FreeBSD
cfbba5b9
GI
564 ;;
565 sparc-*-solaris*)
a86ec89e
GI
566 os_deps='os_solaris.o'
567 test "$with_solaris_sparc_ata" = "yes" \
568 && os_deps="$os_deps os_solaris_ata.o"
cfbba5b9
GI
569 os_mailer='mailx'
570 os_solaris=yes
d008864d 571 os_man_filter=Solaris
cfbba5b9
GI
572 ;;
573 *-pc-solaris*)
574 os_deps='os_solaris.o'
575 os_mailer='mailx'
576 os_solaris=yes
d008864d 577 os_man_filter=Solaris
cfbba5b9
GI
578 ;;
579 *-*-netbsd*)
580 os_deps='os_netbsd.o'
581 os_libs='-lutil'
d008864d 582 os_man_filter=NetBSD
cfbba5b9
GI
583 ;;
584 *-*-openbsd*)
585 os_deps='os_openbsd.o'
586 os_libs='-lutil'
a86ec89e 587 os_dltools='curl wget lynx ftp svn'
d008864d 588 os_man_filter=OpenBSD
cfbba5b9
GI
589 ;;
590 *-*-cygwin*)
ee38a438 591 os_deps='os_win32.o dev_areca.o'
d2e702cf 592 os_mailer='email'
ee38a438
GI
593 os_hostname="'hostname' 'echo "'"${HOSTNAME?unset}"'"'"
594 os_dnsdomainname="'dnsdomainname' 'hostname -d' 'echo "'"${USERDNSDOMAIN?unset}"'"'"
595 os_nisdomainname=
cfbba5b9 596 os_win32=yes
d008864d 597 os_man_filter=Cygwin
cfbba5b9
GI
598 ;;
599 x86_64-*-mingw*)
ee38a438 600 os_deps='os_win32.o dev_areca.o'
cfbba5b9
GI
601 os_win32=yes
602 os_win32_mingw=yes
603 os_win64=yes
d008864d 604 os_man_filter=Windows
cfbba5b9
GI
605 ;;
606 *-*-mingw*)
ee38a438 607 os_deps='os_win32.o dev_areca.o'
cfbba5b9
GI
608 os_win32=yes
609 os_win32_mingw=yes
d008864d 610 os_man_filter=Windows
cfbba5b9
GI
611 ;;
612 *-*-darwin*)
613 os_deps='os_darwin.o'
614 os_libs='-framework CoreFoundation -framework IOKit'
615 os_darwin=yes
d008864d 616 os_man_filter=Darwin
cfbba5b9
GI
617 ;;
618 *-*-nto-qnx*)
619 os_deps='os_qnxnto.o'
620 ;;
f9e10201
JD
621 *-*-os2-*)
622 os_deps='os_os2.o'
623 ;;
cfbba5b9
GI
624 *)
625 os_deps='os_generic.o'
626 ;;
832b75ed
GG
627esac
628
2127e193
GI
629# Replace if '--with-os-deps' was specified
630test -z "$with_os_deps" || os_deps="$with_os_deps"
832b75ed 631
2127e193
GI
632# Check if we need adapter to old interface (dev_legacy.cpp)
633os_src=`echo "${os_deps}"|sed -n 's,^\([[^ .]]*\)\.o.*$,\1.cpp,p'`
634AC_MSG_CHECKING([whether ${os_src} uses new interface])
635if grep "smart_interface" "${srcdir}/${os_src}" >/dev/null 2>&1; then
636 os_new_interface=yes
637else
638 os_new_interface=no
639 os_deps="${os_deps} dev_legacy.o"
640 AC_DEFINE(OLD_INTERFACE, 1, [Define to 1 if os_*.cpp still uses the old interface])
641fi
642AC_MSG_RESULT([$os_new_interface])
643
cfbba5b9
GI
644AC_SUBST([os_deps])
645AC_SUBST([os_libs])
646AC_SUBST([os_dltools])
ee38a438
GI
647AC_SUBST([os_mailer])
648AC_SUBST([os_hostname])
649AC_SUBST([os_dnsdomainname])
650AC_SUBST([os_nisdomainname])
d008864d 651AC_SUBST([os_man_filter])
a86ec89e 652AC_SUBST([os_win32_manifest])
cfbba5b9
GI
653
654# Create drivedb.h update branch name from version: 5.41[.X] -> RELEASE_5_41_DRIVEDB
f9e10201 655DRIVEDB_BRANCH=`echo "$drivedb_version" | sed 's,^\([[0-9]]*\.[[0-9]]*\)\..*$,\1,' \
cfbba5b9
GI
656 | sed -n 's,^\([[0-9]][[0-9]]*\)\.\([[0-9]][[0-9]]*\)$,RELEASE_\1_\2_DRIVEDB,p'`
657if test -z "$DRIVEDB_BRANCH"; then
f9e10201 658 AC_MSG_ERROR([Unable to create DRIVEDB_BRANCH for version: $drivedb_version])
cfbba5b9
GI
659fi
660AC_SUBST([DRIVEDB_BRANCH])
661
662# Enable platform-specific makefile sections
663AM_CONDITIONAL(OS_DARWIN, [test "$os_darwin" = "yes"])
664AM_CONDITIONAL(OS_SOLARIS, [test "$os_solaris" = "yes"])
665AM_CONDITIONAL(OS_WIN32, [test "$os_win32" = "yes"])
666AM_CONDITIONAL(OS_WIN32_MINGW, [test "$os_win32_mingw" = "yes"])
667AM_CONDITIONAL(OS_WIN32_NSIS, [test -n "$MAKENSIS"])
7f0798ef 668AM_CONDITIONAL(OS_WIN64, [test "$os_win64" = "yes"])
832b75ed 669
bed94269 670if test "$GXX" = "yes"; then
f9e10201
JD
671 # Add -Wall and -W[extra] if its not already specified
672 case " $CXXFLAGS " in
673 *\ -Wall\ *) ;;
674 *) CXXFLAGS="$CXXFLAGS -Wall" ;;
675 esac
676 case " $CXXFLAGS " in
677 *\ -W\ *|*\ -Wextra\ *) ;;
678 *) CXXFLAGS="$CXXFLAGS -W" ;;
679 esac
680 # Add -Wformat=2 (GCC 3.0) -fstack-protector[-strong] (GCC 4.1[4.9]) if supported
681 # and CXXFLAGS was not set in configure cmdline (TODO: -Wformat-signedness)
682 case "${ac_test_CXXFLAGS+set}:$ac_test_CXXFLAGS" in
683 set:)
684 for option in "-Wformat=2" "-fstack-protector-strong" "-fstack-protector"; do
685 case " $CXXFLAGS:$option" in *\ -fstack-p*:-fstack-p*) continue ;; esac
686 AC_MSG_CHECKING([whether $CXX supports $option])
687 save_CXXFLAGS=$CXXFLAGS
688 CXXFLAGS="$CXXFLAGS $option"
689 AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [res=yes], [res=no; CXXFLAGS=$save_CXXFLAGS])
690 AC_MSG_RESULT([$res])
691 done
692 ;;
693 esac
832b75ed 694else
f9e10201
JD
695 # We are NOT using gcc, so enable host-specific compiler flags
696 case "${host}" in
697 sparc*-*-solaris*)
698 # Tell the Solaris/SPARC C++ compiler about packed ATA structures
699 case " $CXXFLAGS" in
700 *\ -xmemalign*) ;;
701 *) CXXFLAGS="-xmemalign=1i $CXXFLAGS" ;;
702 esac ;;
703 esac
704 case "${host}" in
705 *-*-solaris*)
706 # Turn on optimization if user has not explicitly set its value
707 case " $CXXFLAGS" in
708 *\ -xO*) ;;
709 *) CXXFLAGS="-xO2 $CXXFLAGS" ;;
710 esac
711 # Suppress trivial warnings
712 case " $CXXFLAGS" in
713 *\ -erroff*) ;;
714 *) CXXFLAGS="-erroff=%none,wbadinitl,wbadasgl,badargtypel2w,badargtype2w $CXXFLAGS" ;;
715 esac ;;
716 esac
832b75ed
GG
717fi
718
719AC_DEFINE_UNQUOTED(SMARTMONTOOLS_BUILD_HOST, "${host}", [smartmontools Build Host])
720
4d59bff9 721AC_SUBST(CXXFLAGS)
832b75ed 722
cfbba5b9
GI
723AC_CONFIG_FILES(Makefile)
724AC_OUTPUT
832b75ed 725AC_PROG_MAKE_SET
a23d5117 726
a86ec89e
GI
727# Note: Use `...` here as some shells do not properly parse '$(... case $x in X) ...)'
728info=`
729 echo "-----------------------------------------------------------------------------"
730 echo "${PACKAGE}-${VERSION} configuration:"
731 echo "host operating system: $host"
732 echo "C++ compiler: $CXX"
733 echo "C compiler: $CC"
734 echo "preprocessor flags: $CPPFLAGS"
735 echo "C++ compiler flags: $CXXFLAGS"
736 echo "C compiler flags: $CFLAGS"
737 echo "linker flags: $LDFLAGS"
738 echo "OS specific modules: $os_deps $os_libs $LIBS"
739
740 case "$host_os" in
741 mingw*)
742 echo "application manifest: ${os_win32_manifest:-built-in}"
743 echo "resource compiler: $WINDRES"
744 echo "message compiler: $WINDMC"
745 echo "NSIS compiler: $MAKENSIS"
746 if test -n "$drivedbdir"; then
747 echo "drive database file: EXEDIR/drivedb.h"
748 if test -n "$MAKENSIS"; then
749 echo "database update tool: EXEDIR/update-smart-drivedb.exe"
750 fi
751 else
752 echo "drive database file: [[disabled]]"
cfbba5b9 753 fi
a86ec89e
GI
754 if test -n "$savestates"; then
755 echo "smartd save files: \`eval eval eval echo $savestates\`MODEL-SERIAL.TYPE.state"
756 fi
757 if test -n "$attributelog"; then
758 echo "smartd attribute logs: \`eval eval eval echo $attributelog\`MODEL-SERIAL.TYPE.csv"
759 fi
760 echo "NVMe DEVICESCAN: ${with_nvme_devicescan-no}"
761 ;;
762
763 *)
764 echo "binary install path: \`eval eval eval echo $sbindir\`"
765 echo "man page install path: \`eval eval eval echo $mandir\`"
766 echo "doc file install path: \`eval eval eval echo $docdir\`"
767 echo "examples install path: \`eval eval eval echo $exampledir\`"
768 if test -n "$drivedbdir"; then
769 echo "drive database file: \`eval eval eval echo $drivedbdir\`/drivedb.h"
770 if test "$with_update_smart_drivedb" = "yes"; then
771 echo "database update script: \`eval eval eval echo $sbindir\`/update-smart-drivedb"
f9e10201
JD
772 if test "$drivedb_version" != "$VERSION"; then
773 echo "... backported to: branches/$DRIVEDB_BRANCH"
774 fi
a86ec89e 775 echo "download tools: \`eval eval eval echo $os_dltools\`"
f9e10201
JD
776 if test -n "$gnupg"; then
777 echo "GnuPG for verification: \`eval eval eval echo $gnupg\`"
778 else
779 echo "GnuPG for verification: [[disabled]]"
780 fi
a86ec89e
GI
781 else
782 echo "database update script: [[disabled]]"
783 fi
d2e702cf 784 else
a86ec89e 785 echo "drive database file: [[disabled]]"
d2e702cf 786 fi
a86ec89e
GI
787 echo "local drive database: \`eval eval eval echo $sysconfdir\`/smart_drivedb.h"
788 echo "smartd config file: \`eval eval eval echo $sysconfdir\`/smartd.conf${smartd_suffix}"
789 echo "smartd warning script: \`eval eval eval echo $smartdscriptdir\`/smartd_warning.sh"
790 if test -n "$smartdplugindir"; then
791 echo "smartd plugin path: \`eval eval eval echo $smartdplugindir\`"
792 else
793 echo "smartd plugin path: [[disabled]]"
794 fi
f9e10201
JD
795 if test -n "$scriptpath"; then
796 echo "PATH within scripts: \`eval eval eval echo $scriptpath\`"
797 else
798 echo "PATH within scripts: [[inherited]]"
799 fi
a86ec89e
GI
800 if test -n "$initddir"; then
801 echo "smartd initd script: \`eval eval eval echo $initddir\`/${initdfile}"
802 elif test -z "$systemdsystemunitdir"; then
803 echo "smartd initd script: [[disabled]]"
804 fi
805 if test -n "$systemdsystemunitdir"; then
806 echo "smartd systemd file: \`eval eval eval echo $systemdsystemunitdir\`/smartd.service"
807 if test -n "$systemdenvfile"; then
808 echo "smartd environ file: \`eval eval eval echo $systemdenvfile\`"
809 else
810 echo "smartd environ file: [[disabled]]"
811 fi
812 fi
813 if test -n "$savestates"; then
814 echo "smartd save files: \`eval eval eval echo $savestates\`MODEL-SERIAL.TYPE.state"
815 else
816 echo "smartd save files: [[disabled]]"
817 fi
818 if test -n "$attributelog"; then
819 echo "smartd attribute logs: \`eval eval eval echo $attributelog\`MODEL-SERIAL.TYPE.csv"
820 else
821 echo "smartd attribute logs: [[disabled]]"
822 fi
823 echo "libcap-ng support: $use_libcap_ng"
824 case "$host_os" in
825 linux*) echo "SELinux support: ${with_selinux-no}" ;;
826 esac
827 case "$host_os" in
f9e10201
JD
828 linux*|darwin*|netbsd*|cygwin*)
829 echo "NVMe DEVICESCAN: ${with_nvme_devicescan-no}" ;;
a86ec89e
GI
830 esac
831 ;;
832 esac
833 echo "-----------------------------------------------------------------------------"
834`
835
836AC_MSG_NOTICE([
837$info
838])
839
840# TODO: Remove when NVMe support is no longer EXPERIMENTAL
841case "$host_os:${with_nvme_devicescan+set}" in
f9e10201 842 linux*:|darwin*:|netbsd*:|cygwin*:|mingw*:)
a86ec89e
GI
843 AC_MSG_WARN([
844This version of smartmontools provides NVMe support which is still
845EXPERIMENTAL. NVMe devices are not yet included in smartd.conf
846'DEVICESCAN' and 'smartctl --scan' unless '-d nvme' is specified.
847Use option '--with-nvme-devicescan' to include NVMe devices.
f9e10201
JD
848Use option '--without-nvme-devicescan' to suppress this warning.
849])
a86ec89e
GI
850 ;;
851esac
852
f9e10201 853# TODO: Remove after smartmontools 6.6
a86ec89e
GI
854case "$host:${with_solaris_sparc_ata+set}" in
855 sparc-*-solaris*:)
856 AC_MSG_WARN([
857Legacy ATA support is no longer enabled by default on Solaris SPARC.
858The required source file 'os_solaris_ata.s' is no longer included in
859the source tarball but still available in the SVN repository.
860Use option '--with-solaris-sparc-ata' to enable legacy ATA support.
f9e10201
JD
861Use option '--without-solaris-sparc-ata' to suppress this warning.
862])
e9583e0c
GI
863 ;;
864esac