configure.ac: Use pkg-config to check for python
[libsigrokdecode.git] / configure.ac
1 ##
2 ## This file is part of the libsigrokdecode project.
3 ##
4 ## Copyright (C) 2010 Bert Vermeulen <bert@biot.com>
5 ##
6 ## This program is free software: you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation, either version 3 of the License, or
9 ## (at your option) any later version.
10 ##
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ## GNU General Public License for more details.
15 ##
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 ##
19
20 # We require at least autoconf 2.63 (AC_INIT format changed there).
21 AC_PREREQ([2.63])
22
23 # libsigrokdecode package version number (NOT the same as shared lib version!).
24 m4_define([srd_package_version_major], [0])
25 m4_define([srd_package_version_minor], [2])
26 m4_define([srd_package_version_micro], [0])
27 m4_define([srd_package_version], [srd_package_version_major.srd_package_version_minor.srd_package_version_micro])
28
29 AC_INIT([libsigrokdecode], [srd_package_version],
30         [sigrok-devel@lists.sourceforge.net], [libsigrokdecode],
31         [http://www.sigrok.org])
32 AC_CONFIG_HEADER([config.h])
33 AC_CONFIG_MACRO_DIR([autostuff])
34 AC_CONFIG_AUX_DIR([autostuff])
35
36 # We require at least automake 1.11 (needed for 'silent rules').
37 AM_INIT_AUTOMAKE([1.11 -Wall -Werror check-news color-tests])
38 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
39 m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
40
41 AH_TOP([#ifndef SRD_CONFIG_H
42 #define SRD_CONFIG_H    /* To stop multiple inclusions. */])
43 AH_BOTTOM([#endif /* SRD_CONFIG_H */])
44
45 # Enable more compiler warnings via -Wall and -Wextra. Add -fvisibility=hidden
46 # and enforce use of SRD_API to explicitly mark all public API functions.
47 CFLAGS="$CFLAGS -Wall -Wextra -fvisibility=hidden"
48
49 # Checks for programs.
50 AC_PROG_CC
51 AC_PROG_CPP
52 AC_PROG_INSTALL
53 AC_PROG_LN_S
54
55 # Required for per-target flags or subdir-objects with C sources.
56 AM_PROG_CC_C_O
57
58 # Initialize libtool.
59 LT_INIT
60
61 # Initialize pkg-config.
62 # We require at least 0.22, as "Requires.private" behaviour changed there.
63 PKG_PROG_PKG_CONFIG([0.22])
64
65 # Library version for libsigrokdecode (NOT the same as the package version).
66 # Carefully read the libtool docs before updating these numbers!
67 # The algorithm for determining which number to change (and how) is nontrivial!
68 # http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info
69 SRD_LIB_VERSION_CURRENT=1
70 SRD_LIB_VERSION_REVISION=0
71 SRD_LIB_VERSION_AGE=0
72 SRD_LIB_VERSION="$SRD_LIB_VERSION_CURRENT:$SRD_LIB_VERSION_REVISION:$SRD_LIB_VERSION_AGE"
73 SRD_LIB_LDFLAGS="-version-info $SRD_LIB_VERSION"
74 AC_SUBST(SRD_LIB_VERSION_CURRENT)
75 AC_SUBST(SRD_LIB_VERSION_REVISION)
76 AC_SUBST(SRD_LIB_VERSION_AGE)
77 AC_SUBST(SRD_LIB_VERSION)
78 AC_SUBST(SRD_LIB_LDFLAGS)
79
80 # assume we can build tests/runtc unless proven otherwise
81 build_runtc="yes"
82
83 # Checks for libraries.
84
85 # libglib-2.0 is always needed.
86 # Note: glib-2.0 is part of the libsigrokdecode API
87 # (hard pkg-config requirement).
88 AM_PATH_GLIB_2_0([2.24.0],
89         [CFLAGS="$CFLAGS $GLIB_CFLAGS"; LIBS="$LIBS $GLIB_LIBS"])
90
91 # Python support. We require at least Python >= 3.0.
92 CPPFLAGS_PYTHON=""
93 LDFLAGS_PYTHON=""
94 PKG_CHECK_MODULES([python3], [python3 >= 3.0],
95         [have_python3="yes"; CPPFLAGS_PYTHON="$python3_CFLAGS";
96         LDFLAGS_PYTHON="$python3_LIBS"], [have_python3="no"])
97 case "$build" in
98 *mingw*)
99         # We currently hardcode the paths to the Python 3.2 default install
100         # location as there's no 'python-config' script on Windows, it seems.
101         # Note: We add both the /c/ and c:/ syntax (needed for cmake).
102         AC_MSG_WARN([using hardcoded Python3 configuration on MinGW])
103         CPPFLAGS_PYTHON="-I/c/Python32/include -Ic:/Python32/include"
104         LDFLAGS_PYTHON="-L/c/Python32/libs -Lc:/Python32/libs -lpython32"
105         ;;
106 *)
107         if test x"$have_python3" = xno; then
108                 AC_MSG_ERROR([python3 not found])
109         fi
110         ;;
111 esac
112 AC_SUBST(CPPFLAGS_PYTHON)
113 AC_SUBST(LDFLAGS_PYTHON)
114
115 # The Check unit testing framework is optional. Disable if not found.
116 PKG_CHECK_MODULES([check], [check >= 0.9.4],
117         [have_check="yes"; CFLAGS="$CFLAGS $check_CFLAGS";
118         LIBS="$LIBS $check_LIBS"], [have_check="no"])
119 AM_CONDITIONAL(HAVE_CHECK, test x"$have_check" = "xyes")
120
121 # Protocol decoder test framework
122 PKG_CHECK_MODULES([libsigrok], [libsigrok >= 0.2.0],
123         [LIBSIGROK_CFLAGS="$libsigrok_CFLAGS"; LIBSIGROK_LIBS="$libsigrok_LIBS"],
124         [build_runtc="no"])
125 AC_SUBST([LIBSIGROK_CFLAGS])
126 AC_SUBST([LIBSIGROK_LIBS])
127
128 # Checks for header files.
129 # These are already checked: inttypes.h stdint.h stdlib.h string.h unistd.h.
130 AC_CHECK_HEADER([sys/resource.h], [], [build_runtc="no"])
131
132 # Checks for typedefs, structures, and compiler characteristics.
133 AC_C_INLINE
134 AC_TYPE_INT8_T
135 AC_TYPE_INT16_T
136 AC_TYPE_INT32_T
137 AC_TYPE_INT64_T
138 AC_TYPE_UINT8_T
139 AC_TYPE_UINT16_T
140 AC_TYPE_UINT32_T
141 AC_TYPE_UINT64_T
142 AC_TYPE_SIZE_T
143
144 # Checks for library functions.
145 AC_CHECK_FUNCS([memset strtoull])
146
147 AC_SUBST(DECODERS_DIR, "$datadir/libsigrokdecode/decoders")
148 AC_SUBST(MAKEFLAGS, '--no-print-directory')
149 AC_SUBST(AM_LIBTOOLFLAGS, '--silent')
150
151 SRD_PACKAGE_VERSION_MAJOR=srd_package_version_major
152 SRD_PACKAGE_VERSION_MINOR=srd_package_version_minor
153 SRD_PACKAGE_VERSION_MICRO=srd_package_version_micro
154 SRD_PACKAGE_VERSION=srd_package_version
155
156 AC_SUBST(SRD_PACKAGE_VERSION_MAJOR)
157 AC_SUBST(SRD_PACKAGE_VERSION_MINOR)
158 AC_SUBST(SRD_PACKAGE_VERSION_MICRO)
159 AC_SUBST(SRD_PACKAGE_VERSION)
160
161 AM_CONDITIONAL(BUILD_RUNTC, test x"$build_runtc" = "xyes")
162
163 AC_CONFIG_FILES([Makefile
164                  version.h
165                  libsigrokdecode.pc
166                  contrib/Makefile
167                  tests/Makefile
168                 ])
169
170 AC_OUTPUT
171
172 echo
173 echo "libsigrokdecode configuration summary:"
174 echo
175 echo "  - Package version (major.minor.micro):    $SRD_PACKAGE_VERSION"
176 echo "  - Library version (current:revision:age): $SRD_LIB_VERSION"
177 echo "  - Prefix: $prefix"
178 echo "  - Building on: $build"
179 echo "  - Building for: $host"
180 echo "  - Building protocol decoder test framework: $build_runtc"
181 echo
182 echo "Detected libraries:"
183 echo
184
185 # Note: This only works for libs with pkg-config integration.
186 for lib in "glib-2.0 >= 2.24.0" "check >= 0.9.4" "libsigrok >= 0.2.0"; do
187         if `$PKG_CONFIG --exists $lib`; then
188                 ver=`$PKG_CONFIG --modversion $lib`
189                 answer="yes ($ver)"
190         else
191                 answer="no"
192         fi
193         echo "  - $lib: $answer"
194 done
195
196 echo
197 echo "Detected Python:"
198 echo
199 echo "  - Python CPPFLAGS: $CPPFLAGS_PYTHON"
200 echo "  - Python LDFLAGS: $LDFLAGS_PYTHON"
201 echo
202