Skip to content

Commit 07ff210

Browse files
committed
configure: Improve portability by not assuming every non-Windows, non-Darwin OSes have udev
udev is only available on Linux. Only enable it when it actually exists on the host. The primary purpose of this change is to support NetBSD.
1 parent 2b74ad0 commit 07ff210

3 files changed

Lines changed: 58 additions & 34 deletions

File tree

Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
AUTOMAKE_OPTIONS = foreign
22
ACLOCAL_AMFLAGS = -I m4
3-
SUBDIRS = src $(UDEV_SUB) $(SYSTEMD_SUB) docs
3+
SUBDIRS = src udev systemd docs
44

55
EXTRA_DIST = \
66
docs \
@@ -10,4 +10,4 @@ EXTRA_DIST = \
1010

1111
DISTCHECK_CONFIGURE_FLAGS = \
1212
--with-udevrulesdir=$$dc_install_base/$(udevrulesdir) \
13-
--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)
13+
--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)

configure.ac

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,63 @@ else
5858
fi
5959
fi
6060

61+
AC_ARG_WITH([udev],
62+
[AS_HELP_STRING([--with-udev],
63+
[Build with udev support @<:@default=auto@:>@])],
64+
[with_udev=$withval],
65+
[with_udev=auto])
66+
if test "x$with_udev" = "xauto"; then
67+
AC_MSG_CHECKING([for udev])
68+
PKG_CHECK_EXISTS([udev],
69+
[AC_MSG_RESULT([yes])
70+
with_udev=yes],
71+
[AC_MSG_RESULT([no])])
72+
fi
73+
if test "x$with_udev" = "xyes"; then
74+
AC_DEFINE([HAVE_UDEV], [1], [Define to enable udev support])
75+
fi
76+
6177
AC_ARG_WITH([udevrulesdir],
6278
AS_HELP_STRING([--with-udevrulesdir=DIR],
63-
[Directory for udev rules]),
79+
[Directory for udev rules @<:@default=auto@:>@]),
6480
[],
6581
[with_udevrulesdir=auto])
6682
if test "x$with_udevrulesdir" = "xauto"; then
67-
udevdir=$($PKG_CONFIG --variable=udevdir udev)
68-
if test "x$udevdir" != "x"; then
69-
with_udevrulesdir=$udevdir"/rules.d"
70-
else
71-
with_udevrulesdir=$prefix/lib/udev/rules.d
72-
fi
83+
PKG_CHECK_VAR([UDEVDIR], [udev], [udevdir],
84+
[with_udevrulesdir="${UDEVDIR}/rules.d"],
85+
[with_udevrulesdir="${libdir}/udev/rules.d"])
7386
fi
87+
AC_SUBST([udevrulesdir], [$with_udevrulesdir])
88+
AM_CONDITIONAL([WANT_UDEV], [test -n "$with_udevrulesdir" -a "x$with_udevrulesdir" != xno -a "x$with_udev" = "xyes"])
7489

7590
AC_ARG_WITH([systemd],
76-
[AS_HELP_STRING([--without-systemd],
77-
[do not build with systemd support @<:@default=yes@:>@])],
91+
[AS_HELP_STRING([--with-systemd],
92+
[Build with systemd support @<:@default=auto@:>@])],
7893
[with_systemd=$withval],
79-
[with_systemd=yes])
94+
[with_systemd=auto])
95+
if test "x$with_systemd" = "xauto"; then
96+
AC_MSG_CHECKING([for systemd])
97+
PKG_CHECK_EXISTS([systemd],
98+
[AC_MSG_RESULT([yes])
99+
with_systemd=yes],
100+
[AC_MSG_RESULT([no])])
101+
fi
102+
if test "x$with_systemd" = "xyes"; then
103+
AC_DEFINE([HAVE_SYSTEMD], [1], [Define to enable systemd support])
104+
fi
80105

