configure.ac 12 KB
Newer Older
Lucas Almeida Rocha's avatar
Lucas Almeida Rocha committed
1 2 3
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

Colin Walters's avatar
Colin Walters committed
4
m4_define(pkg_major_version, 1)
5
m4_define(pkg_minor_version, 53)
6
m4_define(pkg_micro_version, 2)
Colin Walters's avatar
Colin Walters committed
7
m4_define(pkg_version, pkg_major_version.pkg_minor_version.pkg_micro_version)
8
m4_define(pkg_int_version, (pkg_major_version * 100 + pkg_minor_version) * 100 + pkg_micro_version)
Colin Walters's avatar
Colin Walters committed
9

10 11
AC_PREREQ([2.64])
AC_INIT([gjs],[pkg_version],[http://bugzilla.gnome.org/enter_bug.cgi?product=gjs],[gjs],[https://wiki.gnome.org/Projects/Gjs])
12
AM_INIT_AUTOMAKE([1.11.1 subdir-objects dist-xz no-dist-gzip tar-ustar -Wno-portability])
Philip Chimento's avatar
Philip Chimento committed
13
AX_IS_RELEASE([git-directory])
14
AC_CONFIG_SRCDIR([gjs/console.cpp])
15
AC_CONFIG_MACRO_DIR([m4])
16
AC_CONFIG_HEADERS([config.h])
17
AC_REQUIRE_AUX_FILE([tap-driver.sh])
Lucas Almeida Rocha's avatar
Lucas Almeida Rocha committed
18

19
AC_SUBST(GJS_VERSION, m4_eval(pkg_int_version))
Giovanni Campagna's avatar
Giovanni Campagna committed
20 21
AC_DEFINE([GJS_VERSION], pkg_int_version, [The gjs version as an integer])

22
AC_SUBST([GETTEXT_PACKAGE], [gjs])
Lucas Almeida Rocha's avatar
Lucas Almeida Rocha committed
23 24
AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE], ["$GETTEXT_PACKAGE"], [The name of the gettext domain])

25
AM_MAINTAINER_MODE([enable])
26
AM_SILENT_RULES([yes])
Lucas Almeida Rocha's avatar
Lucas Almeida Rocha committed
27

28 29
# our first pkg-config invocation is conditional, ensure macros still work
PKG_PROG_PKG_CONFIG
30
PKG_INSTALLDIR
31

32
AC_LANG([C++])
33
AC_USE_SYSTEM_EXTENSIONS
34
AC_PROG_CXX
Philip Chimento's avatar
Philip Chimento committed
35
AX_CXX_COMPILE_STDCXX_11
Lucas Almeida Rocha's avatar
Lucas Almeida Rocha committed
36

37
LT_PREREQ([2.2.0])
Lucas Almeida Rocha's avatar
Lucas Almeida Rocha committed
38
# no stupid static libraries
39
LT_INIT([disable-static])
Lucas Almeida Rocha's avatar
Lucas Almeida Rocha committed
40

41 42
# Other programs
AC_PROG_MKDIR_P
Philip Chimento's avatar
Philip Chimento committed
43 44
AC_PROG_LN_S
AC_PROG_SED
45
AC_PROG_AWK
46

47
AX_COMPILER_FLAGS
48

49 50 51 52 53 54
AX_CODE_COVERAGE
dnl Clang does not need to link with -lgcov
AX_CHECK_LINK_FLAG([-lgcov],, [
	CODE_COVERAGE_LIBS=
	CODE_COVERAGE_LDFLAGS=
])
55

56 57 58 59 60
AX_VALGRIND_DFLT([drd], [off])
AX_VALGRIND_DFLT([sgcheck], [off])
# DRD and sgcheck don't produce useful diagnostics at this time
AX_VALGRIND_CHECK

Lucas Almeida Rocha's avatar
Lucas Almeida Rocha committed
61
# Checks for libraries.
62
m4_define(glib_required_version, 2.50.0)
Lucas Almeida Rocha's avatar
Lucas Almeida Rocha committed
63

64
GOBJECT_INTROSPECTION_REQUIRE([1.41.4])
Giovanni Campagna's avatar
Giovanni Campagna committed
65

