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