build: Support for pkg-config
[platform/upstream/ofono.git] / configure.ac
1 AC_PREREQ(2.60)
2 AC_INIT(ofono, 0.40)
3
4 AM_INIT_AUTOMAKE([foreign subdir-objects])
5 AM_CONFIG_HEADER(config.h)
6
7 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
8
9 AM_MAINTAINER_MODE
10
11 AC_PREFIX_DEFAULT(/usr/local)
12
13 PKG_PROG_PKG_CONFIG
14
15 COMPILER_FLAGS
16
17 AC_LANG_C
18
19 AC_C_RESTRICT
20
21 AC_PROG_CC
22 AM_PROG_CC_C_O
23 AC_PROG_CC_PIE
24 AC_PROG_INSTALL
25 AM_PROG_MKDIR_P
26
27 m4_define([_LT_AC_TAGCONFIG], [])
28 m4_ifdef([AC_LIBTOOL_TAGS], [AC_LIBTOOL_TAGS([])])
29
30 AC_DISABLE_STATIC
31 AC_PROG_LIBTOOL
32
33 AC_ARG_ENABLE(optimization, AC_HELP_STRING([--disable-optimization],
34                         [disable code optimization through compiler]), [
35         if (test "${enableval}" = "no"); then
36                 CFLAGS="$CFLAGS -O0"
37         fi
38 ])
39
40 AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug],
41                         [enable compiling with debugging information]), [
42         if (test "${enableval}" = "yes" &&
43                                 test "${ac_cv_prog_cc_g}" = "yes"); then
44                 CFLAGS="$CFLAGS -g"
45         fi
46 ])
47
48 AC_ARG_ENABLE(test, AC_HELP_STRING([--enable-test],
49                 [enable test/example scripts]), [enable_test=${enableval}])
50 AM_CONDITIONAL(TEST, test "${enable_test}" = "yes")
51
52 AC_ARG_ENABLE(pie, AC_HELP_STRING([--enable-pie],
53                         [enable position independent executables flag]), [
54         if (test "${enableval}" = "yes" &&
55                                 test "${ac_cv_prog_cc_pie}" = "yes"); then
56                 CFLAGS="$CFLAGS -fPIE"
57                 LDFLAGS="$LDFLAGS -pie"
58         fi
59 ])
60
61 AC_ARG_ENABLE(threads, AC_HELP_STRING([--enable-threads],
62                 [enable threading support]), [enable_threads=${enableval}])
63
64 AC_CHECK_FUNC(signalfd, dummy=yes,
65                         AC_MSG_ERROR(signalfd support is required))
66
67 AC_CHECK_LIB(dl, dlopen, dummy=yes,
68                         AC_MSG_ERROR(dynamic linking loader is required))
69
70 PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.22, dummy=yes,
71                                 AC_MSG_ERROR(GLib >= 2.22 is required))
72 AC_SUBST(GLIB_CFLAGS)
73 AC_SUBST(GLIB_LIBS)
74
75 if (test "${enable_threads}" = "yes"); then
76         AC_DEFINE(NEED_THREADS, 1, [Define if threading support is required])
77         PKG_CHECK_MODULES(GTHREAD, gthread-2.0 >= 2.16, dummy=yes,
78                                 AC_MSG_ERROR(GThread >= 2.16 is required))
79         GLIB_CFLAGS="$GLIB_CFLAGS $GTHREAD_CFLAGS"
80         GLIB_LIBS="$GLIB_LIBS $GTHREAD_LIBS"
81 fi
82
83 PKG_CHECK_MODULES(DBUS, dbus-1 >= 1.0, dummy=yes,
84                                 AC_MSG_ERROR(D-Bus >= 1.0 is required))
85 AC_CHECK_LIB(dbus-1, dbus_watch_get_unix_fd, dummy=yes,
86         AC_DEFINE(NEED_DBUS_WATCH_GET_UNIX_FD, 1,
87                 [Define to 1 if you need the dbus_watch_get_unix_fd() function.]))
88 AC_CHECK_LIB(dbus-1, dbus_connection_can_send_type, dummy=yes,
89         AC_DEFINE(NEED_DBUS_CONNECTION_CAN_SEND_TYPE, 1,
90                 [Define to 1 if you need the dbus_connection_can_send_type() function.]
91 ))
92 AC_SUBST(DBUS_CFLAGS)
93 AC_SUBST(DBUS_LIBS)
94
95 AC_ARG_WITH(dbusconfdir, AC_HELP_STRING([--with-dbusconfdir=PATH],
96         [path to D-Bus config directory]), [path_dbusconf=${withval}],
97                 [path_dbusconf="`$PKG_CONFIG --variable=sysconfdir dbus-1`"])
98 if (test -z "${path_dbusconf}"); then
99         DBUS_CONFDIR="${sysconfdir}/dbus-1/system.d"
100 else
101         DBUS_CONFDIR="${path_dbusconf}/dbus-1/system.d"
102 fi
103 AC_SUBST(DBUS_CONFDIR)
104
105 AC_ARG_WITH(dbusdatadir, AC_HELP_STRING([--with-dbusdatadir=PATH],
106         [path to D-Bus data directory]), [path_dbusdata=${withval}],
107                 [path_dbusdata="`$PKG_CONFIG --variable=datadir dbus-1`"])
108 if (test -z "${path_dbusdata}"); then
109         DBUS_DATADIR="${datadir}/dbus-1/system-services"
110 else
111         DBUS_DATADIR="${path_dbusdata}/dbus-1/system-services"
112 fi
113 AC_SUBST(DBUS_DATADIR)
114
115 AC_ARG_WITH([systemdunitdir], AC_HELP_STRING([--with-systemdunitdir=DIR],
116         [path to systemd service directory]), [path_systemdunit=${withval}],
117                 [path_systemdunit="`$PKG_CONFIG --variable=systemdsystemunitdir systemd`"])
118 if (test -n "${path_systemdunit}"); then
119         SYSTEMD_UNITDIR="${path_systemdunit}"
120         AC_SUBST(SYSTEMD_UNITDIR)
121 fi
122 AM_CONDITIONAL(SYSTEMD, test -n "${path_systemdunit}")
123
124 AC_ARG_ENABLE(capng, AC_HELP_STRING([--enable-capng],
125                 [enable capabilities support]), [enable_capng=${enableval}])
126 if (test "${enable_capng}" = "yes"); then
127         PKG_CHECK_MODULES(CAPNG, libcap-ng, dummy=yes,
128                                 AC_MSG_ERROR(Capabilities library is required))
129         AC_SUBST(CAPNG_CFLAGS)
130         AC_SUBST(CAPNG_LIBS)
131         AC_DEFINE(HAVE_CAPNG, 1, [Define to 1 if you have capabilities library.])
132 fi
133
134 AC_ARG_ENABLE(udev, AC_HELP_STRING([--disable-udev],
135                         [don't use udev support even if available]),
136                                                 [enable_udev=${enableval}])
137 if (test "${enable_udev}" != "no"); then
138         PKG_CHECK_MODULES(UDEV, libudev >= 143, [enable_udev="yes"],
139                                 AC_MSG_ERROR(libudev >= 143 is required))
140         UDEV_DATADIR="`$PKG_CONFIG --variable=udevdir udev`"
141         if (test -z "${UDEV_DATADIR}"); then
142                 UDEV_DATADIR="${sysconfdir}/udev/rules.d"
143         else
144                 UDEV_DATADIR="${UDEV_DATADIR}/rules.d"
145         fi
146         AC_SUBST(UDEV_DATADIR)
147 fi
148 AC_SUBST(UDEV_CFLAGS)
149 AC_SUBST(UDEV_LIBS)
150 AM_CONDITIONAL(UDEV, test "${enable_udev}" = "yes")
151
152 AC_ARG_ENABLE(tools, AC_HELP_STRING([--enable-tools],
153                 [enable testing tools]), [enable_tools=${enableval}])
154 if (test "${enable_tools}" = "yes"); then
155         PKG_CHECK_MODULES(USB, libusb-1.0, dummy=yes,
156                                 AC_MSG_ERROR(USB library is required))
157         AC_SUBST(USB_CFLAGS)
158         AC_SUBST(USB_LIBS)
159 fi
160 AM_CONDITIONAL(TOOLS, test "${enable_tools}" = "yes")
161
162 AC_ARG_ENABLE(atmodem, AC_HELP_STRING([--disable-atmodem],
163                                 [disable ETSI AT modem support]),
164                                         [enable_atmodem=${enableval}])
165 AM_CONDITIONAL(ATMODEM, test "${enable_atmodem}" != "no")
166
167 AC_ARG_ENABLE(cdmamodem, AC_HELP_STRING([--disable-cdmamodem],
168                                 [disable CDMA AT modem support]),
169                                         [enable_cdmamodem=${enableval}])
170 AM_CONDITIONAL(CDMAMODEM, test "${enable_cdmamodem}" != "no")
171
172 AC_ARG_ENABLE(phonesim, AC_HELP_STRING([--disable-phonesim],
173                                 [disable Phone simulator support]),
174                                         [enable_phonesim=${enableval}])
175 AM_CONDITIONAL(PHONESIM, test "${enable_phonesim}" != "no" &&
176                                         test "${enable_atmodem}" != "no")
177
178 AC_ARG_ENABLE(isimodem, AC_HELP_STRING([--disable-isimodem],
179                                 [disable PhoNet/ISI modem support]),
180                                         [enable_isimodem=${enableval}])
181 AM_CONDITIONAL(ISIMODEM, test "${enable_isimodem}" != "no")
182
183 AC_ARG_ENABLE(bluetooth, AC_HELP_STRING([--disable-bluetooth],
184                                 [disable Bluetooth modem support]),
185                                         [enable_bluetooth=${enableval}])
186 if (test "${enable_bluetooth}" != "no"); then
187         PKG_CHECK_MODULES(BLUEZ, bluez, dummy=yes,
188                                 AC_MSG_ERROR(Bluetooth library is required))
189 fi
190 AC_SUBST(BLUEZ_CFLAGS)
191 AC_SUBST(BLUEZ_LIBS)
192 AM_CONDITIONAL(BLUETOOTH, test "${enable_bluetooth}" != "no")
193
194 AC_ARG_ENABLE(datafiles, AC_HELP_STRING([--disable-datafiles],
195                         [don't install configuration and data files]),
196                                         [enable_datafiles=${enableval}])
197
198 AM_CONDITIONAL(DATAFILES, test "${enable_datafiles}" != "no")
199
200 if (test "${prefix}" = "NONE"); then
201         dnl no prefix and no localstatedir, so default to /var
202         if (test "$localstatedir" = '${prefix}/var'); then
203                 AC_SUBST([localstatedir], ['/var'])
204         fi
205
206         prefix="${ac_default_prefix}"
207 fi
208
209 if (test "$localstatedir" = '${prefix}/var'); then
210         storagedir="${prefix}/var/lib/ofono"
211 else
212         storagedir="${localstatedir}/lib/ofono"
213 fi
214 AC_DEFINE_UNQUOTED(STORAGEDIR, "${storagedir}",
215                         [Directory for the storage files])
216
217 if (test "$sysconfdir" = '${prefix}/etc'); then
218         configdir="${prefix}/etc/ofono"
219 else
220         configdir="${sysconfdir}/ofono"
221 fi
222 AC_DEFINE_UNQUOTED(CONFIGDIR, "${configdir}",
223                         [Directory for the configuration files])
224
225 AC_OUTPUT(Makefile include/version.h src/ofono.service ofono.pc)