add mozglue support for gonk (bug 738559, r=glandium)
authorAndreas Gal <gal@mozilla.com>
Fri, 23 Mar 2012 00:40:14 -0700
changeset 93454 fd2c598e7fde575a0d7a29b1b9b6bca917ef0120
parent 93453 d2693e86769dfdfe5601b39161aab9b35353833f
child 93456 3e17d25beb07a96b97544bd4851006f38081cf99
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs738559
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
add mozglue support for gonk (bug 738559, r=glandium)
Makefile.in
configure.in
mozglue/Makefile.in
mozglue/build/Makefile.in
mozglue/gonk/GonkGlue.cpp
mozglue/gonk/Makefile.in
--- a/Makefile.in
+++ b/Makefile.in
@@ -67,16 +67,21 @@ tier_base_dirs = \
 
 ifndef LIBXUL_SDK
 ifeq (android,$(MOZ_WIDGET_TOOLKIT))
 tier_base_dirs += \
   other-licenses/android \
   other-licenses/skia-npapi \
   $(NULL)
 endif
+ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
+tier_base_dirs += \
+  other-licenses/android \
+  $(NULL)
+endif
 
 ifdef MOZ_MEMORY
 tier_base_dirs += memory/jemalloc
 endif
 tier_base_dirs += \
   mozglue \
   memory/mozalloc \
   $(NULL)
--- a/configure.in
+++ b/configure.in
@@ -7230,23 +7230,21 @@ AC_SUBST(MOZ_GLUE_PROGRAM_LDFLAGS)
 AC_SUBST(WIN32_CRT_LIBS)
 dnl Need to set this for make because NSS doesn't have configure
 AC_SUBST(DLLFLAGS)
 
 dnl We need to wrap dlopen and related functions on Android because we use
 dnl our own linker.
 if test "$OS_TARGET" = Android; then
     WRAP_LDFLAGS="${WRAP_LDFLAGS} -L$_objdir/dist/lib -lmozglue"
-    if test "$MOZ_WIDGET_TOOLKIT" = android; then
-        if test -n "$MOZ_OLD_LINKER"; then
-            WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=dlopen,--wrap=dlclose,--wrap=dlerror,--wrap=dlsym,--wrap=dladdr"
-        fi
-        WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=getaddrinfo,--wrap=freeaddrinfo,--wrap=gai_strerror"
-        WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=fork,--wrap=pthread_atfork"
-    fi
+    if test -n "$MOZ_OLD_LINKER"; then
+        WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=dlopen,--wrap=dlclose,--wrap=dlerror,--wrap=dlsym,--wrap=dladdr"
+    fi
+    WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=getaddrinfo,--wrap=freeaddrinfo,--wrap=gai_strerror"
+    WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=fork,--wrap=pthread_atfork"
 fi
 
 dnl ========================================================
 dnl = Use malloc wrapper lib
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(wrap-malloc,
 [  --enable-wrap-malloc    Wrap malloc calls (gnu linker only)],
     _WRAP_MALLOC=1,
--- a/mozglue/Makefile.in
+++ b/mozglue/Makefile.in
@@ -47,13 +47,17 @@ DIRS =
 ifdef MOZ_LINKER
 DIRS += linker
 endif
 
 ifeq (android,$(MOZ_WIDGET_TOOLKIT))
 DIRS += android
 endif
 
+ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
+DIRS += gonk
+endif
+
 DIRS += build
 
 TEST_DIRS = tests
 
 include $(topsrcdir)/config/rules.mk
--- a/mozglue/build/Makefile.in
+++ b/mozglue/build/Makefile.in
@@ -87,16 +87,23 @@ EXTRA_DSO_LDOPTS += $(ZLIB_LIBS)
 ifdef MOZ_MEMORY
 # To properly wrap jemalloc's pthread_atfork call.
 EXTRA_DSO_LDOPTS += -Wl,--wrap=pthread_atfork
 endif
 SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,android,$(DEPTH)/other-licenses/android)
 SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,android,../android)
 endif
 
+ifeq (gonk, $(MOZ_WIDGET_TOOLKIT))
+# To properly wrap jemalloc's pthread_atfork call.
+EXTRA_DSO_LDOPTS += -Wl,--wrap=pthread_atfork
+SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,android,$(DEPTH)/other-licenses/android)
+SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,gonk,../gonk)
+endif
+
 ifdef MOZ_LINKER
 # Add custom dynamic linker
 SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,linker,../linker)
 
 ifeq (arm, $(TARGET_CPU))
 EXTRA_DSO_LDOPTS += -Wl,-version-script,$(srcdir)/arm-eabi-filter
 endif
 
new file mode 100644
--- /dev/null
+++ b/mozglue/gonk/GonkGlue.cpp
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <unistd.h>
+#include <vector>
+
+#define NS_EXPORT __attribute__ ((visibility("default")))
+
+/* Android doesn't have pthread_atfork(), so we need to use our own. */
+struct AtForkFuncs {
+  void (*prepare)(void);
+  void (*parent)(void);
+  void (*child)(void);
+};
+static std::vector<AtForkFuncs> atfork;
+
+extern "C" NS_EXPORT int
+__wrap_pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))
+{
+  AtForkFuncs funcs;
+  funcs.prepare = prepare;
+  funcs.parent = parent;
+  funcs.child = child;
+  atfork.push_back(funcs);
+  return 0;
+}
+
+extern "C" NS_EXPORT pid_t
+__wrap_fork(void)
+{
+  pid_t pid;
+  for (std::vector<AtForkFuncs>::reverse_iterator it = atfork.rbegin();
+       it < atfork.rend(); ++it)
+    if (it->prepare)
+      it->prepare();
+
+  switch ((pid = fork())) {
+  case 0:
+    for (std::vector<AtForkFuncs>::iterator it = atfork.begin();
+         it < atfork.end(); ++it)
+      if (it->child)
+        it->child();
+    break;
+  default:
+    for (std::vector<AtForkFuncs>::iterator it = atfork.begin();
+         it < atfork.end(); ++it)
+      if (it->parent)
+        it->parent();
+  }
+  return pid;
+}
new file mode 100644
--- /dev/null
+++ b/mozglue/gonk/Makefile.in
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+DEPTH		= ../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(DEPTH)/config/autoconf.mk
+
+MODULE           = gonk
+LIBRARY_NAME     = gonk
+FORCE_STATIC_LIB = 1
+STL_FLAGS=
+
+DEFINES += \
+  -DANDROID_PACKAGE_NAME='"$(ANDROID_PACKAGE_NAME)"' \
+  $(NULL)
+
+CPPSRCS = \
+  GonkGlue.cpp \
+  $(NULL)
+
+LOCAL_INCLUDES += -I$(DEPTH)/build
+LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build
+
+include $(topsrcdir)/config/rules.mk