1# $Id: configure.ac 7192 2020-03-25 15:11:07Z flaterco $
2
3# Int types macros require autoconf 2.60 or later
4AC_PREREQ([2.60])
5
6# autoconf 2.65 (Slackware 13.1) has a regression that causes the INT*_T
7# tests to fail improperly.  See email from Eric Blake to the bug-autoconf
8# mailing list on 2010-02-06.
9m4_if(2.65, AC_AUTOCONF_VERSION, [m4_fatal([autoconf version 2.65 is broken and unusable])])
10
11# FIXME: Update version info on each release
12AC_INIT([libtcd], [2.2.7], [dave@flaterco.com])
13AC_SUBST([libtcd_rev_date], ["2015-08-09"])
14AC_SUBST([libtcd_major_rev], ["2"])
15AC_SUBST([libtcd_minor_rev], ["2"])
16# NOTE patchlevel must include leading period if it is provided
17AC_SUBST([libtcd_patchlevel], [".7"])
18
19# Added at the behest of libtoolize.
20AC_CONFIG_MACRO_DIR([m4])
21
22# The following is "bad" because "--enable-feature options should
23# never make a feature behave differently or cause one feature to
24# replace another.  They should only cause parts of the program to be
25# built rather than left out."  COMPAT114 is bad for the same reason.
26# Nobody should use it, but if they do, it may as well work like this.
27
28AC_SUBST([def_COMPAT114], ["undef"])
29AC_SUBST([ver_COMPAT114], [""])
30AC_ARG_ENABLE([COMPAT114],
31  [AS_HELP_STRING([--enable-COMPAT114],
32                  [for emergency use only:  force API changes to enable old applications to build; break applications expecting the v2 API; disable build of shared library; see libtcd.html])],
33  [
34    AS_IF([test "$enable_COMPAT114" = yes], [
35       AC_MSG_WARN([[COMPAT114 is enabled!]])
36       AC_MSG_WARN([[This option is for emergency use ONLY!]])
37       AC_MSG_WARN([[Forcing API changes to enable old applications to build!]])
38       AC_MSG_WARN([[This will BREAK applications expecting the v2 API!]])
39       AC_MSG_WARN([[Disabling build of shared library!]])
40       AC_MSG_WARN([[Read libtcd.html!]])
41       enable_shared=no
42       AC_SUBST([def_COMPAT114], ["define"])
43       AC_SUBST([ver_COMPAT114], ["-COMPAT114"])
44    ])
45  ])
46AC_ARG_ENABLE([lm_hard],
47  [AS_HELP_STRING([--enable-lm_hard],
48                  [link with libm_hard instead of libm (for ARM Android)])],
49  [
50    AS_IF([test "$enable_lm_hard" = yes], [
51       AC_MSG_NOTICE([[Linking with libm_hard instead of libm.]])
52       LIBS="$LIBS -lm_hard"
53    ], [
54       LIBS="$LIBS -lm"
55    ])
56  ],
57  [
58    LIBS="$LIBS -lm"
59  ])
60
61AM_INIT_AUTOMAKE([-Wall -Werror])
62
63AC_LANG([C])
64AC_PROG_CC
65m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
66AC_PROG_LIBTOOL
67
68AC_TYPE_INT8_T
69AC_TYPE_INT16_T
70AC_TYPE_INT32_T
71AC_TYPE_INT64_T
72
73AC_TYPE_UINT8_T
74AC_TYPE_UINT16_T
75AC_TYPE_UINT32_T
76AC_TYPE_UINT64_T
77
78# Unfortunately, we need to take this to the next level and generate a
79# header file that will work outside of autoconf.  Evil:  relying on
80# internals of autoconf macro definitions.
81
82AS_IF([test "$ac_cv_header_sys_types_h" = yes],
83      [AC_SUBST([sub_systypes], ["#include <sys/types.h>"])],
84      [AC_SUBST([sub_systypes], [""])])
85AS_IF([test "$ac_cv_header_inttypes_h" = yes],
86        [AC_SUBST([sub_inttypes], ["#include <inttypes.h>"])],
87      [test "$ac_cv_header_stdint_h" = yes],
88        [AC_SUBST([sub_inttypes], ["#include <stdint.h>"])],
89        [AC_SUBST([sub_inttypes], [""])])
90
91AS_IF([test "$ac_cv_c_int8_t" = yes],
92      [AC_SUBST([sub_int8_t], ["int8_t"])],
93      [AC_SUBST([sub_int8_t], ["$ac_cv_c_int8_t"])])
94AS_IF([test "$ac_cv_c_int16_t" = yes],
95      [AC_SUBST([sub_int16_t], ["int16_t"])],
96      [AC_SUBST([sub_int16_t], ["$ac_cv_c_int16_t"])])
97AS_IF([test "$ac_cv_c_int32_t" = yes],
98      [AC_SUBST([sub_int32_t], ["int32_t"])],
99      [AC_SUBST([sub_int32_t], ["$ac_cv_c_int32_t"])])
100AS_IF([test "$ac_cv_c_int64_t" = yes],
101      [AC_SUBST([sub_int64_t], ["int64_t"])],
102      [AC_SUBST([sub_int64_t], ["$ac_cv_c_int64_t"])])
103
104AS_IF([test "$ac_cv_c_uint8_t" = yes],
105      [AC_SUBST([sub_uint8_t], ["uint8_t"])],
106      [AC_SUBST([sub_uint8_t], ["$ac_cv_c_uint8_t"])])
107AS_IF([test "$ac_cv_c_uint16_t" = yes],
108      [AC_SUBST([sub_uint16_t], ["uint16_t"])],
109      [AC_SUBST([sub_uint16_t], ["$ac_cv_c_uint16_t"])])
110AS_IF([test "$ac_cv_c_uint32_t" = yes],
111      [AC_SUBST([sub_uint32_t], ["uint32_t"])],
112      [AC_SUBST([sub_uint32_t], ["$ac_cv_c_uint32_t"])])
113AS_IF([test "$ac_cv_c_uint64_t" = yes],
114      [AC_SUBST([sub_uint64_t], ["uint64_t"])],
115      [AC_SUBST([sub_uint64_t], ["$ac_cv_c_uint64_t"])])
116
117# Visual C++ 2008 Express Edition has io.h but not unistd.h.
118AC_CHECK_HEADERS([io.h])
119
120# Visual C++ 2008 Express Edition has _chsize but not ftruncate.
121AC_MSG_CHECKING([for ftruncate])
122AC_LINK_IFELSE(
123 [AC_LANG_PROGRAM([[
124#ifdef HAVE_UNISTD_H
125#include <unistd.h>
126#endif
127#ifdef HAVE_IO_H
128#include <io.h>
129#endif
130                  ]], [[ftruncate (0, 0)]])],
131  AC_MSG_RESULT([yes]),
132 [AC_MSG_RESULT([no])
133  AC_MSG_CHECKING([for _chsize])
134  AC_LINK_IFELSE(
135   [AC_LANG_PROGRAM([[
136#ifdef HAVE_UNISTD_H
137#include <unistd.h>
138#endif
139#ifdef HAVE_IO_H
140#include <io.h>
141#endif
142		    ]], [[_chsize (0, 0)]])],
143   [
144    AC_MSG_RESULT([yes])
145    AC_DEFINE(ftruncate, _chsize)
146   ],
147   [AC_MSG_RESULT([no])
148    AC_MSG_ERROR([found neither ftruncate nor _chsize.])
149   ])
150 ])
151
152# Visual C++ 2008 Express Edition uses #pragma message not #warning.
153AC_SUBST([def_PRAGMAMESSAGE], ["undef"])
154AC_MSG_CHECKING([[if #warning works]])
155AC_COMPILE_IFELSE(
156 [AC_LANG_PROGRAM([[]], [[#warning warning]])],
157  AC_MSG_RESULT([yes]),
158 [AC_MSG_RESULT([no])
159  AC_MSG_CHECKING([[if #pragma message works]])
160  AC_COMPILE_IFELSE(
161   [AC_LANG_PROGRAM([[]], [[#pragma message("warning")]])],
162   [
163    AC_MSG_RESULT([yes])
164    AC_SUBST([def_PRAGMAMESSAGE], ["define"])
165   ],
166   [AC_MSG_RESULT([no])
167   ])
168 ])
169
170AC_CONFIG_FILES([Makefile tcd.h])
171AC_OUTPUT
172