• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1dnl
2dnl Launch-on-demand/startup stuff for CUPS.
3dnl
4dnl Copyright © 2020-2024 by OpenPrinting.
5dnl Copyright © 2007-2017 by Apple Inc.
6dnl Copyright © 1997-2005 by Easy Software Products, all rights reserved.
7dnl
8dnl Licensed under Apache License v2.0.  See the file "LICENSE" for more
9dnl information.
10dnl
11
12ONDEMANDFLAGS=""
13ONDEMANDLIBS=""
14AC_SUBST([ONDEMANDFLAGS])
15AC_SUBST([ONDEMANDLIBS])
16
17AC_ARG_WITH([ondemand], AS_HELP_STRING([--with-ondemand=...], [Specify the on-demand launch interface (launchd, systemd, upstart)]))
18
19AS_IF([test "x$with_ondemand" = x], [
20    AS_IF([test $host_os_name = darwin], [
21        with_ondemand="launchd"
22    ], [
23	with_ondemand="yes"
24    ])
25], [test "x$with_ondemand" = xyes -a $host_os_name = darwin], [
26    with_ondemand="launchd"
27], [test "x$with_ondemand" != xno -a "x$with_ondemand" != xsystemd -a "x$with_ondemand" != xupstart -a "x$with_ondemand" != xyes], [
28    AC_MSG_ERROR([Unknown --with-ondemand value "$with_ondemand" specified.])
29])
30
31dnl Launchd is used on macOS/Darwin...
32LAUNCHD_DIR=""
33AC_SUBST([LAUNCHD_DIR])
34
35AS_IF([test $with_ondemand = launchd], [
36    AC_CHECK_FUNC([launch_activate_socket], [
37	AC_DEFINE([HAVE_LAUNCHD], [1], [Have launchd support?])
38	AC_DEFINE([HAVE_ONDEMAND], [1], [Have on-demand launch support?])
39        with_ondemand="launchd"
40    ], [
41        AS_IF([test $with_ondemand = launchd], [
42            AC_MSG_ERROR([Need launch_activate_socket/liblaunch for launchd support.])
43        ])
44    ])
45    AC_CHECK_HEADER([launch.h], [
46        AC_DEFINE([HAVE_LAUNCH_H], [1], [Have <launch.h> header?])
47    ])
48
49    AS_IF([test $host_os_name = darwin], [
50	LAUNCHD_DIR="/System/Library/LaunchDaemons"
51	# liblaunch is already part of libSystem
52    ])
53])
54
55dnl Systemd is used on Linux...
56AC_ARG_WITH([systemd], AS_HELP_STRING([--with-systemd], [set directory for systemd service files]), [
57    SYSTEMD_DIR="$withval"
58], [
59    SYSTEMD_DIR=""
60])
61AC_SUBST([SYSTEMD_DIR])
62
63AS_IF([test $with_ondemand = systemd -o $with_ondemand = yes], [
64    AS_IF([test "x$PKGCONFIG" = x], [
65	AS_IF([test $with_ondemand = systemd], [
66	    AC_MSG_ERROR([Need pkg-config to enable systemd support.])
67	])
68    ], [
69	AC_MSG_CHECKING([for libsystemd])
70	have_systemd="no"
71	AS_IF([$PKGCONFIG --exists libsystemd], [
72	    AC_MSG_RESULT([yes])
73	    have_systemd="yes"
74	    with_ondemand="systemd"
75	    ONDEMANDFLAGS="$($PKGCONFIG --cflags libsystemd)"
76	    ONDEMANDLIBS="$($PKGCONFIG --libs libsystemd)"
77	], [$PKGCONFIG --exists libsystemd-daemon], [
78	    AC_MSG_RESULT([yes - legacy])
79	    have_systemd="yes"
80	    with_ondemand="systemd"
81	    ONDEMANDFLAGS="$($PKGCONFIG --cflags libsystemd-daemon)"
82	    ONDEMANDLIBS="$($PKGCONFIG --libs libsystemd-daemon)"
83
84	    AS_IF([$PKGCONFIG --exists libsystemd-journal], [
85		ONDEMANDFLAGS="$ONDEMANDFLAGS $($PKGCONFIG --cflags libsystemd-journal)"
86		ONDEMANDLIBS="$ONDEMANDLIBS $($PKGCONFIG --libs libsystemd-journal)"
87	    ])
88	], [
89	    AC_MSG_RESULT([no])
90	])
91
92	AS_IF([test $have_systemd = yes], [
93	    AC_DEFINE([HAVE_SYSTEMD], [1], [Have systemd support?])
94	    AC_DEFINE([HAVE_ONDEMAND], [1], [Have on-demand launch support?])
95	    AC_CHECK_HEADER([systemd/sd-journal.h], [
96	        AC_DEFINE([HAVE_SYSTEMD_SD_JOURNAL_H], [1], [Have <systemd/sd-journal.h> header?])
97	    ])
98	    AS_IF([test "x$SYSTEMD_DIR" = x], [
99		SYSTEMD_DIR="$($PKGCONFIG --variable=systemdsystemunitdir systemd)"
100	    ])
101	])
102    ])
103])
104
105dnl Upstart is also used on Linux (e.g., ChromeOS)
106AS_IF([test $with_ondemand = upstart], [
107    AC_DEFINE([HAVE_UPSTART]. [1], [Have upstart support?])
108    AC_DEFINE([HAVE_ONDEMAND], [1], [Have on-demand launch support?])
109])
110
111dnl Solaris uses smf
112AC_ARG_WITH([smfmanifestdir], AS_HELP_STRING([--with-smfmanifestdir], [set path for Solaris SMF manifest]), [
113    SMFMANIFESTDIR="$withval"
114], [
115    SMFMANIFESTDIR=""
116])
117AC_SUBST([SMFMANIFESTDIR])
118
119dnl Use init on other platforms...
120AC_ARG_WITH([rcdir], AS_HELP_STRING([--with-rcdir], [set path for rc scripts]), [
121    rcdir="$withval"
122], [
123    rcdir=""
124])
125AC_ARG_WITH([rclevels], AS_HELP_STRING([--with-rclevels], [set run levels for rc scripts]), [
126    rclevels="$withval"
127], [
128    rclevels="2 3 5"
129])
130AC_ARG_WITH([rcstart], AS_HELP_STRING([--with-rcstart], [set start number for rc scripts]), [
131    rcstart="$withval"
132], [
133    rcstart=""
134])
135AC_ARG_WITH([rcstop], AS_HELP_STRING([--with-rcstop], [set stop number for rc scripts]), [
136    rcstop="$withval"
137], [
138    rcstop=""
139])
140
141AS_IF([test "x$rcdir" = x], [
142    AS_IF([test "x$LAUNCHD_DIR" = x -a "x$SYSTEMD_DIR" = x -a "x$SMFMANIFESTDIR" = x], [
143	# Fall back on "init", the original service startup interface...
144	AS_IF([test -d /sbin/init.d], [
145	    # SuSE
146	    rcdir="/sbin/init.d"
147	], [test -d /etc/init.d], [
148	    # Others
149	    rcdir="/etc"
150	], [
151	    # RedHat, NetBSD
152	    rcdir="/etc/rc.d"
153	])
154    ], [
155	rcdir="no"
156    ])
157])
158
159AS_IF([test "x$rcstart" = x], [
160    AS_CASE(["$host_os_name"], [linux* | gnu*], [
161	# Linux
162	rcstart="81"
163    ], [sunos*], [
164	# Solaris
165	rcstart="81"
166    ], [*], [
167	# Others
168	rcstart="99"
169    ])
170])
171
172AS_IF([test "x$rcstop" = x], [
173    AS_CASE(["$host_os_name"], [linux* | gnu*], [
174	# Linux
175	rcstop="36"
176    ], [*], [
177	# Others
178	rcstop="00"
179    ])
180])
181
182INITDIR=""
183INITDDIR=""
184RCLEVELS="$rclevels"
185RCSTART="$rcstart"
186RCSTOP="$rcstop"
187AC_SUBST([INITDIR])
188AC_SUBST([INITDDIR])
189AC_SUBST([RCLEVELS])
190AC_SUBST([RCSTART])
191AC_SUBST([RCSTOP])
192
193AS_IF([test "x$rcdir" != xno], [
194    AS_IF([test "x$rclevels" = x], [
195	INITDDIR="$rcdir"
196    ], [
197	INITDIR="$rcdir"
198    ])
199])
200
201dnl Xinetd support...
202AC_ARG_WITH([xinetd], AS_HELP_STRING([--with-xinetd], [set path for xinetd config files]), [
203    xinetd="$withval"
204], [
205    xinetd=""
206])
207XINETD=""
208AC_SUBST([XINETD])
209
210AS_IF([test "x$xinetd" = x], [
211    AS_IF([test ! -x /sbin/launchd], [
212	for dir in /etc/xinetd.d /usr/local/etc/xinetd.d; do
213	    AS_IF([test -d $dir], [
214		XINETD="$dir"
215		break
216	    ])
217	done
218    ])
219], [test "x$xinetd" != xno], [
220    XINETD="$xinetd"
221])
222