1dnl Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
2dnl
3dnl Permission is hereby granted, free of charge, to any person obtaining a
4dnl copy of this software and associated documentation files (the "Software"),
5dnl to deal in the Software without restriction, including without limitation
6dnl the rights to use, copy, modify, merge, publish, distribute, sublicense,
7dnl and/or sell copies of the Software, and to permit persons to whom the
8dnl Software is furnished to do so, subject to the following conditions:
9dnl
10dnl The above copyright notice and this permission notice (including the next
11dnl paragraph) shall be included in all copies or substantial portions of the
12dnl Software.
13dnl
14dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15dnl IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16dnl FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17dnl THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18dnl LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19dnl FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20dnl DEALINGS IN THE SOFTWARE.
21dnl
22dnl Process this file with autoconf to create configure.
23
24# Initialize Autoconf
25AC_PREREQ([2.60])
26AC_INIT([rgb], [1.1.0],
27	[https://gitlab.freedesktop.org/xorg/app/rgb/-/issues], [rgb])
28AC_CONFIG_SRCDIR([Makefile.am])
29AC_CONFIG_HEADERS([config.h])
30AC_USE_SYSTEM_EXTENSIONS
31
32# Initialize Automake
33AM_INIT_AUTOMAKE([foreign dist-xz])
34
35# Require X.Org macros 1.8 or later for MAN_SUBSTS set by XORG_MANPAGE_SECTIONS
36m4_ifndef([XORG_MACROS_VERSION],
37	  [m4_fatal([must install xorg-macros 1.8 or later before running autoconf/autogen])])
38XORG_MACROS_VERSION(1.8)
39XORG_DEFAULT_OPTIONS
40
41AC_CHECK_FUNCS([asprintf])
42
43PKG_CHECK_MODULES(RGB, xproto)
44
45AC_MSG_CHECKING([for rgb database location])
46AC_ARG_WITH([rgb-db-dir],
47	AS_HELP_STRING([--with-rgb-db-dir=<path>],
48		[rgb database location (default is ${datadir}/X11/rgb)]),
49	[db_path=$withval], [db_path=${datadir}/X11/rgb])
50AC_MSG_RESULT([$db_path])
51dnl XXX not working - AC_DEFINE([RGB_DB], $db_path, [set to location of rgb database (without any file type suffix)])
52db_file=`basename $db_path`
53db_dir=`dirname $db_path`
54AC_SUBST([db_file])
55AC_SUBST([db_dir])
56
57AC_MSG_CHECKING([for rgb database format])
58AC_ARG_WITH([rgb-db-type],
59	AS_HELP_STRING([--with-rgb-db-type=(text|dbm|ndbm)],
60		[rgb database type (default is text)]),
61	[db_type=$withval], [db_type="text"])
62AC_MSG_RESULT([$db_type])
63
64RGB_DB_TYPE=$db_type
65
66AC_ARG_WITH([rgb-db-library],
67	AS_HELP_STRING([--with-rgb-db-library=<library-name>],
68		[rgb database library (default is to search for one)]),
69	[db_lib=$withval], [db_lib="auto"])
70
71case $db_type in
72	text)
73		RGB_DB_FILES=""
74		AC_DEFINE([USE_RGB_TXT], [1],
75			[Define to 1 to use plain text files for rgb database])
76		;;
77	dbm)
78		AS_IF([test "x$db_lib" = "xauto"],
79		  [AC_SEARCH_LIBS([dbminit], [db dbm nsl], [],
80		     AC_MSG_ERROR([dbm requested but dbminit() not found in any libraries]))],
81		  [AC_CHECK_LIB([$db_lib], [dbminit], [],
82		     AC_MSG_ERROR([dbm requested but dbminit() not found when linking with -l$db_lib]))])
83		AC_CHECK_HEADER([dbm.h], [DBM_HEADER='<dbm.h>'],
84		  [AC_CHECK_HEADER([rpcsvc/dbm.h], [DBM_HEADER='<rpcsvc/dbm.h>'],
85		    [AC_MSG_ERROR([dbm requested but dbm.h not found])])])
86		PKG_CHECK_MODULES(XORG, [xorg-server])
87		RGB_CFLAGS="$RGB_CFLAGS $XORG_CFLAGS"
88		RGB_DB_FILES='$(db_file).dir $(db_file).pag'
89		;;
90	ndbm)
91		# Find a dbm or ndbm implementation
92		AS_IF([test "x$db_lib" = "xauto"],
93		  [AC_SEARCH_LIBS([dbm_open], [db ndbm dbm], [],
94		     AC_MSG_ERROR([ndbm requested but dbm_open() not found in any libraries]))],
95		  [AC_CHECK_LIB([$db_lib], [dbm_open], [],
96		     AC_MSG_ERROR([ndbm requested but dbm_open() not found when linking with -l$db_lib]))])
97		AC_DEFINE([NDBM], [1],
98			  [Define to 1 if you have ndbm.h interfaces])
99		DBM_HEADER='<ndbm.h>'
100		PKG_CHECK_MODULES(XORG, [xorg-server])
101		RGB_CFLAGS="$RGB_CFLAGS $XORG_CFLAGS"
102		RGB_DB_FILES='$(db_file).dir $(db_file).pag'
103		;;
104esac
105if test x$DBM_HEADER != x ; then
106  AC_DEFINE_UNQUOTED([DBM_HEADER], [$DBM_HEADER],
107		     [Header file to include for dbm functions])
108fi
109AC_SUBST([RGB_DB_TYPE])
110AC_SUBST([RGB_DB_FILES])
111AM_CONDITIONAL(RGB_DB, [test x$db_type != xtext])
112
113AC_CONFIG_FILES([Makefile
114                 man/Makefile])
115
116AC_OUTPUT
117