setup.py: Rework pycairo discovery to not use pkg-config
[pygobject.git] / configure.ac
blobf55a54afada3c52c56b405d6e4e5d802cfbd074f
1 -*- mode: m4 -*-
2 AC_PREREQ([2.68])
4 # The version of python used is determined by the executable pointed to by the
5 # --with-python switch, or if that's not set, by the PYTHON environment
6 # variable.  For instance if your system installs Python 3 as python3 to
7 # configure to compile pygobject under Python 3 you would do this:
8 #   $ ./configure --with-python=python3
9 # or
10 #   $ PYTHON=python3 ./configure
12 # You can also build against a full interpreter path, such as
13 #   $ ./configure --with-python=~/my-patched-python/python
15 m4_define(python_min_ver, 2.7)
16 m4_define(python3_min_ver, 3.4)
18 dnl the pygobject version number
19 m4_define(pygobject_major_version, 3)
20 m4_define(pygobject_minor_version, 27)
21 m4_define(pygobject_micro_version, 1)
22 m4_define(pygobject_version, pygobject_major_version.pygobject_minor_version.pygobject_micro_version)
24 dnl versions of packages we require ...
25 m4_define(introspection_required_version, 1.46.0)
26 m4_define(pycairo_required_version, 1.11.1)
27 m4_define(glib_required_version, 2.38.0)
28 m4_define(gio_required_version, 2.38.0)
29 m4_define(libffi_required_version, 3.0)
31 AC_INIT([pygobject],[pygobject_version],
32         [http://bugzilla.gnome.org/enter_bug.cgi?product=pygobject],
33         [pygobject],[https://wiki.gnome.org/Projects/PyGObject/])
35 m4_ifndef([AX_IS_RELEASE], [AC_MSG_ERROR(['autoconf-archive' missing])])
37 AX_IS_RELEASE([minor-version])
38 AC_CONFIG_MACRO_DIR([m4])
39 AC_CONFIG_SRCDIR([gi/gimodule.c])
41 AC_DEFINE(PYGOBJECT_MAJOR_VERSION, pygobject_major_version, [pygobject major version])
42 AC_SUBST(PYGOBJECT_MAJOR_VERSION, pygobject_major_version)
43 AC_DEFINE(PYGOBJECT_MINOR_VERSION, pygobject_minor_version, [pygobject minor version])
44 AC_SUBST(PYGOBJECT_MINOR_VERSION, pygobject_minor_version)
45 AC_DEFINE(PYGOBJECT_MICRO_VERSION, pygobject_micro_version, [pygobject micro version])
46 AC_SUBST(PYGOBJECT_MICRO_VERSION, pygobject_micro_version)
48 AC_CONFIG_HEADERS(config.h)
49 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES(yes)])
50 AM_INIT_AUTOMAKE([1.13 foreign no-dist-gzip dist-xz])
52 AC_CANONICAL_BUILD
53 AC_CANONICAL_HOST
54 AC_MSG_CHECKING([for build time linking with Python (Win32)])
55 case "$host" in
56   *-*-mingw*|*-*-cygwin*)
57     os_win32=yes
58     link_python_libs=yes
59     OS_EXT=dll
60     ;;
61   *-*-darwin*)
62     os_win32=no
63     link_python_libs=no
64     OS_EXT=dylib
65     ;;
66   *)
67     os_win32=no
68     link_python_libs=no
69     OS_EXT=so
70     ;;
71 esac
72 AC_MSG_RESULT([$link_python_libs])
73 AM_CONDITIONAL(OS_WIN32, test "$os_win32" = "yes")
75 AC_SUBST(OS_EXT)
76 AC_DEFINE_UNQUOTED(OS_EXT, "$OS_EXT", [Define shared library extension])
78 LT_PREREQ([2.2.6])
79 LT_INIT([dlopen win32-dll disable-static])
81 AC_SEARCH_LIBS([strerror],[cposix])
82 AC_PROG_CC
83 AM_PROG_CC_C_O
85 # option to specify python interpreter to use; this just sets $PYTHON, so that
86 # we will fallback to reading $PYTHON if --with-python is not given, and
87 # python.m4 will get the expected input
88 AC_ARG_WITH(python,
89   AS_HELP_STRING([--with-python=PATH],[Path to Python interpreter; searches $PATH if only a program name is given; if not given, searches for a few standard names such as "python3" or "python2"]),
90   [PYTHON="$withval"], [])
91 if test x"$PYTHON" = xyes; then
92         AC_MSG_ERROR([--with-python option requires a path or program argument])
94 if test -n "$PYTHON" && ! which "$PYTHON"; then
95         AC_MSG_ERROR([Python interpreter $PYTHON does not exist])
98 # check that we have the minimum version of python necessary to build
99 JD_PATH_PYTHON(python_min_ver)
101 # check if we are building for python 3
102 AM_PYTHON_CHECK_VERSION([$PYTHON], [3.0],
103                          build_py3k=true,
104                          build_py3k=false)
106 # if building for python 3 make sure we have the minimum version supported
107 if test $build_py3k = true ; then
108   AC_MSG_CHECKING([for $PYTHON >=] python3_min_ver)
109   AM_PYTHON_CHECK_VERSION([$PYTHON], python3_min_ver,
110                           [AC_MSG_RESULT(yes)],
111                           [AC_MSG_ERROR(too old)])
114 # - 'SO' for PyPy, CPython 2.7-3.2
115 # - 'EXT_SUFFIX' for CPython3.3+ (http://bugs.python.org/issue16754)
116 # - fallback to '.so'
117 PYTHON_SO=`$PYTHON -c "import distutils.sysconfig, sys; get = distutils.sysconfig.get_config_var; sys.stdout.write(get('EXT_SUFFIX') or get('SO') or '.so');"`
118 AC_SUBST(PYTHON_SO)
120 PYG_CHECK_PYTHON_HEADERS(, AC_MSG_ERROR([Python headers not found]))
121 if test "x$link_python_libs" = "xyes"; then
122   PYG_CHECK_PYTHON_LIBS(, AC_MSG_ERROR([Python libs not found. Windows requires Python modules to be explicitly linked to libpython.]))
125 dnl get rid of the -export-dynamic stuff from the configure flags ...
126 export_dynamic=`(./libtool --config; echo eval echo \\$export_dynamic_flag_spec) | sh`
128 dnl glib
129 AM_PATH_GLIB_2_0(glib_required_version,,[AC_MSG_ERROR(maybe you want the pygobject-2-4 branch?)],gobject $extra_mods)
130 if test -n "$export_dynamic"; then
131   GLIB_LIBS=`echo $GLIB_LIBS | sed -e "s/$export_dynamic//"`
134 PYTHON_VALGRIND_SUPP=`$PYTHON -c "import sys; sys.stdout.write('python' + sys.version.__getitem__(0))"`
135 AC_SUBST([PYTHON_VALGRIND_SUPP])
137 dnl libffi
138 PKG_CHECK_MODULES(FFI, libffi >= libffi_required_version)
139 LIBFFI_PC=libffi
141 AC_SUBST(FFI_CFLAGS)
142 AC_SUBST(FFI_LIBS)
143 AC_SUBST(LIBFFI_PC)
145 dnl gio
146 PKG_CHECK_MODULES(GIO, gio-2.0 >= gio_required_version)
148 AC_ARG_ENABLE(cairo,
149     AS_HELP_STRING([--enable-cairo],[Enable Cairo bindings using introspection information]),
150     enable_cairo=$enableval,
151     enable_cairo=yes)
153 PKG_CHECK_MODULES(GI,
154     glib-2.0 >= glib_required_version
155     gobject-introspection-1.0 >= introspection_required_version
158 GOBJECT_INTROSPECTION_CHECK(introspection_required_version)
160 GI_DATADIR=$($PKG_CONFIG --variable=gidatadir gobject-introspection-1.0)
161 AC_SUBST(GI_DATADIR)
163 if test "$enable_cairo" != no; then
164     PKG_CHECK_MODULES(CAIRO, cairo cairo-gobject)
166     if test $build_py3k = true; then
167         PKG_CHECK_MODULES(PYCAIRO,
168             py3cairo >= pycairo_required_version
169         )
170     else
171         PKG_CHECK_MODULES(PYCAIRO,
172             pycairo >= pycairo_required_version
173         )
174     fi
176 AM_CONDITIONAL(ENABLE_CAIRO, test "$enable_cairo" = "yes")
178 AC_ARG_WITH(common,
179     AS_HELP_STRING([--without-common],
180         [For package maintainers: do not install Python version independent files]),
181     with_common=$enableval,
182     with_common=yes)
183 AM_CONDITIONAL(WITH_COMMON, test "$with_common" = "yes")
185 # Disable -Werror always, see
186 # https://mail.gnome.org/archives/desktop-devel-list/2017-April/msg00009.html
187 AX_COMPILER_FLAGS(,, [yes])
188 # Disable some warnings, either because they get generated by headers of
189 # dependencies we don't control or because it was hard to fix them.
190 # Feel free and try to get rid of them.
191 # For clang only:
192 AX_APPEND_COMPILE_FLAGS([-Wno-unknown-warning-option -Wno-incompatible-pointer-types-discards-qualifiers -Wno-cast-align])
193 # For gcc + clang:
194 AX_APPEND_COMPILE_FLAGS([-Wno-discarded-qualifiers -Wno-redundant-decls -Wno-switch-enum -Wno-undef])
196 AX_CODE_COVERAGE()
198 AC_CONFIG_FILES(
199   Makefile
200   pygobject-3.0.pc
201   gi/Makefile
202   gi/repository/Makefile
203   gi/overrides/Makefile
204   examples/Makefile
205   tests/Makefile
206   pygtkcompat/Makefile
207   PKG-INFO)
208 AC_OUTPUT
210 AC_MSG_RESULT([
211         pygobject $VERSION
213         Is release:                     $ax_is_release
214         Using python interpreter:       $PYTHON
215         cairo support:                  $enable_cairo
216         code coverage support:          $enable_code_coverage