66
GOBJECT_REQUIREMENT="gobject-2.0 >= glib_required_version"
67
gjs_base_packages="$GOBJECT_REQUIREMENT gio-2.0"
Philip Chimento's avatar
Philip Chimento committed
68
common_packages="gthread-2.0 gio-2.0 >= glib_required_version mozjs-52"
69
gjs_packages="gobject-introspection-1.0 libffi $common_packages"
70
gjs_cairo_packages="cairo cairo-gobject $common_packages"
Philip Chimento's avatar
Philip Chimento committed
71
gjs_gtk_packages="gtk+-3.0 >= 3.20"
72
# gjs-tests links against everything
73
gjstests_packages="gio-unix-2.0 $gjs_packages"
Lucas Almeida Rocha's avatar
Lucas Almeida Rocha committed
74

75 76
AX_PKG_CHECK_MODULES([GJS], [$GOBJECT_REQUIREMENT], [$gjs_packages])
dnl These don't need to be put in the .pc file so use regular PKG_CHECK_MODULES
77 78
PKG_CHECK_MODULES([GJS_GDBUS], [$gjs_base_packages])
PKG_CHECK_MODULES([GJS_CONSOLE], [$gjs_base_packages])
79 80
PKG_CHECK_MODULES([GJSTESTS], [$gjstests_packages])

81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
CPPFLAGS_save="$CPPFLAGS"
CPPFLAGS="$GJS_CFLAGS"
LIBS_save="$LIBS"
LIBS="$GJS_LIBS"

dnl If SpiderMonkey was compiled with --enable-debug, then we need to define
dnl -DDEBUG before including js-config.h.
AC_MSG_CHECKING([whether SpiderMonkey was configured with --enable-debug])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#include <js-config.h>
#ifdef JS_DEBUG
#error debug yes, if we didn't already error out due to DEBUG not being defined
#endif
]])], [
  AC_MSG_RESULT([no])
  GJS_DEBUG_DEF=
], [
  AC_DEFINE([HAVE_DEBUG_SPIDERMONKEY], [1],
    [Define to 1 if SpiderMonkey was compiled with --enable-debug])
  GJS_DEBUG_DEF='#define DEBUG 1'
  AC_MSG_RESULT([yes])
])

