xref: /aosp_15_r20/external/kmod/configure.ac (revision cc4ad7da8cefe208cb129ac2aa9a357c7c72deb2)
1AC_PREREQ(2.64)
2AC_INIT([kmod],
3	[32],
4	[[email protected]],
5	[kmod],
6	[http://git.kernel.org/?p=utils/kernel/kmod/kmod.git])
7
8AC_CONFIG_SRCDIR([libkmod/libkmod.c])
9AC_CONFIG_MACRO_DIR([m4])
10AC_CONFIG_HEADERS(config.h)
11AC_CONFIG_AUX_DIR([build-aux])
12
13AC_USE_SYSTEM_EXTENSIONS
14AC_SYS_LARGEFILE
15AC_PREFIX_DEFAULT([/usr])
16AM_MAINTAINER_MODE([enable])
17AM_INIT_AUTOMAKE([check-news foreign 1.11 silent-rules tar-pax no-dist-gzip dist-xz subdir-objects color-tests parallel-tests])
18AM_SILENT_RULES([yes])
19LT_INIT([disable-static pic-only])
20
21AS_IF([test "x$enable_static" = "xyes"], [AC_MSG_ERROR([--enable-static is not supported by kmod])])
22AS_IF([test "x$enable_largefile" = "xno"], [AC_MSG_ERROR([--disable-largefile is not supported by kmod])])
23
24module_compressions=""
25module_signatures="legacy"
26
27#####################################################################
28# Program checks and configurations
29#####################################################################
30
31AC_PROG_SED
32AC_PROG_MKDIR_P
33AC_PROG_LN_S
34PKG_PROG_PKG_CONFIG
35AC_PATH_PROG([XSLTPROC], [xsltproc])
36
37AC_PROG_CC_C99
38
39#####################################################################
40# Function and structure checks
41#####################################################################
42
43AC_CHECK_FUNCS_ONCE(__xstat)
44AC_CHECK_FUNCS_ONCE([__secure_getenv secure_getenv])
45AC_CHECK_FUNCS_ONCE([finit_module])
46
47CC_CHECK_FUNC_BUILTIN([__builtin_clz])
48CC_CHECK_FUNC_BUILTIN([__builtin_types_compatible_p])
49CC_CHECK_FUNC_BUILTIN([__builtin_uaddl_overflow], [ ], [ ])
50CC_CHECK_FUNC_BUILTIN([__builtin_uaddll_overflow], [ ], [ ])
51
52# dietlibc doesn't have st.st_mtim struct member
53AC_CHECK_MEMBERS([struct stat.st_mtim], [], [], [#include <sys/stat.h>])
54
55# musl 1.0 and bionic 4.4 don't have strndupa
56AC_CHECK_DECLS_ONCE([strndupa])
57
58# RHEL 5 and older do not have be32toh
59AC_CHECK_DECLS_ONCE([be32toh])
60
61# Check kernel headers
62AC_CHECK_HEADERS_ONCE([linux/module.h])
63
64AC_MSG_CHECKING([whether _Static_assert() is supported])
65AC_COMPILE_IFELSE(
66	[AC_LANG_SOURCE([[_Static_assert(1, "Test");]])],
67        [AC_DEFINE([HAVE_STATIC_ASSERT], [1], [Define if _Static_assert() is available])
68	 AC_MSG_RESULT([yes])],
69	[AC_MSG_RESULT([no])])
70
71AC_MSG_CHECKING([whether _Noreturn is supported])
72AC_COMPILE_IFELSE(
73	[AC_LANG_SOURCE([[#include <stdlib.h>
74	_Noreturn int foo(void) { exit(0); }]])],
75        [AC_DEFINE([HAVE_NORETURN], [1], [Define if _Noreturn is available])
76	 AC_MSG_RESULT([yes])],
77	[AC_MSG_RESULT([no])])
78
79
80#####################################################################
81# --with-
82#####################################################################
83
84AC_ARG_WITH([distconfdir], AS_HELP_STRING([--with-distconfdir=DIR], [directory to search for distribution configuration files]),
85        [], [with_distconfdir='${prefix}/lib'])
86AC_SUBST([distconfdir], [$with_distconfdir])
87
88AC_ARG_WITH([rootlibdir],
89        AS_HELP_STRING([--with-rootlibdir=DIR], [rootfs directory to install shared libraries]),
90        [], [with_rootlibdir=$libdir])
91AC_SUBST([rootlibdir], [$with_rootlibdir])
92
93# Ideally this would be $prefix/lib/modules but default to /lib/modules for compatibility with earlier versions
94AC_ARG_WITH([module_directory],
95        AS_HELP_STRING([--with-module-directory=DIR], [directory in which to look for kernel modules @<:@default=/lib/modules@:>@]),
96        [], [with_module_directory=/lib/modules])
97AC_SUBST([module_directory], [$with_module_directory])
98
99# Check all directory arguments for consistency.
100for ac_var in	distconfdir rootlibdir module_directory
101do
102  eval ac_val=\$$ac_var
103  # Remove trailing slashes.
104  case $ac_val in
105    */ )
106      ac_val=`expr "X$ac_val" : 'X\(.*@<:@^/@:>@\)' \| "X$ac_val" : 'X\(.*\)'`
107      eval $ac_var=\$ac_val;;
108  esac
109  # Be sure to have absolute directory names.
110  case $ac_val in
111    @<:@\\/$@:>@* | ?:@<:@\\/@:>@* )  continue;;
112  esac
113  as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val"
114done
115
116AC_ARG_WITH([zstd],
117	AS_HELP_STRING([--with-zstd], [handle Zstandard-compressed modules @<:@default=disabled@:>@]),
118	[], [with_zstd=no])
119AS_IF([test "x$with_zstd" != "xno"], [
120	PKG_CHECK_MODULES([libzstd], [libzstd >= 1.4.4], [LIBS="$LIBS $libzstd_LIBS"])
121	AC_DEFINE([ENABLE_ZSTD], [1], [Enable Zstandard for modules.])
122	module_compressions="zstd $module_compressions"
123], [
124	AC_MSG_NOTICE([Zstandard support not requested])
125])
126CC_FEATURE_APPEND([with_features], [with_zstd], [ZSTD])
127
128AC_ARG_WITH([xz],
129	AS_HELP_STRING([--with-xz], [handle Xz-compressed modules @<:@default=disabled@:>@]),
130	[], [with_xz=no])
131AS_IF([test "x$with_xz" != "xno"], [
132	PKG_CHECK_MODULES([liblzma], [liblzma >= 4.99], [LIBS="$LIBS $liblzma_LIBS"])
133	AC_DEFINE([ENABLE_XZ], [1], [Enable Xz for modules.])
134	module_compressions="xz $module_compressions"
135], [
136	AC_MSG_NOTICE([Xz support not requested])
137])
138CC_FEATURE_APPEND([with_features], [with_xz], [XZ])
139
140AC_ARG_WITH([zlib],
141	AS_HELP_STRING([--with-zlib], [handle gzipped modules @<:@default=disabled@:>@]),
142	[], [with_zlib=no])
143AS_IF([test "x$with_zlib" != "xno"], [
144	PKG_CHECK_MODULES([zlib], [zlib], [LIBS="$LIBS $zlib_LIBS"])
145	AC_DEFINE([ENABLE_ZLIB], [1], [Enable zlib for modules.])
146	module_compressions="gzip $module_compressions"
147], [
148	AC_MSG_NOTICE([zlib support not requested])
149])
150CC_FEATURE_APPEND([with_features], [with_zlib], [ZLIB])
151
152AC_ARG_WITH([openssl],
153	AS_HELP_STRING([--with-openssl], [handle PKCS7 signatures @<:@default=disabled@:>@]),
154	[], [with_openssl=no])
155AS_IF([test "x$with_openssl" != "xno"], [
156	PKG_CHECK_MODULES([libcrypto], [libcrypto >= 1.1.0], [LIBS="$LIBS $libcrypto_LIBS"])
157	AC_DEFINE([ENABLE_OPENSSL], [1], [Enable openssl for modinfo.])
158	module_signatures="PKCS7 $module_signatures"
159], [
160	AC_MSG_NOTICE([openssl support not requested])
161])
162CC_FEATURE_APPEND([with_features], [with_openssl], [LIBCRYPTO])
163
164AC_ARG_WITH([bashcompletiondir],
165	AS_HELP_STRING([--with-bashcompletiondir=DIR], [Bash completions directory]),
166	[],
167	[AS_IF([$($PKG_CONFIG --exists bash-completion)], [
168		with_bashcompletiondir=$($PKG_CONFIG --variable=completionsdir bash-completion)
169	] , [
170		with_bashcompletiondir=${datadir}/bash-completion/completions
171	])])
172AC_SUBST([bashcompletiondir], [$with_bashcompletiondir])
173
174#####################################################################
175# --enable-
176#####################################################################
177
178AC_ARG_ENABLE([tools],
179        AS_HELP_STRING([--disable-tools], [disable building tools that provide same functionality as module-init-tools @<:@default=enabled@:>@]),
180	[], enable_tools=yes)
181AM_CONDITIONAL([BUILD_TOOLS], [test "x$enable_tools" = "xyes"])
182
183AC_ARG_ENABLE([manpages],
184        AS_HELP_STRING([--disable-manpages], [disable manpages @<:@default=enabled@:>@]),
185	[], enable_manpages=yes)
186AM_CONDITIONAL([BUILD_MANPAGES], [test "x$enable_manpages" = "xyes"])
187
188AC_ARG_ENABLE([test-modules],
189        AS_HELP_STRING([--disable-test-modules], [disable building test modules during make check: cached modules will be used @<:@default=enabled@:>@]),
190	[], enable_test_modules=yes)
191AM_CONDITIONAL([BUILD_MODULES], [test "x$enable_test_modules" = "xyes"])
192
193AC_ARG_ENABLE([logging],
194	AS_HELP_STRING([--disable-logging], [disable system logging @<:@default=enabled@:>@]),
195	[], enable_logging=yes)
196AS_IF([test "x$enable_logging" = "xyes"], [
197	AC_DEFINE(ENABLE_LOGGING, [1], [System logging.])
198])
199
200AC_ARG_ENABLE([debug],
201	AS_HELP_STRING([--enable-debug], [enable debug messages @<:@default=disabled@:>@]),
202	[], [enable_debug=no])
203AS_IF([test "x$enable_debug" = "xyes"], [
204	AC_DEFINE(ENABLE_DEBUG, [1], [Debug messages.])
205])
206
207AC_ARG_ENABLE([coverage],
208	AS_HELP_STRING([--enable-coverage], [enable test coverage @<:@default=disabled@:>@]),
209	[], [enable_coverage=no])
210AS_IF([test "x$enable_coverage" = "xyes"], [
211	AC_CHECK_PROG(have_coverage, [lcov], [yes], [no])
212	AS_IF([test "x$have_coverage" = xno],[
213		AC_MSG_ERROR([*** lcov support requested but the program was not found])
214	], [
215		lcov_version_major="`lcov --version | cut -d ' ' -f 4 | cut -d '.' -f 1`"
216		lcov_version_minor="`lcov --version | cut -d ' ' -f 4 | cut -d '.' -f 2`"
217		AS_IF([test "$lcov_version_major" -lt 1 -o "$lcov_version_minor" -lt 10], [
218			AC_MSG_ERROR([*** lcov version is too old. 1.10 required])
219		], [
220			have_coverage=yes
221                        CC_CHECK_FLAGS_APPEND([with_coverage_cflags], [CFLAGS], [\
222                        -fprofile-arcs \
223                        -ftest-coverage])
224		])
225        ])
226])
227AM_CONDITIONAL([ENABLE_COVERAGE], [test "x$enable_coverage" = "xyes"])
228
229m4_ifdef([GTK_DOC_CHECK], [
230GTK_DOC_CHECK([1.14],[--flavour no-tmpl-flat])
231], [
232AM_CONDITIONAL([ENABLE_GTK_DOC], false)])
233
234#####################################################################
235# Default CFLAGS and LDFLAGS
236#####################################################################
237
238CC_CHECK_FLAGS_APPEND(with_cflags, [CFLAGS], [\
239		       -pipe \
240		       -DANOTHER_BRICK_IN_THE \
241		       -Wall \
242		       -W \
243		       -Wextra \
244		       -Wno-inline \
245		       -Wvla \
246		       -Wundef \
247		       -Wformat=2 \
248		       -Wlogical-op \
249		       -Wsign-compare \
250		       -Wformat-security \
251		       -Wmissing-include-dirs \
252		       -Wformat-nonliteral \
253		       -Wold-style-definition \
254		       -Wpointer-arith \
255		       -Winit-self \
256		       -Wdeclaration-after-statement \
257		       -Wfloat-equal \
258		       -Wmissing-prototypes \
259		       -Wstrict-prototypes \
260		       -Wredundant-decls \
261		       -Wmissing-declarations \
262		       -Wmissing-noreturn \
263		       -Wshadow \
264		       -Wendif-labels \
265		       -Wstrict-aliasing=3 \
266		       -Wwrite-strings \
267		       -Wno-long-long \
268		       -Wno-overlength-strings \
269		       -Wno-unused-parameter \
270		       -Wno-missing-field-initializers \
271		       -Wno-unused-result \
272		       -Wnested-externs \
273		       -Wchar-subscripts \
274		       -Wtype-limits \
275		       -Wuninitialized \
276		       -fno-common \
277		       -fdiagnostics-show-option \
278		       -fvisibility=hidden \
279		       -ffunction-sections \
280		       -fdata-sections])
281AC_SUBST([OUR_CFLAGS], "$with_cflags $with_coverage_cflags")
282
283
284CC_CHECK_FLAGS_APPEND([with_ldflags], [LDFLAGS], [ \
285		       -Wl,--as-needed \
286		       -Wl,--no-undefined \
287		       -Wl,--gc-sections])
288AC_SUBST([OUR_LDFLAGS], $with_ldflags)
289
290AC_DEFINE_UNQUOTED(KMOD_FEATURES, ["$with_features"], [Features in this build])
291
292#####################################################################
293# Generate files from *.in
294#####################################################################
295
296AC_SUBST([module_compressions], $module_compressions)
297AC_SUBST([module_signatures], $module_signatures)
298
299AC_CONFIG_FILES([
300	Makefile
301	man/Makefile
302	libkmod/docs/Makefile
303	libkmod/docs/version.xml
304	libkmod/libkmod.pc
305	tools/kmod.pc
306])
307
308
309#####################################################################
310
311AC_OUTPUT
312AC_MSG_RESULT([
313	$PACKAGE $VERSION
314	=======
315
316	module_directory:	${module_directory}
317	prefix:			${prefix}
318	sysconfdir:		${sysconfdir}
319	distconfdir:		${distconfdir}
320	libdir:			${libdir}
321	rootlibdir:		${rootlibdir}
322	includedir:		${includedir}
323	bindir:			${bindir}
324	Bash completions dir:   ${with_bashcompletiondir}
325
326	compiler:		${CC}
327	cflags:			${with_cflags} ${CFLAGS}
328	ldflags:		${with_ldflags} ${LDFLAGS}
329
330	tools:			${enable_tools}
331	logging:		${enable_logging}
332	compression:		zstd=${with_zstd}  xz=${with_xz}  zlib=${with_zlib}
333	debug:			${enable_debug}
334	coverage:		${enable_coverage}
335	doc:			${enable_gtk_doc}
336	man:			${enable_manpages}
337	test-modules:           ${enable_test_modules}
338
339	features:               ${with_features}
340])
341