81106
AC_ARG_WITH([systemdsystemunitdir],
82107
[AS_HELP_STRING([--with-systemdsystemunitdir=DIR],
83-
[directory for systemd service files])],
84-
[with_systemdsystemunitdir=$withval],
85-
[with_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)])
86-
87-
if test "x$with_systemdsystemunitdir" != xno; then
88-
AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
108+
[Directory for systemd service files @<:@default=auto@:>@])],
109+
[],
110+
[with_systemdsystemunitdir=auto])
111+
if test "x$with_systemdsystemunitdir" = "xauto"; then
112+
PKG_CHECK_VAR([SYSTEMDSYSTEMUNITDIR], [systemd], [systemdsystemunitdir],
113+
[with_systemdsystemunitdir="${SYSTEMDSYSTEMUNITDIR}"],
114+
[with_systemdsystemunitdir=""])
89115
fi
90-
AM_CONDITIONAL(WANT_SYSTEMD, [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno -a "x$with_systemd" = "xyes" ])
116+
AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
117+
AM_CONDITIONAL([WANT_SYSTEMD], [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno -a "x$with_systemd" = "xyes"])
91118

92119
if test "x$with_systemd" = xyes; then
93120
udev_activation_rule="ENV{SYSTEMD_WANTS}=\"usbmuxd.service\""
@@ -116,8 +143,6 @@ AC_CHECK_FUNCS([ppoll clock_gettime localtime_r])
116143

117144
# Check for operating system
118145
AC_MSG_CHECKING([whether to enable WIN32 build settings])
119-
UDEV_SUB=
120-
SYSTEMD_SUB=
121146
case ${host_os} in
122147
*mingw32*|*cygwin*)
123148
win32=true
@@ -135,24 +160,19 @@ case ${host_os} in
135160
*)
136161
win32=false
137162
AC_MSG_RESULT([no])
138-
UDEV_SUB=udev
139-
AC_SUBST([udevrulesdir], [$with_udevrulesdir])
140-
AC_DEFINE(HAVE_UDEV, 1, [Define to enable udev support])
141-
activation_method="systemd"
142-
if test "x$with_systemd" != "xyes"; then
143-
echo "*** Note: support for systemd activation has been disabled, using udev activation instead ***"
163+
if test "x$with_udev" = "xyes"; then
144164
activation_method="udev"
165+
elif test "x$with_systemd" = "xyes"; then
166+
activation_method="systemd"
167+
echo "*** Note: support for udev activation has been disabled, using systemd activation instead ***"
145168
else
146-
AC_DEFINE(HAVE_SYSTEMD, 1, [Define to enable systemd support])
147-
SYSTEMD_SUB=systemd
169+
activation_method="manual"
170+
echo "*** Note: support for udev/systemd activation have been disabled, using manual activation instead ***"
148171
fi
149172
;;
150173
esac
151174
AM_CONDITIONAL(WIN32, test x$win32 = xtrue)
152175

153-
AC_SUBST([UDEV_SUB])
154-
AC_SUBST([SYSTEMD_SUB])
155-
156176
AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wmissing-declarations -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default -Wno-unused-parameter")
157177
AC_SUBST(GLOBAL_CFLAGS)
158178

@@ -180,11 +200,11 @@ Configuration for $PACKAGE $VERSION:
180200
preflight worker support ..: $have_limd
181201
activation method .........: $activation_method"
182202

183-
if test "x$activation_method" = "xsystemd"; then
203+
if test "x$with_systemd" = "xyes"; then
184204
echo " systemd unit directory ....: ${systemdsystemunitdir}"
185205
fi
186206

187-
if test -n "$udevrulesdir"; then
207+
if test "x$with_udev" = "xyes"; then
188208
echo " udev rules directory ......: ${udevrulesdir}"
189209
fi
190210

udev/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ edit = \
44
-e 's|@sbindir[@]|$(sbindir)|g' \
55
< $< > $@ || rm $@
66

7+
if WANT_UDEV
8+
79
udevrules_DATA = \
810
39-usbmuxd.rules
911

@@ -18,3 +20,5 @@ MAINTAINERCLEANFILES = \
1820

1921
CLEANFILES = \
2022
39-usbmuxd.rules
23+
24+
endif

0 commit comments

Comments
 (0)