1# configure.ac for the libcoap package
2#
3# Copyright (C) 2010-2015 Olaf Bergmann <bergmann@tzi.org>
4#           (C)      2015 Carsten Schoenert <c.schoenert@t-online.de>
5#
6# Please run 'autogen.sh' to let autoconf produce a configure script.
7
8# Define the libcoap software version here. Note! The libtool versions are
9# defined later.
10m4_define([libcoap_major_version], [4])
11m4_define([libcoap_minor_version], [1])
12m4_define([libcoap_micro_version], [2])
13
14m4_define([libcoap_version],[libcoap_major_version.libcoap_minor_version.libcoap_micro_version])
15
16AC_INIT([libcoap], [libcoap_version], [libcoap-developers@lists.sourceforge.net], [libcoap], [https://libcoap.net/])
17AC_PREREQ([2.64])
18AM_INIT_AUTOMAKE([1.10 -Wall no-define no-dist-gzip dist-bzip2])
19
20# Generate one configuration header file for building the library itself with
21# an autogenerated template. We need later a second one (include/libcoap.h)
22# that will be installed alongside the library.
23AC_CONFIG_HEADERS([coap_config.h])
24
25AC_PROG_CC
26AM_PROG_CC_C_O
27AC_CONFIG_MACRO_DIR([m4])
28m4_pattern_allow([AM_PROG_AR])
29AM_PROG_AR
30
31# enable the automatically build of shared and static libraries, the unit
32# tests needs the static library
33LT_INIT([shared static])
34
35# Setting the libtool versioning
36###################################################################################
37#                                                                                 #
38#  To set the version of the library, libtool provides the -version-info          #
39#  parameter, which accepts three numbers, separated by colons, that are called   #
40#  respectively, current, revision and age. Both their name and their behaviour,  #
41#  nowadays, have to be considered fully arbitrary, as the explanation provided   #
42#  in the official documentation is confusing to say the least, and can be, in    #
43#  some cases, considered completely wrong.                                       #
44#  https://autotools.io/libtool/version.html                                      #
45#                                                                                 #
46###################################################################################
47#
48# How to work with the libtool versioning?
49#
50# Follow the followings steps from top to bottom. This means allways start at point 1
51# if you plan to make a release and change the values.
52# Every new library starts with a version 'current'  (short 'c') = 0
53#                                         'revision' (short 'r') = 0
54#                                         'age'      (short 'a') = 0
55#
56# Update the libtool versioning only immediately before a public release of libcoap.
57#
58# 1. If the library source code has changed at all since the last update, then
59#    increment revision (c:r:a becomes c:r+1:a).
60#  --> Increase the 'LT_LIBCOAP_REVISION' value with *everey* new software release.
61#
62# 2. If any interfaces [exported functions or data] have been added, removed, or
63#    changed since the last update, increment current, and set revision to 0
64#    (c:r:a becomes c+1:r=0:a).
65#  --> Increase the 'LT_LIBCOAP_CURRENT' value whenever as an interface has been added,
66#      removed or changed. This implies also a API change! You mostly have to change
67#      the 'libcoap_major_version' then too!
68#  --> Set 'LT_LIBCOAP_REVISION' to 0.
69#
70# 3. If any interfaces have been added since the last public release, then increment
71#    age (c:r:a becomes c:r:a+1). Adding new interfaces will make the library allways
72#    backwards compatable.
73#  --> Increase the 'LT_LIBCOAP_AGE' value only if the changes made to the ABI are
74#      backward compatible.
75#
76# 4. If any interfaces whitin the library have been removed since the last public
77#    release, then set age to 0.
78#  --> Set 'LT_LIBCOAP_AGE' to 0.
79
80LT_LIBCOAP_CURRENT=0
81LT_LIBCOAP_REVISION=0
82LT_LIBCOAP_AGE=0
83LIBCOAP_SO_VERSION=$LT_LIBCOAP_CURRENT.$LT_LIBCOAP_REVISION.$LT_LIBCOAP_AGE
84
85# Announce the libtool version
86AC_SUBST(LT_LIBCOAP_CURRENT)
87AC_SUBST(LT_LIBCOAP_REVISION)
88AC_SUBST(LT_LIBCOAP_AGE)
89AC_SUBST(LIBCOAP_SO_VERSION)
90
91# Defining the API Version
92LIBCOAP_API_VERSION=1
93AC_SUBST(LIBCOAP_API_VERSION)
94
95# Adding some default warning options for code QS
96# see https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
97# and http://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html
98WARNING_CFLAGS="\
99-pedantic \
100-Wall \
101-Wextra \
102-Wformat-security \
103-Winline \
104-Wmissing-declarations \
105-Wmissing-prototypes \
106-Wnested-externs \
107-Wpointer-arith \
108-Wshadow \
109-Wstrict-prototypes \
110-Wswitch-default \
111-Wswitch-enum \
112-Wunused \
113-Wunused-result \
114"
115
116# check whether or not the compiler supports -Wlogical-op (clang does not...)
117AX_CHECK_COMPILE_FLAG([-Wlogical-op], [WARNING_CFLAGS="$WARNING_CFLAGS -Wlogical-op"],,[-Werror])
118AX_CHECK_COMPILE_FLAG([-fdiagnostics-color], [CFLAGS="$CFLAGS -fdiagnostics-color"],,[-Werror])
119
120AC_SUBST([WARNING_CFLAGS])
121
122AX_CHECK_LINK_FLAG([-Wl,--version-script=./libcoap-${LIBCOAP_API_VERSION}.map],
123                   [libcoap_SYMBOLS="-Wl,--version-script=\$(srcdir)/libcoap-\$(LIBCOAP_API_VERSION).map"],
124                   [libcoap_SYMBOLS="-export-symbols \$(srcdir)/libcoap-\$(LIBCOAP_API_VERSION).sym"])
125
126AC_SUBST(libcoap_SYMBOLS)
127
128# configure options
129# __documentation__
130AC_ARG_ENABLE([documentation],
131              [AC_HELP_STRING([--enable-documentation],
132              [Enable building the documentation (default=yes)])],
133              [build_documentation="$enableval"],
134              [build_documentation="yes"])
135
136if test "x$build_documentation" = "xyes"; then
137	# Check for doxygen
138	AC_PATH_PROGS([DOXYGEN], [doxygen])
139	if test -z "$DOXYGEN"; then
140		if test "x$build_documentation" = "xyes"; then
141			AC_MSG_WARN([==> Doxygen not found - continuing without Doxygen support])
142			AC_MSG_WARN([==> The libcoap html documentation will not be build!])
143			doxygen_version="not found"
144		fi
145	else
146		AC_MSG_CHECKING([for compatible doxygen version])
147						doxygen_version=`$DOXYGEN --version`
148						AS_VERSION_COMPARE([$doxygen_version], [1.7.0],
149						[AC_MSG_RESULT([no])
150						 DOXYGEN=""],
151						[AC_MSG_RESULT([yes])],
152						[AC_MSG_RESULT([yes])])
153		if test "x$DOXYGEN" = "x" -a "x$build_documentation" = "xyes"; then
154			AC_MSG_ERROR([==> Doxygen $doxygen_version too old. Doxygen 1.7+ required for documentation build.])
155			AC_MSG_ERROR([==> Install required doxygen version or disable the documentation using --disable-documentation])
156		else
157			# we found doxygen and the version is valid
158			DOC_DIR=doc
159			AC_SUBST(DOC_DIR)
160			# now checking dot (needed for graphics)
161			AC_PATH_PROG([DOT], [dot])
162			if test "x$DOT" = "x"; then
163				AC_MSG_WARN([==> dot not found - continuing without DOT support])
164				AC_MSG_WARN([==> The libcoap html documentation will be build without DOT graphics!])
165				HAVE_DOT="NO"
166				USE_CALL_GRAPH="NO"
167			else
168				AC_MSG_CHECKING([for compatible dot version])
169				dot_version=`$DOT -V 2>&1|$GREP -oP '(?<=version\W)@<:@0-9.@:>@*(?=\W(.*))'`
170				AS_VERSION_COMPARE([$dot_version], [2.26.0],
171								   [AC_MSG_RESULT([no])
172								    DOT=""],
173								   [AC_MSG_RESULT([yes])],
174								   [AC_MSG_RESULT([yes])])
175				if test "x$DOT" = "x" -a "x$build_documentation" = "xyes"; then
176						AC_MSG_WARN([==> Graphviz dot $dot_version too old. Graphviz 2.26+ required for documentation build.])
177						AC_MSG_ERROR([==> Install required graphviz version or disable the documentation using --disable-documentation])
178				fi
179				# we found dot and the version is valid
180				HAVE_DOT="YES"
181				# let doxygen create caller graphics
182				# see http://www.stack.nl/~dimitri/doxygen/manual/config.html#cfg_call_graph
183				USE_CALL_GRAPH="YES"
184				# exporting the tests to doc/Doxygen(.in)
185				AC_SUBST(HAVE_DOT)
186				AC_SUBST(USE_CALL_GRAPH)
187			fi
188		fi
189	fi
190fi
191AM_CONDITIONAL(BUILD_DOCUMENTATION, [test "x$build_documentation" = "xyes"])
192
193AM_CONDITIONAL([HAVE_DOXYGEN],
194	[test -n "$DOXYGEN"])AM_COND_IF([HAVE_DOXYGEN],
195	[AC_CONFIG_FILES([doc/Doxyfile])])
196
197# configure options
198# __tests__
199AC_ARG_ENABLE([tests],
200              [AC_HELP_STRING([--enable-tests],
201              [Enable building the tests (default=no)])],
202              [build_tests="$enableval"],
203              [build_tests="no"])
204
205if test "x$build_tests" = "xyes"; then
206	# CUnit ships not version within the pkgconfig file cunit.pc so we have to do some more work here
207	# Check for CUnit header files
208	AC_CHECK_HEADERS([CUnit/CUnit.h],
209					 [],
210					 [AC_MSG_WARN([==> You want to build the testing binary but the needed header files for CUnit could not be found!])
211					  AC_MSG_ERROR([==> Install the package that contains the headers or disable the testing binary using --disable-tests.])
212					 ])
213	# Check now for libcunit
214	save_LIBS="$LIBS"
215	LIBS=""
216	CUNIT_LIBS=""
217	have_cunit=no
218	AC_SEARCH_LIBS([CU_add_suite],
219				   [cunit],
220				   [CUNIT_LIBS="$LIBS"
221				    AC_DEFINE(HAVE_LIBCUNIT, [1], [Define if the system has libcunit])
222				   ],
223				   [AC_MSG_WARN([==> You want to build the testing binary but the needed library 'libcunit' for linking could not be found!])
224				    AC_MSG_ERROR([==> Install the package that contains the library or disable the testing binary using --disable-tests.])
225				   ])
226	LIBS="$save_LIBS"
227	AC_SUBST(CUNIT_LIBS)
228	HAVE_CUNIT="YES"
229fi
230AM_CONDITIONAL(HAVE_CUNIT, [test "x$CUNIT_LIBS" != "x"])
231
232# configure options
233# __examples__
234AC_ARG_ENABLE([examples],
235              [AC_HELP_STRING([--enable-examples],
236              [Enable building the tests (default=yes)])],
237              [build_examples="$enableval"],
238              [build_examples="yes"])
239
240if test "x$build_examples" = "xyes" -a "x$build_documentation" = "xyes"; then
241	AC_ARG_VAR([A2X], [a2x command])
242	AC_PATH_PROG([A2X], [a2x])
243	if test "x$A2X" = "x"; then
244		AC_MSG_WARN([==> You want to build the examples binaries, that is also including the respective manpages but a2x was not found!])
245		AC_MSG_ERROR([==> Install the package that contains the a2x binary or disable the build of the examples using --disable-examples.])
246	fi
247	build_examples="yes"
248fi
249AM_CONDITIONAL(BUILD_EXAMPLES, [test "x$build_examples" = "xyes"])
250
251# end configure options
252#######################
253
254# Check for ctags
255AC_ARG_VAR([CTAGS_PROG],[the 'ctag' program to use for make target 'update-map-file'])
256AC_PATH_PROG([CTAGS_PROG],[ctags],[])
257if test "x$CTAGS_PROG" = "x"; then
258	AC_MSG_NOTICE([==> Note: 'ctags' command not found!])
259	AC_MSG_WARN([==> Without ctags you will be unable to run the target 'update-map-file'!])
260	AC_MSG_WARN([==> This is no problem if you just want to build the library libcoap.])
261fi
262if ! "$CTAGS_PROG" --c-kinds=f /dev/null &>/dev/null; then
263	AC_MSG_NOTICE([==> Note: your ctags does not support '--c-kinds'!])
264	AC_MSG_NOTICE([==> Most likely, you are using the GNU Emacs ctag and not exuberant ctag])
265	AC_MSG_WARN([==> This option is required for target 'update-map-file'])
266	AC_MSG_WARN([==> which is not a problem if you just want to build the library libcoap.])
267fi
268
269# Checks for header files.
270AC_CHECK_HEADERS([assert.h arpa/inet.h limits.h netdb.h netinet/in.h \
271                  stdlib.h string.h strings.h sys/socket.h sys/time.h \
272                  time.h unistd.h sys/unistd.h syslog.h])
273
274# Checks for typedefs, structures, and compiler characteristics.
275AC_TYPE_SIZE_T
276AC_TYPE_SSIZE_T
277
278# Checks for library functions.
279AC_FUNC_MALLOC
280AC_CHECK_FUNCS([memset select socket strcasecmp strrchr getaddrinfo \
281                strnlen])
282
283# Check if -lsocket -lnsl is required (specifically Solaris)
284AC_SEARCH_LIBS([socket], [socket])
285AC_SEARCH_LIBS([inet_ntop], [nsl])
286
287# Check if clock_gettime() requires librt, when available
288AC_SEARCH_LIBS([clock_gettime], [rt])
289
290AC_MSG_CHECKING([operating system])
291
292# Set up here some extra platform depended defines and variables.
293# The "ADDITIONAL_CFLAGS" is need as this stand-alone definition
294# for the doxygen part.
295case $host in
296	*-linux* | *-uclinux*)
297	AC_MSG_RESULT([Linux])
298	ADDITIONAL_CFLAGS="-D_GNU_SOURCE -DWITH_POSIX"
299
300	# Not yet needed but if some code definitions have to depend on the platform.
301	#AC_DEFINE(OS_LINUX, 1, [Linux backend])
302	#AC_SUBST(OS_LINUX)
303	;;
304
305	*-solaris*)
306	AC_MSG_RESULT([Solaris])
307	# set _XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED to enable XPG4v2 (POSIX 2004)
308	# set __EXTENSION__ to shut up feature test macros that restrict -std=c99
309	# to only C99 (and nothing newer)
310	ADDITIONAL_CFLAGS="-D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=600 -D__EXTENSIONS__=1 -DWITH_POSIX"
311	;;
312
313	*-darwin*)
314	AC_MSG_RESULT([Darwin])
315	ADDITIONAL_CFLAGS="-D_GNU_SOURCE -DWITH_POSIX"
316
317	AC_DEFINE(__APPLE_USE_RFC_3542, 1, [Define this to 1 for ancillary data on MacOS])
318
319	# Not yet needed but if some code definitions have to depend on the platform.
320	#AC_DEFINE(OS_MACOS, 1, [MacOS backend])
321	#AC_SUBST(OS_MACOS)
322	;;
323
324	*)
325	AC_MSG_WARN([==> Currently unsupported operating system ${host}!])
326	AC_MSG_ERROR([==> If you can provide patches to support your operating system please write to 'libcoap-developers@lists.sourceforge.net'.])
327esac
328
329# Exporting the PREDEFINED_CFLAGS definition
330PREDEFINED_CFLAGS=`echo $ADDITIONAL_CFLAGS | sed -e 's/-D//g'`
331AC_SUBST(PREDEFINED_CFLAGS)
332
333# And finaly combining the CFLAGS together ...
334CFLAGS+=" $ADDITIONAL_CFLAGS"
335
336# Override the various template files, currently just makefiles and the
337# pkgconfig *.pc file.
338# Later if the API version is changing dont forget to change the
339# libcoap-$LIBCOAP_API_VERSION.pc.in file too!! You will have to change
340# the 'Cflags' variable to something like
341#     Cflags: -I${includedir}/coap-@LIBCOAP_API_VERSION@
342#
343AC_CONFIG_FILES([
344Makefile
345doc/Makefile
346examples/Makefile
347examples/coap-client.txt
348examples/coap-server.txt
349examples/coap-rd.txt
350include/coap/coap.h
351tests/Makefile
352libcoap-$LIBCOAP_API_VERSION.pc:libcoap-$LIBCOAP_API_VERSION.pc.in
353])
354
355AC_OUTPUT
356
357AC_MSG_RESULT([
358libcoap configuration summary:
359      libcoap package version : "$PACKAGE_VERSION"
360      libcoap library version : "$LIBCOAP_SO_VERSION"
361      libcoap API version     : "$LIBCOAP_API_VERSION"
362      host system             : "$host"]);
363if test "x$build_documentation" = "xyes" -a "x$DOXYGEN" != "x"; then
364	AC_MSG_RESULT([      build documentation     : "yes"])
365	AC_MSG_RESULT([          --> Doxygen around  : "yes" ($DOXYGEN $doxygen_version)])
366	if test "x$DOT" = "x"; then
367		AC_MSG_RESULT([             -->  dot around  : "no" (DOT not found!)])
368	else
369		AC_MSG_RESULT([             -->  dot around  : "yes" ($DOT $dot_version)])
370	fi
371else
372	if test "x$build_documentation" = "xno"; then
373		AC_MSG_RESULT([      build documentation     : "no"])
374	fi
375fi
376if test "x$build_tests" = "xyes"; then
377	AC_MSG_RESULT([      build unit test binary  : "yes"])
378else
379	AC_MSG_RESULT([      build unit test binary  : "no"])
380fi
381if test "x$build_examples" = "xyes"; then
382	AC_MSG_RESULT([      build examples          : "yes"])
383	if test "x$A2X" != "x"; then
384		AC_MSG_RESULT([             -->  use a2x     : "yes" ($A2X)])
385	else
386		AC_MSG_RESULT([             -->  use a2x     : "no"])
387	fi
388else
389	AC_MSG_RESULT([      build examples          : "no"])
390fi
391