1#
2#  Copyright © 2019 Thomas Dickey
3#  Copyright © 2003 Keith Packard, Noah Levitt
4#
5#  Permission to use, copy, modify, distribute, and sell this software and its
6#  documentation for any purpose is hereby granted without fee, provided that
7#  the above copyright notice appear in all copies and that both that
8#  copyright notice and this permission notice appear in supporting
9#  documentation, and that the name of Keith Packard not be used in
10#  advertising or publicity pertaining to distribution of the software without
11#  specific, written prior permission.  Keith Packard makes no
12#  representations about the suitability of this software for any purpose.  It
13#  is provided "as is" without express or implied warranty.
14#
15#  KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16#  INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17#  EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18#  CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19#  DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20#  TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21#  PERFORMANCE OF THIS SOFTWARE.
22#
23
24# Initialize Autoconf
25AC_PREREQ([2.70])
26AC_INIT([libXt], [1.3.1],
27	[https://gitlab.freedesktop.org/xorg/lib/libxt/-/issues/], [libXt])
28AC_CONFIG_SRCDIR([Makefile.am])
29AC_CONFIG_HEADERS([config.h])
30AC_CONFIG_MACRO_DIR([m4])
31
32# Set common system defines for POSIX extensions, such as _GNU_SOURCE
33# Must be called before any macros that run the compiler (like AC_PROG_LIBTOOL)
34# to avoid autoconf errors.
35AC_USE_SYSTEM_EXTENSIONS
36
37# Initialize Automake
38AM_INIT_AUTOMAKE([foreign dist-xz])
39
40# Initialize libtool
41LT_INIT
42
43# Require X.Org macros 1.16 or later for XORG_MEMORY_CHECK_FLAGS
44m4_ifndef([XORG_MACROS_VERSION],
45	  [m4_fatal([must install xorg-macros 1.16 or later before running autoconf/autogen])])
46XORG_MACROS_VERSION(1.16)
47XORG_DEFAULT_OPTIONS
48XORG_CHECK_MALLOC_ZERO
49XORG_ENABLE_SPECS
50XORG_WITH_XMLTO(0.0.20)
51XORG_WITH_FOP
52XORG_WITH_XSLTPROC
53XORG_CHECK_SGML_DOCTOOLS(1.01)
54XORG_PROG_RAWCPP
55XORG_WITH_PERL
56
57
58# Checks for header files.
59AC_CHECK_HEADER([alloca.h], AC_DEFINE(INCLUDE_ALLOCA_H, 1, [Define to 1 if Xalloca.h should include <alloca.h>]))
60
61# Checks for library functions.
62AC_CHECK_FUNCS([reallocarray])
63
64# Obtain compiler/linker options for dependencies
65PKG_CHECK_MODULES(XT, sm ice x11 xproto kbproto)
66
67# Set-up variables to use build machine compiler when cross-compiling
68if test x"$CC_FOR_BUILD" = x; then
69	if test x"$cross_compiling" = xyes; then
70		AC_CHECK_PROGS(CC_FOR_BUILD, gcc cc)
71	else
72		CC_FOR_BUILD="$CC"
73	fi
74fi
75if test x"$cross_compiling" != xyes; then
76       : ${CFLAGS_FOR_BUILD=${CFLAGS}}
77       : ${LDFLAGS_FOR_BUILD=${LDFLAGS}}
78fi
79AC_SUBST([CC_FOR_BUILD])
80DEFAULT_CPPFLAGS_FOR_BUILD="${CPPFLAGS}"
81AC_CHECK_FUNC(asprintf,
82  [DEFAULT_CPPFLAGS_FOR_BUILD="${DEFAULT_CPPFLAGS_FOR_BUILD} -DHAVE_ASPRINTF -D_GNU_SOURCE"])
83CPPFLAGS_FOR_BUILD=${CPPFLAGS_FOR_BUILD-${DEFAULT_CPPFLAGS_FOR_BUILD}}
84AC_SUBST(CPPFLAGS_FOR_BUILD)
85DEFAULT_CFLAGS_FOR_BUILD="${CFLAGS} ${CWARNFLAGS}"
86AC_SUBST(CFLAGS_FOR_BUILD)
87AC_SUBST(LDFLAGS_FOR_BUILD)
88
89# Map function checks to old Imake #defines
90case $host_os in
91	# darwin through Snow Leopard has poll() but can't be used to poll character devices.
92	darwin@<:@789@:>@*|darwin10*) ;;
93	darwin*)
94		_ac_xorg_macosx_version_min=""
95		if echo $CPPFLAGS $CFLAGS | grep -q mmacosx-version-min ; then
96			_ac_xorg_macosx_version_min=`echo $CPPFLAGS $CFLAGS | sed 's/^.*-mmacosx-version-min=\(@<:@^ @:>@*\).*$/\1/'`
97		else
98			_ac_xorg_macosx_version_min=$MACOSX_DEPLOYMENT_TARGET
99		fi
100		case $_ac_xorg_macosx_version_min in
101			10.@<:@0123456@:>@|10.@<:@0123456@:>@.*) ;;
102			*)
103				AC_CHECK_FUNC(poll, [AC_DEFINE(USE_POLL, 1, [poll() function is available])], )
104			;;
105		esac
106		unset _ac_xorg_macosx_version_min
107		;;
108	*)
109		AC_CHECK_FUNC(poll, [AC_DEFINE(USE_POLL, 1, [poll() function is available])], )
110	;;
111esac
112
113# Link with winsock if mingw target
114case $host_os in
115	*mingw*)
116		AC_CHECK_LIB([ws2_32],[main])
117	;;
118	*)
119	;;
120esac
121
122# Options
123AC_MSG_CHECKING(if XKB support is wanted)
124AC_ARG_ENABLE(xkb, AS_HELP_STRING([--disable-xkb], [Disable XKB support]),
125	XKB="$enableval", XKB="yes")
126AC_MSG_RESULT($XKB)
127if test "x$XKB" = "xyes" ; then
128	AC_DEFINE(XKB, 1, [Define to 1 to use XKB for keysym resolution.])
129fi
130
131AC_MSG_CHECKING(if C const-support is wanted)
132AC_ARG_ENABLE(const, AS_HELP_STRING([--disable-const], [Disable const-support]),
133	USE_CONST="$enableval", USE_CONST="yes")
134AC_MSG_RESULT($USE_CONST)
135if test "x$USE_CONST" = "xyes" ; then
136	AC_DEFINE(_CONST_X_STRING, 1, [Define to 1 to use standard C const feature.])
137fi
138
139AC_MSG_CHECKING(if geo-tattler traces are wanted)
140AC_ARG_ENABLE(geo-tattler, AS_HELP_STRING([--enable-geo-tattler], [Enable geo-tattler traces]),
141	GEO_TATTLER="$enableval", GEO_TATTLER="no")
142AC_MSG_RESULT($GEO_TATTLER)
143if test "x$GEO_TATTLER" = "xyes" ; then
144	AC_DEFINE(XT_GEO_TATTLER, 1, [Define to 1 to enable geo-tattler traces.])
145fi
146
147# --enable-unit-tests
148XORG_ENABLE_UNIT_TESTS
149XORG_WITH_GLIB([2.40])
150XORG_MEMORY_CHECK_FLAGS
151if test "x$enable_unit_tests" != "xno" ; then
152	AC_CHECK_FUNCS([malloc_usable_size])
153	AC_CHECK_HEADERS([malloc.h])
154fi
155
156# Replaces XFileSearchPathDefault from Imake configs
157XFILESEARCHPATHDEFAULT='$(sysconfdir)/X11/%L/%T/%N%C%S:$(sysconfdir)/X11/%l/%T/%N%C%S:$(sysconfdir)/X11/%T/%N%C%S:$(sysconfdir)/X11/%L/%T/%N%S:$(sysconfdir)/X11/%l/%T/%N%S:$(sysconfdir)/X11/%T/%N%S:$(datadir)/X11/%L/%T/%N%C%S:$(datadir)/X11/%l/%T/%N%C%S:$(datadir)/X11/%T/%N%C%S:$(datadir)/X11/%L/%T/%N%S:$(datadir)/X11/%l/%T/%N%S:$(datadir)/X11/%T/%N%S:$(libdir)/X11/%L/%T/%N%C%S:$(libdir)/X11/%l/%T/%N%C%S:$(libdir)/X11/%T/%N%C%S:$(libdir)/X11/%L/%T/%N%S:$(libdir)/X11/%l/%T/%N%S:$(libdir)/X11/%T/%N%S'
158
159AC_MSG_CHECKING(for X files search path)
160AC_ARG_WITH(xfile-search-path,
161	AS_HELP_STRING([--with-xfile-search-path=<path>],
162		       [Set path to search for app-defaults and other files]),
163	[XFILESEARCHPATHDEFAULT="$withval"], [])
164AC_MSG_RESULT(${XFILESEARCHPATHDEFAULT:-none})
165AC_SUBST([XFILESEARCHPATHDEFAULT])
166
167AC_MSG_CHECKING(for X app-defaults directory)
168AC_ARG_WITH(appdefaultdir,
169	AS_HELP_STRING([--with-appdefaultdir=<path>],
170		       [Set app-default directory (default: ${datadir}/X11/app-defaults)]),
171	[appdefaultdir="$withval"],
172	[appdefaultdir=${datadir}/X11/app-defaults])
173AC_MSG_RESULT($appdefaultdir)
174AX_DEFINE_DIR([appdefaultdir], [appdefaultdir], [app default data directory])
175
176# Replacement for Imake ToolkitStringsABIOptions, controls string tables
177# generated by util/string.list in StringDefs.h & Shell.h
178AC_MSG_CHECKING(for ABI options)
179case $host_os in
180	solaris*)
181		# Solaris uses -intelabi even on SPARC
182		STRINGSABIOPTIONS="-intelabi -solarisabinames"
183		;;
184	sco* | svr4*)
185		case $host_cpu in
186		    i*86) STRINGSABIOPTIONS="-intelabi" ;;
187		       *) STRINGSABIOPTIONS="" ;;
188		esac
189		;;
190esac
191AC_MSG_RESULT(${STRINGSABIOPTIONS:-none})
192AC_SUBST(STRINGSABIOPTIONS)
193
194ERRORDBDIR=${datadir}/X11
195AC_SUBST(ERRORDBDIR)
196
197AC_CONFIG_FILES([Makefile
198		src/Makefile
199		util/Makefile
200		include/Makefile
201		man/Makefile
202		specs/Makefile
203		specs/libXt.ent
204		test/Makefile
205		xt.pc])
206AC_OUTPUT
207