• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1AC_INIT(sg3_utils, 1.48, dgilbert@interlog.com)
2
3AM_INIT_AUTOMAKE([-Wall -Werror foreign])
4AM_MAINTAINER_MODE
5AM_CONFIG_HEADER(config.h)
6
7AC_PROG_CC
8# AC_PROG_CXX
9AC_PROG_INSTALL
10
11# AM_PROG_AR is supported and needed since automake v1.12+
12ifdef([AM_PROG_AR], [AM_PROG_AR], [])
13
14# Adding libtools to the build seems to bring in C++ environment
15AC_PROG_LIBTOOL
16
17# check for headers
18AC_HEADER_STDC
19AC_CHECK_HEADERS([byteswap.h stdatomic.h], [], [], [])
20
21# check for functions
22AC_CHECK_FUNCS(getopt_long,
23	       GETOPT_O_FILES='',
24	       GETOPT_O_FILES='getopt_long.o')
25AC_CHECK_FUNCS(posix_fadvise)
26AC_CHECK_FUNCS(posix_memalign)
27AC_CHECK_FUNCS(gettimeofday)
28AC_CHECK_FUNCS(sysconf)
29AC_CHECK_FUNCS(lseek64)
30AC_CHECK_FUNCS(srand48_r)
31SAVED_LIBS=$LIBS
32AC_SEARCH_LIBS([pthread_create], [pthread])
33# AC_SEARCH_LIBS adds libraries at the start of $LIBS so remove $SAVED_LIBS
34# from the end of $LIBS.
35pthread_lib=${LIBS%${SAVED_LIBS}}
36AC_CHECK_FUNCS([pthread_cancel pthread_kill])
37LIBS=$SAVED_LIBS
38AC_SUBST(PTHREAD_LIB, [$pthread_lib])
39
40SAVED_LIBS=$LIBS
41AC_SEARCH_LIBS([clock_gettime], [rt])
42rt_lib=${LIBS%${SAVED_LIBS}}
43AC_CHECK_FUNCS(clock_gettime)
44LIBS=$SAVED_LIBS
45AC_SUBST(RT_LIB, [$rt_lib])
46
47AC_SUBST(GETOPT_O_FILES)
48
49
50AC_CANONICAL_HOST
51
52AC_DEFINE_UNQUOTED(SG_LIB_BUILD_HOST, "${host}", [sg3_utils Build Host])
53
54check_for_getrandom() {
55	AC_CHECK_HEADERS([sys/random.h], [AC_DEFINE_UNQUOTED(HAVE_GETRANDOM, 1, [Found sys/random.h])], [], [])
56}
57
58check_for_linux_nvme_headers() {
59	AC_CHECK_HEADERS([linux/nvme_ioctl.h], [AC_DEFINE_UNQUOTED(HAVE_NVME, 1, [Found NVMe])], [], [])
60	AC_CHECK_HEADERS([linux/types.h linux/bsg.h linux/kdev_t.h], [], [],
61		     [[#ifdef HAVE_LINUX_TYPES_H
62		     # include <linux/types.h>
63		     #endif
64		     ]])
65}
66
67check_for_linux_sg_v4_hdr() {
68	AC_EGREP_CPP(found,
69		[ # include <scsi/sg.h>
70		  #ifdef SG_IOSUBMIT
71		   found
72		  #endif
73		],
74		[AC_DEFINE_UNQUOTED(HAVE_LINUX_SG_V4_HDR, 1, [Have Linux sg v4 header]) ])
75}
76
77case "${host}" in
78	*-*-android*)
79		AC_DEFINE_UNQUOTED(SG_LIB_ANDROID, 1, [sg3_utils on android])
80		AC_DEFINE_UNQUOTED(SG_LIB_LINUX, 1, [sg3_utils on linux])
81		check_for_linux_sg_v4_hdr
82		check_for_getrandom
83		check_for_linux_nvme_headers;;
84        *-*-freebsd*|*-*-kfreebsd*-gnu*)
85		AC_DEFINE_UNQUOTED(SG_LIB_FREEBSD, 1, [sg3_utils on FreeBSD])
86		AC_DEFINE_UNQUOTED(HAVE_NVME, 1, [Found NVMe])
87		check_for_getrandom
88                LIBS="$LIBS -lcam";;
89        *-*-solaris*)
90		AC_DEFINE_UNQUOTED(SG_LIB_SOLARIS, 1, [sg3_utils on Solaris]);;
91        *-*-netbsd*)
92		AC_DEFINE_UNQUOTED(SG_LIB_NETBSD, 1, [sg3_utils on NetBSD]);;
93        *-*-openbsd*)
94		AC_DEFINE_UNQUOTED(SG_LIB_OPENBSD, 1, [sg3_utils on OpenBSD]);;
95        *-*-osf*)
96		AC_DEFINE_UNQUOTED(SG_LIB_OSF1, 1, [sg3_utils on Tru64 UNIX]);;
97        *-*-cygwin*)
98		AC_DEFINE_UNQUOTED(SG_LIB_WIN32, 1, [sg3_utils on Win32])
99		# AC_CHECK_HEADERS([nvme.h], [AC_DEFINE_UNQUOTED(HAVE_NVME, 1, [Found NVMe])], [], [])
100		AC_DEFINE_UNQUOTED(HAVE_NVME, 1, [Found NVMe])
101		check_for_getrandom
102                CFLAGS="$CFLAGS -Wno-char-subscripts";;
103        *-*-mingw* | *-*-msys*)
104		AC_DEFINE_UNQUOTED(SG_LIB_WIN32, 1, [sg3_utils on Win32])
105		AC_DEFINE_UNQUOTED(SG_LIB_MINGW, 1, [also MinGW environment])
106		# AC_CHECK_HEADERS([nvme.h], [AC_DEFINE_UNQUOTED(HAVE_NVME, 1, [Found NVMe])], [], [])
107		AC_DEFINE_UNQUOTED(HAVE_NVME, 1, [Found NVMe])
108		check_for_getrandom
109                CFLAGS="$CFLAGS -D__USE_MINGW_ANSI_STDIO";;
110        *-*-linux-gnu* | *-*-linux* | *-*-uclinux-gnu* | *-*-uclinux*)
111                AC_DEFINE_UNQUOTED(SG_LIB_LINUX, 1, [sg3_utils on linux])
112		check_for_linux_sg_v4_hdr
113		check_for_getrandom
114                check_for_linux_nvme_headers;;
115        *-*-haiku*)
116		AC_DEFINE_UNQUOTED(SG_LIB_HAIKU, 1, [sg3_utils on Haiku])
117                AC_SUBST([os_cflags], [''])
118                AC_SUBST([os_libs], ['']) ;;
119        *)
120                AC_DEFINE_UNQUOTED(SG_LIB_OTHER, 1, [sg3_utils on other])
121		isother=yes;;
122esac
123
124# Define platform-specific symbol.
125AM_CONDITIONAL(OS_FREEBSD, [echo $host_os | grep 'freebsd' > /dev/null])
126AM_CONDITIONAL(OS_LINUX, [echo $host_os | grep -E '^(uc)?linux' > /dev/null])
127AM_CONDITIONAL(OS_OSF, [echo $host_os | grep '^osf' > /dev/null])
128AM_CONDITIONAL(OS_SOLARIS, [echo $host_os | grep '^solaris' > /dev/null])
129AM_CONDITIONAL(OS_WIN32_MINGW, [echo $host_os | grep '^mingw' > /dev/null])
130AM_CONDITIONAL(OS_WIN32_CYGWIN, [echo $host_os | grep '^cygwin' > /dev/null])
131AM_CONDITIONAL(OS_ANDROID, [echo $host_os | grep 'android' > /dev/null])
132AM_CONDITIONAL(OS_NETBSD, [echo $host_os | grep 'netbsd' > /dev/null])
133AM_CONDITIONAL(OS_OPENBSD, [echo $host_os | grep 'openbsd' > /dev/null])
134AM_CONDITIONAL(OS_HAIKU, [echo $host_os | grep '^haiku' > /dev/null])
135AM_CONDITIONAL(OS_OTHER, [test "x$isother" = "xyes"])
136
137AC_ARG_ENABLE([debug],
138	      [  --enable-debug          Turn on debugging],
139	      [case "${enableval}" in
140		  yes) debug=true ;;
141		  no)  debug=false ;;
142		  *) AC_MSG_ERROR([bad value ${enableval} for --enable-debug]) ;;
143	       esac],[debug=false])
144AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
145
146AC_ARG_ENABLE([pt_dummy],
147	      [  --enable-pt_dummy       pass-through codes compiles, does nothing],
148	      [case "${enableval}" in
149		  yes) pt_dummy=true ;;
150		  no)  pt_dummy=false ;;
151		  *) AC_MSG_ERROR([bad value ${enableval} for --enable-dummy_pt]) ;;
152	       esac],[pt_dummy=false])
153AM_CONDITIONAL([PT_DUMMY], [test x$pt_dummy = xtrue])
154
155AC_ARG_ENABLE([linuxbsg],
156  AC_HELP_STRING([--disable-linuxbsg], [option ignored, this is placeholder]),
157  [AC_DEFINE_UNQUOTED(IGNORE_LINUX_BSG, 1, [option ignored], )], [])
158
159AC_ARG_ENABLE([win32-spt-direct],
160  AC_HELP_STRING([--enable-win32-spt-direct], [enable Win32 SPT Direct]),
161  AC_DEFINE_UNQUOTED(WIN32_SPT_DIRECT, 1, [enable Win32 SPT Direct], )
162)
163
164AC_ARG_ENABLE([scsistrings],
165  [AS_HELP_STRING([--disable-scsistrings],
166		  [Disable full SCSI sense strings and NVMe status strings])],
167  [], [AC_DEFINE_UNQUOTED(SG_SCSI_STRINGS, 1, [full SCSI sense strings and NVMe status strings], )])
168
169AC_ARG_ENABLE([nvme-supp],
170  AC_HELP_STRING([--disable-nvme-supp], [remove all or most NVMe code]),
171  [AC_DEFINE_UNQUOTED(IGNORE_NVME, 1, [compile out NVMe support], )], [])
172
173AC_ARG_ENABLE([fast-lebe],
174  AC_HELP_STRING([--disable-fast-lebe], [use generic little-endian/big-endian code instead]),
175  [AC_DEFINE_UNQUOTED(IGNORE_FAST_LEBE, 1, [use generic little-endian/big-endian instead], )], [])
176
177AC_ARG_ENABLE([linux-sgv4],
178  AC_HELP_STRING([--disable-linux-sgv4], [for Linux sg driver avoid v4 interface even if available]),
179  [AC_DEFINE_UNQUOTED(IGNORE_LINUX_SGV4, 1, [even if Linux sg v4 available, use v3 instead], )], [])
180
181
182AC_OUTPUT(
183	Makefile
184	include/Makefile
185	lib/Makefile
186	src/Makefile
187	doc/Makefile
188	scripts/Makefile
189)
190
191
192# Borrowed from smartmontools configure.ac
193# Note: Use `...` here as some shells do not properly parse '$(... case $x in X) ...)'
194info=`
195  echo "-----------------------------------------------------------------------------"
196  echo "${PACKAGE}-${VERSION} configuration:"
197  echo "host operating system:  $host"
198  echo "default C compiler:     $CC"
199
200  case "$host_os" in
201    mingw*)
202      echo "application manifest:   ${os_win32_manifest:-built-in}"
203      echo "resource compiler:      $WINDRES"
204      echo "message compiler:       $WINDMC"
205      echo "NSIS compiler:          $MAKENSIS"
206      ;;
207
208    *)
209      echo "binary install path:    \`eval eval eval echo $bindir\`"
210      echo "scripts install path:   \`eval eval eval echo $bindir\`"
211      echo "man page install path:  \`eval eval eval echo $mandir\`"
212      ;;
213  esac
214  echo "-----------------------------------------------------------------------------"
215`
216
217AC_MSG_NOTICE([
218$info
219])
220
221