# Sanity check for SpiderMonkey
AC_MSG_CHECKING([if a minimal SpiderMonkey program compiles and runs])
AC_RUN_IFELSE([AC_LANG_PROGRAM([
$GJS_DEBUG_DEF
#include <js/Initialization.h>
  ], [
if (!JS_Init()) exit(1);
JS_ShutDown();
  ])],
  [AC_MSG_RESULT([yes])],
  [AC_MSG_RESULT([no])
    AC_MSG_ERROR([Check if you are using the recommended configuration for
SpiderMonkey. See the file org.gnome.Sdk.json.in in
https://gitlab.gnome.org/GNOME/gnome-sdk-images])],
  [AC_MSG_RESULT([cross-compiling, unable to determine])])

LIBS="$LIBS_save"
CPPFLAGS="$CPPFLAGS_save"

123
# Optional cairo dep (enabled by default)
Colin Walters's avatar
Colin Walters committed
124
AC_ARG_WITH(cairo,
125 126
  [AS_HELP_STRING([--without-cairo], [Don't build cairo module])])
AS_IF([test "x$with_cairo" != "xno"],
127
  [AX_PKG_CHECK_MODULES([GJS_CAIRO], [], [$gjs_cairo_packages],
128 129
    [have_cairo=yes], [have_cairo=no])],
  [have_cairo=no])
130
AM_CONDITIONAL(ENABLE_CAIRO, test x$have_cairo = xyes)
131 132
AS_IF([test x$have_cairo = xyes], [
  AC_DEFINE([ENABLE_CAIRO],[1],[Define if you want to build with cairo support])
133
  AX_PKG_CHECK_MODULES([GJS_CAIRO_XLIB], [], [cairo-xlib], [],
134 135 136
    [AC_MSG_WARN([Cairo-xlib support not found])])
], [AS_IF([test "x$with_cairo" = "xyes"],
  [AC_MSG_ERROR([Cairo requested but not found])])])
Giovanni Campagna's avatar
Giovanni Campagna committed
137

138 139
# Optional GTK+ dep (enabled by default)
AC_ARG_WITH(gtk,
140 141
  [AS_HELP_STRING([--without-gtk], [Don't build GTK-related code])])
AS_IF([test "x$with_gtk" != "xno"],
142
  [AX_PKG_CHECK_MODULES([GJS_GTK], [], [$gjs_gtk_packages],
143 144
    [have_gtk=yes], [have_gtk=no])],
  [have_gtk=no])
145 146 147
AM_CONDITIONAL(ENABLE_GTK, test x$have_gtk = xyes)
AS_IF([test x$have_gtk = xyes], [
  AC_DEFINE([ENABLE_GTK],[1],[Define if you want to build with GTK+ support])
148 149
], [AS_IF([test "x$with_gtk" = "xyes"],
  [AC_MSG_ERROR([GTK requested but not found])])])
150

151 152 153 154 155 156 157 158 159 160 161 162
# Some Linux APIs required for profiler
AC_ARG_ENABLE([profiler],
  [AS_HELP_STRING([--disable-profiler], [Don't build profiler])])
AS_IF([test x$enable_profiler != xno], [
  gl_TIMER_TIME
  AS_IF([test x$ac_cv_func_timer_settime = xno],
    [AC_MSG_ERROR([The profiler is currently only supported on Linux.
Configure with --disable-profiler to skip it on other platforms.])])
  AC_DEFINE([ENABLE_PROFILER], [1], [Define if the profiler should be built.])
])
AM_CONDITIONAL([ENABLE_PROFILER], [test x$enable_profiler != xno])

163
PKG_CHECK_VAR([GI_DATADIR], [gobject-introspection-1.0], [gidatadir])
164

165
# readline
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
LIBS_no_readline=$LIBS

# On some systems we need to link readline to a termcap compatible
# library.
gjs_cv_lib_readline=no
AC_MSG_CHECKING([how to link readline libs])
for gjs_libtermcap in "" ncursesw ncurses curses termcap; do
  if test -z "$gjs_libtermcap"; then
    READLINE_LIBS="-lreadline"
  else
    READLINE_LIBS="-lreadline -l$gjs_libtermcap"
  fi
  LIBS="$READLINE_LIBS $LIBS_no_readline"
  AC_LINK_IFELSE(
    [AC_LANG_CALL([],[readline])],
    [gjs_cv_lib_readline=yes])
  if test $gjs_cv_lib_readline = yes; then
    break
  fi
done
if test $gjs_cv_lib_readline = no; then
  AC_MSG_RESULT([none])
188
  READLINE_LIBS=""
189
  ac_cv_header_readline_readline_h=no
190 191
else
  AC_MSG_RESULT([$READLINE_LIBS])
192
  AC_CHECK_HEADERS([readline/readline.h])
193
fi
194

195
AC_SUBST([READLINE_LIBS])
196

197 198 199
# End of readline checks: restore LIBS
LIBS=$LIBS_no_readline

200 201 202 203 204 205 206 207 208 209 210 211
AC_MSG_CHECKING([whether printf() accepts '%Id' for alternative integer output])
CXXFLAGS_save="$CXXFLAGS"
CXXFLAGS="-Werror -Wformat -pedantic-errors"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]],
  [[printf("%Id", (int)0);]])], [
    AC_MSG_RESULT([yes])
    AC_DEFINE([HAVE_PRINTF_ALTERNATIVE_INT], [1],
      [Define to 1 if printf() accepts '%Id' for alternative integer output])
  ],
  [AC_MSG_RESULT([no])])
CXXFLAGS="$CXXFLAGS_save"

212
AC_ARG_ENABLE(installed_tests,
213 214
  [AS_HELP_STRING([--enable-installed-tests],
    [Install test programs @<:@default: no@:>@])])
215 216
AM_CONDITIONAL(BUILDOPT_INSTALL_TESTS, test x$enable_installed_tests = xyes)

217 218 219 220 221
dnl
dnl Tracing
dnl

AC_ARG_ENABLE([dtrace],
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
  [AS_HELP_STRING([--enable-dtrace],
    [Include dtrace trace support @<:@default: no@:>@])])

AC_ARG_ENABLE([systemtap],
  [AS_HELP_STRING([--enable-systemtap],
    [Include systemtap trace support (implies --enable-dtrace) @<:@default: no@:>@])])
AS_IF([test "x$enable_systemtap" = "xyes"], [enable_dtrace=yes])
AM_CONDITIONAL([ENABLE_SYSTEMTAP], [test "x$enable_systemtap" = "xyes"])

AS_IF([test "x$enable_dtrace" = "xyes"], [
  AC_PATH_PROG([DTRACE], [dtrace])
  AS_IF([test -z "$DTRACE"],
    [AC_MSG_ERROR([dtrace is required for --enable-dtrace or --enable-systemtap])])
  AC_CHECK_HEADER([sys/sdt.h],,
    [AC_MSG_ERROR([sys/sdt.h header is required for --enable-dtrace or --enable-systemtap])])
237
  AC_DEFINE([HAVE_DTRACE], [1], [Define to 1 if using dtrace probes.])
238 239
])
AM_CONDITIONAL([ENABLE_DTRACE], [test "x$enable_dtrace" = "xyes"])
240

241 242 243 244
dnl
dnl Check for -Bsymbolic-functions linker flag used to avoid
dnl intra-library PLT jumps, if available.
dnl
245 246 247 248
AC_ARG_ENABLE([Bsymbolic],
  [AS_HELP_STRING([--disable-Bsymbolic], [avoid linking with -Bsymbolic])])
AS_IF([test "x$enable_Bsymbolic" != "xno"],
  [AX_APPEND_LINK_FLAGS([-Bsymbolic-functions])])
249

250 251 252 253 254 255 256 257
dnl
dnl Check for -fsanitize=address and -fsanitize=undefined support
dnl
AC_ARG_ENABLE([asan],
  [AS_HELP_STRING([--enable-asan], [Build with address sanitizer support @<:@default: no@:>@])])

AS_IF([test "x$enable_asan" = "xyes"], [
  AX_CHECK_COMPILE_FLAG([-fsanitize=address -fno-omit-frame-pointer -g], [
258 259
    AX_CHECK_LINK_FLAG([-fsanitize=address])
    SAN_FLAGS="-fsanitize=address"
260 261 262 263 264 265 266
  ])
])

AC_ARG_ENABLE([ubsan],
  [AS_HELP_STRING([--enable-ubsan], [Build with undefined behavior sanitizer support @<:@default: no@:>@])])

AS_IF([test "x$enable_ubsan" = "xyes"], [
267
  AX_CHECK_COMPILE_FLAG([-fsanitize=undefined -fno-sanitize=vptr -fno-omit-frame-pointer -g], [
268 269
    AX_CHECK_LINK_FLAG([-fsanitize=undefined -fno-sanitize=vptr])
    SAN_FLAGS="$SAN_FLAGS -fsanitize=undefined -fno-sanitize=vptr"
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
  ])
])

# According to https://github.com/google/sanitizers/issues/380, asan is not
# compatible with -no-undefined.
NO_UNDEFINED_FLAG=-no-undefined
AS_IF([test -n "${SAN_FLAGS}"], [
    GJS_CFLAGS="$GJS_CFLAGS $SAN_FLAGS -fno-omit-frame-pointer -g"
    # We have to clobber LDFLAGS here and not use AM_LDFLAGS, or else
    # g-ir-scanner will not pick it up.
    LDFLAGS="$LDFLAGS $SAN_FLAGS"
    NO_UNDEFINED_FLAG=
])
AC_SUBST([NO_UNDEFINED_FLAG])

285 286 287 288 289
# This is needed (at least) for clang on Ubuntu PIC (Position-Independent Code)
AX_APPEND_COMPILE_FLAGS([$lt_prog_compiler_pic], [CXXFLAGS])
AX_APPEND_COMPILE_FLAGS([$lt_prog_compiler_pic], [CFLAGS])
AX_APPEND_LINK_FLAGS([$lt_prog_compiler_pic])

290 291 292 293 294 295 296 297 298 299
AC_ARG_WITH([xvfb-tests],
  [AS_HELP_STRING([--with-xvfb-tests],
    [Run all tests under an XVFB server @<:@default=no@:>@])])
AS_IF([test "x$with_xvfb_tests" = "xyes"], [
  AC_PATH_PROG([XVFB], [Xvfb])
  AS_IF([test -z "$XVFB"],
    [AC_MSG_ERROR([Xvfb is required for --with-xvfb-tests])])
])
AM_CONDITIONAL([XVFB_TESTS], [test "x$with_xvfb_tests" = "xyes"])

300 301 302 303
AC_ARG_WITH([dbus-tests],
  [AS_HELP_STRING([--without-dbus-tests],
    [Don't try to use DBus during make check @<:@default=use@:>@])])
AS_IF([test "x$with_dbus_tests" != "xno"], [
Philip Chimento's avatar
Philip Chimento committed
304 305 306
  AC_PATH_PROG([DBUS_RUN_SESSION], [dbus-run-session])
  AS_IF([test -z "$DBUS_RUN_SESSION"],
    [AC_MSG_ERROR([dbus-run-session is required for --with-dbus-tests])])
307 308 309
])
AM_CONDITIONAL([DBUS_TESTS], [test "x$with_dbus_tests" != "xno"])

310
AC_SUBST([gjsjsdir], [\${datadir}/gjs-1.0])
Lucas Almeida Rocha's avatar
Lucas Almeida Rocha committed
311

312 313 314
dnl automake 1.11/1.12 defines this but does not substitute it
AC_SUBST([pkglibexecdir], ["${libexecdir}/${PACKAGE}"])

315
AC_CONFIG_FILES([Makefile gjs-1.0.pc win32/config.h.win32])
316 317 318 319 320 321 322 323 324 325 326
dnl Symlink the files from gobject-introspection's test libraries into the tree;
dnl Automake plans to drop support for compiling them in-place.
AC_CONFIG_LINKS([
  installed-tests/gitestmacros.h:$GI_DATADIR/tests/gitestmacros.h
  installed-tests/regress.c:$GI_DATADIR/tests/regress.c
  installed-tests/regress.h:$GI_DATADIR/tests/regress.h
  installed-tests/warnlib.c:$GI_DATADIR/tests/warnlib.c
  installed-tests/warnlib.h:$GI_DATADIR/tests/warnlib.h
  installed-tests/gimarshallingtests.c:$GI_DATADIR/tests/gimarshallingtests.c
  installed-tests/gimarshallingtests.h:$GI_DATADIR/tests/gimarshallingtests.h
])
Lucas Almeida Rocha's avatar
Lucas Almeida Rocha committed
327
AC_OUTPUT
Colin Walters's avatar
Colin Walters committed
328

329
# Warn about conditions that affect runtime
330
PKG_CHECK_EXISTS([gobject-introspection-1.0 >= 1.53.4], [], [
331 332 333 334
    AC_MSG_WARN([You do not have a new enough version of
gobject-introspection to run the tests. You can still build GJS, but some
tests will fail.])])

335 336 337 338
TEST_MSG=
AM_COND_IF([XVFB_TESTS], [TEST_MSG="xvfb "])
AM_COND_IF([DBUS_TESTS], [TEST_MSG="${TEST_MSG}dbus"])
AS_IF([test -z "$TEST_MSG"], [TEST_MSG="nothing special"])
339

Colin Walters's avatar
Colin Walters committed
340 341 342 343 344 345 346
AC_MSG_RESULT([
        $PACKAGE_NAME $VERSION

	GJS_CFLAGS:		${GJS_CFLAGS}
	GJS_LIBS:		${GJS_LIBS}

	cairo:			${have_cairo}
347
	GTK+:			${have_gtk}
348
	readline:		${ac_cv_header_readline_readline_h}
349 350
	dtrace:			${enable_dtrace:-no}
	systemtap:		${enable_systemtap:-no}
351
	Profiler:		${enable_profiler:-yes}
352
	Run tests under:	${TEST_MSG}
353
	Code coverage:		${enable_code_coverage}
Colin Walters's avatar
Colin Walters committed
354
])