1 dnl This Source Code Form is subject to the terms of the Mozilla Public
2 dnl License, v. 2.0. If a copy of the MPL was not distributed with this
3 dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 AC_DEFUN([MOZ_CONFIG_NSPR], [
7 ifelse([$1],,define(CONFIGURING_JS,yes))
9 dnl Possible ways this can be called:
10 dnl from toplevel configure:
11 dnl JS_STANDALONE= BUILDING_JS=
12 dnl from js/src/configure invoked by toplevel configure:
13 dnl JS_STANDALONE= BUILDING_JS=1
14 dnl from standalone js/src/configure:
15 dnl JS_STANDALONE=1 BUILDING_JS=1
17 dnl ========================================================
18 dnl = Find the right NSPR to use.
19 dnl ========================================================
20 MOZ_ARG_WITH_STRING(nspr-cflags,
21 [ --with-nspr-cflags=FLAGS
22 Pass FLAGS to CC when building code that uses NSPR.
23 Use this when there's no accurate nspr-config
24 script available. This is the case when building
25 SpiderMonkey as part of the Mozilla tree: the
26 top-level configure script computes NSPR flags
27 that accomodate the quirks of that environment.],
29 MOZ_ARG_WITH_STRING(nspr-libs,
30 [ --with-nspr-libs=LIBS Pass LIBS to LD when linking code that uses NSPR.
31 See --with-nspr-cflags for more details.],
34 ifdef([CONFIGURING_JS],[
35 MOZ_ARG_ENABLE_BOOL(nspr-build,
36 [ --enable-nspr-build Configure and build NSPR from source tree],
41 if test -z "$BUILDING_JS" || test -n "$JS_STANDALONE"; then
45 MOZ_ARG_WITH_BOOL(system-nspr,
46 [ --with-system-nspr Use an NSPR that is already built and installed.
47 Use the 'nspr-config' script in the current path,
48 or look for the script in the directories given with
49 --with-nspr-exec-prefix or --with-nspr-prefix.
50 (Those flags are only checked if you specify
51 --with-system-nspr.)],
54 if test -z "$BUILDING_JS"; then
59 ifdef([CONFIGURING_JS],[
60 if test -n "$JS_STANDALONE"; then
62 *linux*|*darwin*|*dragonfly*|*freebsd*|*netbsd*|*openbsd*)
63 if test -z "$_HAS_NSPR" && test "$JS_THREADSAFE"; then
64 JS_POSIX_NSPR_DEFAULT=1
70 MOZ_ARG_ENABLE_BOOL(posix-nspr-emulation,
71 [ --enable-posix-nspr-emulation
72 Enable emulation of NSPR for POSIX systems],
77 dnl Pass at most one of
78 dnl --with-system-nspr
79 dnl --with-nspr-cflags/libs
80 dnl --enable-nspr-build
81 dnl --enable-posix-nspr-emulation
83 AC_MSG_CHECKING([NSPR selection])
86 if test -n "$_USE_SYSTEM_NSPR"; then
87 nspr_opts="x$nspr_opts"
90 if test -n "$NSPR_CFLAGS" -o -n "$NSPR_LIBS"; then
91 nspr_opts="x$nspr_opts"
92 which_nspr="command-line"
94 if test -n "$MOZ_BUILD_NSPR"; then
95 nspr_opts="x$nspr_opts"
96 which_nspr="source-tree"
98 if test "$JS_POSIX_NSPR" = unset; then
101 nspr_opts="x$nspr_opts"
102 which_nspr="posix-wrapper"
105 if test -z "$nspr_opts"; then
106 if test -z "$BUILDING_JS"; then
107 dnl Toplevel configure defaults to using nsprpub from the source tree
109 which_nspr="source-tree"
111 dnl JS configure defaults to emulated NSPR if available, falling back
113 if test -n "$JS_THREADSAFE"; then
114 JS_POSIX_NSPR="$JS_POSIX_NSPR_DEFAULT"
115 if test -z "$JS_POSIX_NSPR"; then
117 which_nspr="source-tree"
119 which_nspr="posix-wrapper"
127 if test -z "$nspr_opts" || test "$nspr_opts" = x; then
128 AC_MSG_RESULT($which_nspr)
130 AC_MSG_ERROR([only one way of using NSPR may be selected. See 'configure --help'.])
133 AC_SUBST(MOZ_BUILD_NSPR)
135 if test -n "$BUILDING_JS"; then
136 if test "$JS_POSIX_NSPR" = 1; then
137 AC_DEFINE(JS_POSIX_NSPR)
139 AC_SUBST(JS_POSIX_NSPR)
142 # A (sub)configure invoked by the toplevel configure will always receive
143 # --with-nspr-libs on the command line. It will never need to figure out
145 if test -n "$_IS_OUTER_CONFIGURE"; then
147 if test -n "$_USE_SYSTEM_NSPR"; then
148 AM_PATH_NSPR($NSPR_MINVER, [MOZ_NATIVE_NSPR=1], [AC_MSG_ERROR([you do not have NSPR installed or your version is older than $NSPR_MINVER.])])
151 if test -n "$MOZ_NATIVE_NSPR" -o -n "$NSPR_CFLAGS" -o -n "$NSPR_LIBS"; then
153 CFLAGS="$CFLAGS $NSPR_CFLAGS"
154 AC_TRY_COMPILE([#include "prtypes.h"],
155 [#ifndef PR_STATIC_ASSERT
156 #error PR_STATIC_ASSERT not defined or requires including prtypes.h
159 AC_MSG_ERROR([system NSPR does not support PR_STATIC_ASSERT or including prtypes.h does not provide it]))
160 AC_TRY_COMPILE([#include "prtypes.h"],
162 #error PR_UINT64 not defined or requires including prtypes.h
165 AC_MSG_ERROR([system NSPR does not support PR_UINT64 or including prtypes.h does not provide it]))
167 elif test -z "$JS_POSIX_NSPR" -a -n "$JS_THREADSAFE"; then
168 if test -z "$LIBXUL_SDK"; then
169 NSPR_CFLAGS="-I${LIBXUL_DIST}/include/nspr"
170 if test -n "$GNU_CC"; then
171 NSPR_LIBS="-L${LIBXUL_DIST}/lib -lnspr${NSPR_VERSION} -lplc${NSPR_VERSION} -lplds${NSPR_VERSION}"
173 NSPR_LIBS="${LIBXUL_DIST}/lib/nspr${NSPR_VERSION}.lib ${LIBXUL_DIST}/lib/plc${NSPR_VERSION}.lib ${LIBXUL_DIST}/lib/plds${NSPR_VERSION}.lib "
176 NSPR_CFLAGS=`"${LIBXUL_DIST}"/sdk/bin/nspr-config --prefix="${LIBXUL_DIST}" --includedir="${LIBXUL_DIST}/include/nspr" --cflags`
177 NSPR_LIBS=`"${LIBXUL_DIST}"/sdk/bin/nspr-config --prefix="${LIBXUL_DIST}" --libdir="${LIBXUL_DIST}"/lib --libs`
181 AC_SUBST(NSPR_CFLAGS)
184 NSPR_PKGCONF_CHECK="nspr"
185 if test -n "$MOZ_NATIVE_NSPR"; then
186 # piggy back on $MOZ_NATIVE_NSPR to set a variable for the nspr check for js.pc
187 NSPR_PKGCONF_CHECK="nspr >= $NSPR_MINVER"
190 CFLAGS="$CFLAGS $NSPR_CFLAGS"
191 AC_TRY_COMPILE([#include "prlog.h"],
192 [#ifndef PR_STATIC_ASSERT
193 #error PR_STATIC_ASSERT not defined
196 AC_MSG_ERROR([system NSPR does not support PR_STATIC_ASSERT]))
199 AC_SUBST(NSPR_PKGCONF_CHECK)
201 fi # _IS_OUTER_CONFIGURE
205 AC_DEFUN([MOZ_SUBCONFIGURE_NSPR], [
207 if test -z "$MOZ_NATIVE_NSPR"; then
208 ac_configure_args="$_SUBDIR_CONFIG_ARGS --with-dist-prefix=$MOZ_BUILD_ROOT/dist --with-mozilla"
209 if test -z "$MOZ_DEBUG"; then
210 ac_configure_args="$ac_configure_args --disable-debug"
212 ac_configure_args="$ac_configure_args --enable-debug"
214 if test "$MOZ_OPTIMIZE" = "1"; then
215 ac_configure_args="$ac_configure_args --enable-optimize"
216 elif test -z "$MOZ_OPTIMIZE"; then
217 ac_configure_args="$ac_configure_args --disable-optimize"
219 if test -n "$HAVE_64BIT_OS"; then
220 ac_configure_args="$ac_configure_args --enable-64bit"
222 if test -n "$USE_ARM_KUSER"; then
223 ac_configure_args="$ac_configure_args --with-arm-kuser"
225 # A configure script generated by autoconf 2.68 does not allow the cached
226 # values of "precious" variables such as CFLAGS and LDFLAGS to differ from
227 # the values passed to the configure script. Since we modify CFLAGS and
228 # LDFLAGS before passing them to NSPR's configure script, we cannot share
229 # config.cache with NSPR. As a result, we cannot pass AS, CC, CXX, etc. to
230 # NSPR via a shared config.cache file and must pass them to NSPR on the
231 # configure command line.
232 for var in AS CC CXX CPP LD AR RANLIB STRIP; do
233 ac_configure_args="$ac_configure_args $var='`eval echo \\${${var}}`'"
235 # A configure script generated by autoconf 2.68 warns if --host is
236 # specified but --build isn't. So we always pass --build to NSPR's
238 ac_configure_args="$ac_configure_args --build=$build"
239 ac_configure_args="$ac_configure_args $NSPR_CONFIGURE_ARGS"
241 # Save these, so we can mess with them for the subconfigure ..
242 _SAVE_CFLAGS="$CFLAGS"
243 _SAVE_CPPFLAGS="$CPPFLAGS"
244 _SAVE_LDFLAGS="$LDFLAGS"
246 if test -n "$MOZ_LINKER" -a "$ac_cv_func_dladdr" = no ; then
247 # dladdr is supported by the new linker, even when the system linker doesn't
248 # support it. Trick nspr into using dladdr when it's not supported.
249 export CPPFLAGS="-include $_topsrcdir/mozglue/linker/dladdr.h $CPPFLAGS"
251 export LDFLAGS="$LDFLAGS $NSPR_LDFLAGS"
252 export CFLAGS="$CFLAGS $MOZ_FRAMEPTR_FLAGS"
254 # Use a separate cache file for NSPR since it uses autoconf 2.68.
255 _save_cache_file="$cache_file"
256 cache_file=$_objdir/nsprpub/config.cache
258 AC_OUTPUT_SUBDIRS(nsprpub)
260 # .. and restore them
261 cache_file="$_save_cache_file"
262 CFLAGS="$_SAVE_CFLAGS"
263 CPPFLAGS="$_SAVE_CPPFLAGS"
264 LDFLAGS="$_SAVE_LDFLAGS"
266 ac_configure_args="$_SUBDIR_CONFIG_ARGS"