1# Support for older autoconf without m4_esyscmd_s
2m4_ifndef([m4_esyscmd_s], [m4_define([m4_chomp_all], [m4_format([[%.*s]], m4_bregexp(m4_translit([[$1]], [/], [/ ]), [/*$]), [$1])])])
3m4_ifndef([m4_esyscmd_s], [m4_define([m4_esyscmd_s], [m4_chomp_all(m4_esyscmd([$1]))])])
4AC_PREREQ([2.63])
5AC_INIT([ebusd], m4_esyscmd_s([cat VERSION]), [ebusd@ebusd.eu], [ebusd], [https://github.com/john30/ebusd])
6
7AC_CONFIG_AUX_DIR([build])
8AC_CONFIG_MACRO_DIR([m4])
9AC_GNU_SOURCE
10
11if test -z $CXXFLAGS; then
12	CXXFLAGS="-fpic -Wall -Wno-unused-function -Wextra -g -O2"
13fi
14AC_PROG_CXX([g++-6 g++-5 g++-4.9 g++-4.8 g++])
15AX_CXX_COMPILE_STDCXX([11], [ext], [mandatory])
16
17AC_CHECK_HEADERS([arpa/inet.h \
18		  dirent.h \
19		  fcntl.h \
20		  netdb.h \
21		  poll.h \
22		  pthread.h \
23		  sys/ioctl.h \
24		  sys/select.h \
25		  sys/time.h \
26		  time.h \
27		  termios.h])
28
29AC_CHECK_LIB([pthread], [pthread_setname_np],
30	AC_DEFINE([HAVE_PTHREAD_SETNAME_NP], [1], [Defined if pthread_setname_np is available.]),
31	AC_MSG_RESULT([Could not find pthread_setname_np in pthread.]))
32EXTRA_LIBS=
33AC_CHECK_LIB([rt], [clock_gettime], [EXTRA_LIBS+="-lrt"])
34AC_SUBST(EXTRA_LIBS)
35
36AC_CHECK_FUNC([pselect], [AC_DEFINE(HAVE_PSELECT, [1], [Defined if pselect() is available.])])
37AC_CHECK_FUNC([ppoll], [AC_DEFINE(HAVE_PPOLL, [1], [Defined if ppoll() is available.])])
38AC_CHECK_HEADER([linux/serial.h], [AC_DEFINE(HAVE_LINUX_SERIAL, [1], [Defined if linux/serial.h is available.])])
39AC_CHECK_HEADER([dev/usb/uftdiio.h], [AC_DEFINE(HAVE_FREEBSD_UFTDI, [1], [Defined if dev/usb/uftdiio.h is available.])])
40
41AC_ARG_ENABLE(coverage, AS_HELP_STRING([--enable-coverage], [enable code coverage tracking]), [CXXFLAGS+=" -coverage -O0"], [])
42AC_ARG_WITH(contrib, AS_HELP_STRING([--without-contrib], [disable inclusion of contributed sources]), [], [with_contrib=yes])
43if test "x$with_contrib" != "xno"; then
44	AC_DEFINE_UNQUOTED(HAVE_CONTRIB, [1], [Defined if contributed sources are enabled.])
45fi
46AC_ARG_WITH(argp-lib, AS_HELP_STRING([--with-argp-lib=PATH], [path to argp libraries]), [LDFLAGS+="-L$with_argp_lib"])
47AC_ARG_WITH(argp-include, AS_HELP_STRING([--with-argp-include=PATH], [path to argp includes]), [CXXFLAGS+="-I$with_argp_include"])
48AC_CHECK_FUNC([argp_parse], [have_argp=yes], AC_CHECK_LIB([argp], [argp_parse], [have_argp=yes; LIBS="-largp $LIBS"], [have_argp=no]))
49if test "x$have_argp" = "xyes"; then
50	AC_CHECK_HEADER([argp.h], AC_DEFINE([HAVE_ARGP_H], [1], [Defined if argp.h is available.]), AC_MSG_ERROR([argp.h not found]))
51else
52	AC_MSG_ERROR([argp library not found, specify argp-standalone location in --with-argp-lib= and --with-argp-include= options.])
53fi
54AC_ARG_WITH(mqtt, AS_HELP_STRING([--without-mqtt], [disable support for MQTT handling]), [], [with_mqtt=yes])
55if test "x$with_mqtt" != "xno"; then
56	AC_CHECK_LIB([mosquitto], [mosquitto_lib_init],
57		[AC_DEFINE_UNQUOTED(HAVE_MQTT, [1], [Defined if MQTT handling is enabled.])
58		EXTRA_LIBS+=" -lmosquitto"],
59		[AC_MSG_RESULT([Could not find mosquitto_lib_init in libmosquitto.])
60		with_mqtt="no"])
61fi
62AM_CONDITIONAL([MQTT], [test "x$with_mqtt" != "xno"])
63
64AC_MSG_CHECKING([for direct float format conversion])
65AC_TRY_RUN(
66	[
67#include <stdint.h>
68int main() {
69	union {
70		uint32_t i;
71		float f;
72	} test;
73	test.f = 0.15;
74	return test.i == 0x3e19999a ? 0 : 1;
75}
76	],
77	[direct_float=1],
78	[direct_float=],
79	[direct_float=no],
80)
81if [[ "x$direct_float" == "x" ]]; then
82AC_TRY_RUN(
83	[
84#include <stdint.h>
85int main() {
86	union {
87		uint32_t i;
88		float f;
89	} test;
90	test.f = 0.15;
91	return test.i == 0x9a99193e ? 0 : 1;
92}
93	],
94	[direct_float=2],
95	[direct_float=no],
96	[direct_float=no],
97)
98fi
99if [[ "x$direct_float" == "xno" ]]; then
100	AC_MSG_RESULT([no])
101else
102	AC_MSG_RESULT([yes])
103	AC_DEFINE_UNQUOTED([HAVE_DIRECT_FLOAT_FORMAT], $direct_float, [Defined if direct conversion from float to int is available (2 for swapped byte order).])
104fi
105
106AC_CONFIG_SRCDIR([src/ebusd/main.cpp])
107AC_CONFIG_HEADERS([config.h])
108AC_CONFIG_FILES([Makefile
109		docs/Makefile
110		src/lib/utils/Makefile
111		src/lib/ebus/Makefile
112		src/lib/ebus/test/Makefile
113		src/ebusd/Makefile
114		src/tools/Makefile])
115AM_CONDITIONAL([CONTRIB], [test "x$with_contrib" != "xno"])
116AM_COND_IF([CONTRIB], [AC_CONFIG_FILES([
117		src/lib/ebus/contrib/Makefile
118		src/lib/ebus/contrib/test/Makefile
119	])])
120
121AC_DEFINE_UNQUOTED(PACKAGE_PIDFILE, LOCALSTATEDIR "/run/" PACKAGE ".pid", [The path and name of the PID file.])
122AC_DEFINE_UNQUOTED(PACKAGE_LOGFILE, LOCALSTATEDIR "/log/" PACKAGE "/" PACKAGE ".log", [The path and name of the log file.])
123AC_DEFINE(SCAN_VERSION, "[m4_esyscmd_s([sed -e 's#^\([0-9]*\.[0-9]*\).*#\1#' -e 's#\.\([0-9]\)$#0\1#' -e 's#\.##' VERSION])]", [The version of the package formatted for the scan result.])
124AC_DEFINE(REVISION, "[m4_esyscmd_s([git describe --always 2>/dev/null || (date +p%Y%m%d)])]", [The revision of the package.])
125
126AC_CHECK_PROGS([HAVE_DOXYGEN], [doxygen], [])
127if test -z "$HAVE_DOXYGEN"; then
128	AC_MSG_WARN([Doxygen not found - continuing without Doxygen support.])
129fi
130
131AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$HAVE_DOXYGEN"])
132AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([docs/Doxyfile])])
133
134AM_INIT_AUTOMAKE([1.11 -Wall -Werror foreign subdir-objects])
135
136m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
137AC_PROG_RANLIB
138
139m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
140
141AC_OUTPUT
142