merge b2g-inbound to mozilla-central a=merge
[gecko.git] / build / autoconf / nspr-build.m4
blob631f69e8f03b655bf1bd7ad45b2d571b3417b788
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.],
28     NSPR_CFLAGS=$withval)
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.],
32     NSPR_LIBS=$withval)
34 ifdef([CONFIGURING_JS],[
35     MOZ_ARG_ENABLE_BOOL(nspr-build,
36 [  --enable-nspr-build     Configure and build NSPR from source tree],
37         MOZ_BUILD_NSPR=1,
38         MOZ_BUILD_NSPR=)
41 if test -z "$BUILDING_JS" || test -n "$JS_STANDALONE"; then
42   _IS_OUTER_CONFIGURE=1
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.)],
52     _USE_SYSTEM_NSPR=1 )
54 if test -z "$BUILDING_JS"; then
55     JS_THREADSAFE=1
58 JS_POSIX_NSPR=unset
59 ifdef([CONFIGURING_JS],[
60     if test -n "$JS_STANDALONE"; then
61       case "$target" in
62         *linux*|*darwin*|*dragonfly*|*freebsd*|*netbsd*|*openbsd*)
63           if test -z "$_HAS_NSPR" && test "$JS_THREADSAFE"; then
64             JS_POSIX_NSPR_DEFAULT=1
65           fi
66           ;;
67       esac
68     fi
70     MOZ_ARG_ENABLE_BOOL(posix-nspr-emulation,
71 [  --enable-posix-nspr-emulation
72                           Enable emulation of NSPR for POSIX systems],
73     JS_POSIX_NSPR=1,
74     JS_POSIX_NSPR=)
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])
84 nspr_opts=
85 which_nspr=default
86 if test -n "$_USE_SYSTEM_NSPR"; then
87     nspr_opts="x$nspr_opts"
88     which_nspr="system"
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
99     JS_POSIX_NSPR=
100 else
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
108       MOZ_BUILD_NSPR=1
109       which_nspr="source-tree"
110     else
111       dnl JS configure defaults to emulated NSPR if available, falling back
112       dnl to nsprpub.
113       if test -n "$JS_THREADSAFE"; then
114           JS_POSIX_NSPR="$JS_POSIX_NSPR_DEFAULT"
115           if test -z "$JS_POSIX_NSPR"; then
116              MOZ_BUILD_NSPR=1
117              which_nspr="source-tree"
118           else
119              which_nspr="posix-wrapper"
120           fi
121       else
122           which_nspr="none"
123       fi
124    fi
127 if test -z "$nspr_opts" || test "$nspr_opts" = x; then
128     AC_MSG_RESULT($which_nspr)
129 else
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)
138   fi
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
144 # anything itself.
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
152     _SAVE_CFLAGS=$CFLAGS
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
157                  #endif],
158                 ,
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"],
161                 [#ifndef PR_UINT64
162                  #error PR_UINT64 not defined or requires including prtypes.h
163                  #endif],
164                 ,
165                 AC_MSG_ERROR([system NSPR does not support PR_UINT64 or including prtypes.h does not provide it]))
166     CFLAGS=$_SAVE_CFLAGS
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}"
172         else
173             NSPR_LIBS="${LIBXUL_DIST}/lib/nspr${NSPR_VERSION}.lib ${LIBXUL_DIST}/lib/plc${NSPR_VERSION}.lib ${LIBXUL_DIST}/lib/plds${NSPR_VERSION}.lib "
174         fi
175     else
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`
178     fi
181 AC_SUBST(NSPR_CFLAGS)
182 AC_SUBST(NSPR_LIBS)
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"
189     _SAVE_CFLAGS=$CFLAGS
190     CFLAGS="$CFLAGS $NSPR_CFLAGS"
191     AC_TRY_COMPILE([#include "prlog.h"],
192                 [#ifndef PR_STATIC_ASSERT
193                  #error PR_STATIC_ASSERT not defined
194                  #endif],
195                 ,
196                 AC_MSG_ERROR([system NSPR does not support PR_STATIC_ASSERT]))
197     CFLAGS=$_SAVE_CFLAGS
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"
211     else
212         ac_configure_args="$ac_configure_args --enable-debug"
213     fi
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"
218     fi
219     if test -n "$HAVE_64BIT_OS"; then
220         ac_configure_args="$ac_configure_args --enable-64bit"
221     fi
222     if test -n "$USE_ARM_KUSER"; then
223         ac_configure_args="$ac_configure_args --with-arm-kuser"
224     fi
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}}`'"
234     done
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
237     # configure script.
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"
250     fi
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"