Add nacl compilation

This commit is contained in:
Victor Shcherb 2012-06-04 21:18:50 +02:00
parent 48a2ce0f2d
commit 01387328a3
11 changed files with 471 additions and 37 deletions

View file

@ -70,8 +70,10 @@ build-%/$(TARGET)-$(ARCH)/$(LIBNAME).$(STATICLIB_EXT): $$(addprefix build-%/,$(O
@mkdir -p `dirname $@`
$(AR) rs $@ $?
# This target assembles dynamic library
.SECONDEXPANSION:
# This target assembles dynamic library
.SECONDEXPANSION:
build-%/$(TARGET)-$(ARCH)/$(LIBNAME).$(DYNAMICLIB_EXT): $$(addprefix build-%/,$(OBJECTS))
@mkdir -p `dirname $@`
$(CXX) -o $@ $? $(LDFLAGS) -L$(PREBUILT_DIR_PREFIX)-$* $(LDLIBS)
$(CXX) -o $@ $(addprefix build-$*/,$(OBJECTS)) $(LDFLAGS) -L$(PREBUILT_DIR_PREFIX)-$* $(LDLIBS)

View file

@ -96,6 +96,10 @@ win_CXX := i586-mingw32msvc-gcc
win_CC := i586-mingw32msvc-gcc
win_STRIP := i586-mingw32msvc-strip
win_CPP_FLAGS := -D_Windows
win_STATICLIB_EXT := a
win_DYNAMICLIB_EXT := dll
win_LIBRARY_PREFIX := lib
win_LDFLAGS := -shared -Wl,-Bsymbolic
#win_CFLAGS := -D_JNI_IMPLEMENTATION_ -Ilib/inc_win -I$(JAVA_HOME)/include -O
#win_LINKFLAGS := -Wl,--kill-at -shared
############################################################################################################################

View file

@ -13,15 +13,15 @@ OSMAND_FLAGS = \
-DHASH_MAP_GNU
LIBNAME = $(LIBRARY_PREFIX)osmand
LIBTYPE = $(DYNAMICLIB_EXT)
LDLIBS += -lskia -lproto -lpthread -lft2 -lexpat -lpng
LDLIBS += -lskia -lproto -lpthread -lft2 -lexpat -lpng -lz
ifeq ($(TARGET),nacl)
LDLIBS += -L$(TC_PATH)/i686-nacl/usr/lib -lz
OSMAND_FLAGS += \
-DRT_NOT_SUPPORTED
LOCAL_SRC_FILES += \
src/osmand_nacl.c
src/osmand_nacl.cpp
else
LDLIBS += -lrt -lz
LDLIBS += -lrt
LOCAL_SRC_FILES += \
src/java_wrap.cpp
# Set library name

View file

@ -1,44 +1,50 @@
THIS_MAKE:=$(abspath $(lastword $(MAKEFILE_LIST)))
LIBNAME:=osmand
TARGET:=nacl
include ../Makefile.vars
LOCAL_PATH=.
include Common.mk
LOCAL_SRC_FILES += \
src/osmand_nacl.c
SRC_LIBRARY_x64 = ../lib/nacl-x64-release/libosmand.nexe
SRC_LIBRARY_x86 = ../lib/nacl-x86-release/libosmand.nexe
LDFLAGS:=-lppapi -expat -protobuf
LIBRARY_x64 = nacl/osmand-x64.nexe
LIBRARY_x86 = nacl/osmand-x86.nexe
# Default target is everything
all : build-release/$(LIBNAME)_$(TARGET)_32.nexe build-release/$(LIBNAME)_$(TARGET)_64.nexe build-release/$(LIBNAME).nmf
compile : all libraries
# Compilation
include ../Makefile.rules
build-release/$(LIBNAME)_$(TARGET)_32.nexe : $(addprefix build-release/obj-$(TARGET)-32/,$(OBJECTS_NAMES))
$(CXX) -o $@ $^ -m32 $(CXXFLAGS) $(LDFLAGS)
libraries : $(LIBRARY_x64) $(LIBRARY_x86)
all : x86 x64
x86:
make -f Makefile ARCH=x86 TARGET=nacl
build-release/$(LIBNAME)_x86_64.nexe : $(addprefix build-release/obj-$(TARGET)-64/,$(OBJECTS_NAMES))
$(CXX) -o $@ $^ -m64 $(CXXFLAGS) $(LDFLAGS)
x64:
make -f Makefile ARCH=x64 TARGET=nacl
$(LIBRARY_x86) : $(SRC_LIBRARY_x86)
cp $(SRC_LIBRARY_x86) $(LIBRARY_x86)
$(LIBRARY_x64) : $(SRC_LIBRARY_x64)
cp $(SRC_LIBRARY_x64) $(LIBRARY_x64)
# NMF Manifiest generation
#NMF_FILE = $(LIBNAME).nmf
## NMF Manifiest generation
##
## Use the python script create_nmf to scan the binaries for dependencies using
## objdump. Pass in the (-L) paths to the default library toolchains so that we
## can find those libraries and have it automatically copy the files (-s) to
## the target directory for us.
#NMF:=python $(NACL_SDK_ROOT)/tools/create_nmf.py
#NMF_ARGS:=-D $(TC_PATH)/x86_64-nacl/bin/objdump
#NMF_PATHS:=-L $(TC_PATH)/x86_64-nacl/lib32 -L $(TC_PATH)/x86_64-nacl/lib
#
# Use the python script create_nmf to scan the binaries for dependencies using
# objdump. Pass in the (-L) paths to the default library toolchains so that we
# can find those libraries and have it automatically copy the files (-s) to
# the target directory for us.
NMF:=python $(NACL_SDK_ROOT)/tools/create_nmf.py
NMF_ARGS:=-D $(TC_PATH)/x86_64-nacl/bin/objdump
NMF_PATHS:=-L $(TC_PATH)/x86_64-nacl/lib32 -L $(TC_PATH)/x86_64-nacl/lib
build-release/$(PROJECT).nmf : build-release/$(PROJECT)_x86_64.nexe build-release/$(PROJECT)_x86_32.nexe
echo $(NMF) $(NMF_ARGS) -s . -o $@ $(NMF_PATHS) $^
$(NMF) $(NMF_ARGS) -s . -o $@ $(NMF_PATHS) $^
#$(NMF_FILE) : $(LIBRARY_x64) $(LIBRARY_x86)
# $(NMF) $(NMF_ARGS) -s . -o $@ $(NMF_PATHS) $^
# Define a phony rule so it always runs, to build nexe and start up server.
.PHONY: RUN
RUN: all
.PHONY: run
run : all libraries
python httpd.py 5100 &
stop :
wget -q -O - 'http://localhost:5100?quit=1' > /dev/null

1
Osmand-kernel/osmand/nacl/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.nexe

View file

@ -0,0 +1,178 @@
/*
* Copyright (c) 2012 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/**
* @fileoverview This file provides a BrowserChecker Javascript class.
* Users can create a BrowserChecker object, invoke checkBrowser(|version|),
* and then use getIsValidBrowser() and getBrowserSupportStatus()
* to determine if the browser version is greater than |version|
* and if the Native Client plugin is found.
*/
// Create a namespace object
var browser_version = browser_version || {};
/**
* Class to provide checking for version and NativeClient.
* @param {integer} arg1 An argument that indicates major version of Chrome we
* require, such as 14.
*/
/**
* Constructor for the BrowserChecker. Sets the major version of
* Chrome that is required to |minChromeVersion|.
* @param minChromeVersion The earliest major version of chrome that
* is supported. If the Chrome browser version is less than
* |minChromeVersion| then |isValidBrowswer| will be set to false.
* @param opt_maxChromeVersion Ignored. Retained for backwards compatibility.
* @param appVersion The application version string.
* @param plugins The plugins that exist in the browser.
* @constructor
*/
browser_version.BrowserChecker = function(minChromeVersion,
appVersion, plugins,
opt_maxChromeVersion) {
/**
* Version specified by the user. This class looks to see if the browser
* version is >= |minChromeVersion_|.
* @type {integer}
* @private
*/
this.minChromeVersion_ = minChromeVersion;
/**
* List of Browser plugin objects.
* @type {Ojbect array}
* @private
*/
this.plugins_ = plugins;
/**
* Application version string from the Browser.
* @type {integer}
* @private
*/
this.appVersion_ = appVersion;
/**
* Flag used to indicate if the browser has Native Client and is if the
* browser version is recent enough.
* @type {boolean}
* @private
*/
this.isValidBrowser_ = false;
/**
* Actual major version of Chrome -- found by querying the browser.
* @type {integer}
* @private
*/
this.chromeVersion_ = null;
/**
* Browser support status. This allows the user to get a detailed status
* rather than using this.browserSupportMessage.
*/
this.browserSupportStatus_ =
browser_version.BrowserChecker.StatusValues.UNKNOWN;
}
/**
* The values used for BrowserChecker status to indicate success or
* a specific error.
* @enum {id}
*/
browser_version.BrowserChecker.StatusValues = {
UNKNOWN: 0,
NACL_ENABLED: 1,
UNKNOWN_BROWSER: 2,
CHROME_VERSION_TOO_OLD: 3,
NACL_NOT_ENABLED: 4,
NOT_USING_SERVER: 5
};
/**
* Determines if the plugin with name |name| exists in the browser.
* @param {string} name The name of the plugin.
* @param {Object array} plugins The plugins in this browser.
* @return {bool} |true| if the plugin is found.
*/
browser_version.BrowserChecker.prototype.pluginExists = function(name,
plugins) {
for (var index=0; index < plugins.length; index++) {
var plugin = this.plugins_[index];
var plugin_name = plugin['name'];
// If the plugin is not found, you can use the Javascript console
// to see the names of the plugins that were found when debugging.
if (plugin_name.indexOf(name) != -1) {
return true;
}
}
return false;
}
/**
* Returns browserSupportStatus_ which indicates if the browser supports
* Native Client. Values are defined as literals in
* browser_version.BrowserChecker.StatusValues.
* @ return {int} Level of NaCl support.
*/
browser_version.BrowserChecker.prototype.getBrowserSupportStatus = function() {
return this.browserSupportStatus_;
}
/**
* Returns isValidBrowser (true/false) to indicate if the browser supports
* Native Client.
* @ return {bool} If this browser has NativeClient and correct version.
*/
browser_version.BrowserChecker.prototype.getIsValidBrowser = function() {
return this.isValidBrowser_;
}
/**
* Checks to see if this browser can support Native Client applications.
* For Chrome browsers, checks to see if the "Native Client" plugin is
* enabled.
*/
browser_version.BrowserChecker.prototype.checkBrowser = function() {
var versionPatt = /Chrome\/(\d+)\.(\d+)\.(\d+)\.(\d+)/;
var result = this.appVersion_.match(versionPatt);
// |result| stores the Chrome version number.
if (!result) {
this.isValidBrowser_ = false;
this.browserSupportStatus_ =
browser_version.BrowserChecker.StatusValues.UNKNOWN_BROWSER;
} else {
this.chromeVersion_ = result[1];
// We know we have Chrome, check version and/or plugin named Native Client
if (this.chromeVersion_ >= this.minChromeVersion_) {
var found_nacl = this.pluginExists('Native Client', this.plugins_);
if (found_nacl) {
this.isValidBrowser_ = true;
this.browserSupportStatus_ =
browser_version.BrowserChecker.StatusValues.NACL_ENABLED;
} else {
this.isValidBrowser_ = false;
this.browserSupportStatus_ =
browser_version.BrowserChecker.StatusValues.NACL_NOT_ENABLED;
}
} else {
// We are in a version that is less than |minChromeVersion_|
this.isValidBrowser_ = false;
this.browserSupportStatus_ =
browser_version.BrowserChecker.StatusValues.CHROME_VERSION_TOO_OLD;
}
}
var my_protocol = window.location.protocol;
if (my_protocol.indexOf('file') == 0) {
this.isValidBrowser_ = false;
this.browserSupportStatus_ =
browser_version.BrowserChecker.StatusValues.NOT_USING_SERVER;
}
}

View file

@ -0,0 +1,232 @@
<!DOCTYPE html>
<html>
<!--
Copyright (c) 2011 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head>
<title>Load Progress Example</title>
<script type="text/javascript" src="check_browser.js"></script>
<script type="text/javascript">
// Check for Native Client support in the browser before the DOM loads.
var isValidBrowser = false;
var browserSupportStatus = 0;
var checker = new browser_version.BrowserChecker(
14, // Minumum Chrome version.
navigator["appVersion"],
navigator["plugins"]);
checker.checkBrowser();
loadProgressModule = null; // Global application object.
statusText = 'NO-STATUS';
isValidBrowser = checker.getIsValidBrowser();
browserSupportStatus = checker.getBrowserSupportStatus();
// Handler that gets called when the NaCl module starts loading. This
// event is always triggered when an <EMBED> tag has a MIME type of
// application/x-nacl.
function moduleDidStartLoad() {
appendToEventLog('loadstart');
}
// Progress event handler. |event| contains a couple of interesting
// properties that are used in this example:
// total The size of the NaCl module in bytes. Note that this value
// is 0 until |lengthComputable| is true. In particular, this
// value is 0 for the first 'progress' event.
// loaded The number of bytes loaded so far.
// lengthComputable A boolean indicating that the |total| field
// represents a valid length.
//
// event The ProgressEvent that triggered this handler.
function moduleLoadProgress(event) {
var loadPercent = 0.0;
var loadPercentString;
if (event.lengthComputable && event.total > 0) {
loadPercent = event.loaded / event.total * 100.0;
loadPercentString = loadPercent + '%';
} else {
// The total length is not yet known.
loadPercent = -1.0;
loadPercentString = 'Computing...';
}
appendToEventLog('progress: ' + loadPercentString +
' (' + event.loaded + ' of ' + event.total + ' bytes)');
}
// Handler that gets called if an error occurred while loading the NaCl
// module. Note that the event does not carry any meaningful data about
// the error, you have to check lastError on the <EMBED> element to find
// out what happened.
function moduleLoadError() {
appendToEventLog('error: ' + loadProgressModule.lastError);
}
// Handler that gets called if the NaCl module load is aborted.
function moduleLoadAbort() {
appendToEventLog('abort');
}
// When the NaCl module has loaded indicate success.
function moduleDidLoad() {
loadProgressModule = document.getElementById('load_progress');
appendToEventLog('load');
updateStatus('SUCCESS');
}
// Handler that gets called when the NaCl module loading has completed.
// You will always get one of these events, regardless of whether the NaCl
// module loaded successfully or not. For example, if there is an error
// during load, you will get an 'error' event and a 'loadend' event. Note
// that if the NaCl module loads successfully, you will get both a 'load'
// event and a 'loadend' event.
function moduleDidEndLoad() {
appendToEventLog('loadend');
var lastError = event.target.lastError;
if (lastError == undefined || lastError.length == 0) {
lastError = '&lt;none&gt;';
}
appendToEventLog('lastError: ' + lastError);
}
// Handle a message coming from the NaCl module.
function handleMessage(message_event) {
alert(message_event.data);
}
// Set the global status message. Updates the 'status_field' element with
// the new text.
// opt_message The message text. If this is null or undefined, then
// attempt to set the element with id 'status_field' to the value of
// |statusText|.
function updateStatus(opt_message) {
if (opt_message)
statusText = opt_message;
var statusField = document.getElementById('status_field');
if (statusField) {
statusField.innerHTML = statusText;
}
}
// Append an event name to the 'event_log_field' element. Event names
// are separated by a <br> tag so they get listed one per line.
// logMessage The message to append to the log.
function appendToEventLog(logMessage) {
var eventLogField = document.getElementById('event_log_field');
if (eventLogField.innerHTML.length == 0) {
eventLogField.innerHTML = logMessage;
} else {
eventLogField.innerHTML = eventLogField.innerHTML +
'<br />' +
logMessage;
}
}
</script>
</head>
<body>
<h1>Native Client Load Event Example</h1>
<h2>Event Log</h2>
<div id="event_log_field"></div>
<h2>Status</h2>
<div id="status_field">NO-STATUS</div>
<div id="listener">
<script type="text/javascript">
var listener = document.getElementById('listener');
listener.addEventListener('loadstart', moduleDidStartLoad, true);
listener.addEventListener('progress', moduleLoadProgress, true);
listener.addEventListener('error', moduleLoadError, true);
listener.addEventListener('abort', moduleLoadAbort, true);
listener.addEventListener('load', moduleDidLoad, true);
listener.addEventListener('loadend', moduleDidEndLoad, true);
listener.addEventListener('message', handleMessage, true);
switch (browserSupportStatus) {
case browser_version.BrowserChecker.StatusValues.NACL_ENABLED:
appendToEventLog('Native Client plugin enabled.');
break;
case browser_version.BrowserChecker.StatusValues.UNKNOWN_BROWSER:
updateStatus('UNKNOWN BROWSER');
break;
case browser_version.BrowserChecker.StatusValues.CHROME_VERSION_TOO_OLD:
appendToEventLog(
'Chrome too old: You must use Chrome version 14 or later.');
updateStatus('NEED CHROME 14 OR LATER');
break;
case browser_version.BrowserChecker.StatusValues.NACL_NOT_ENABLED:
appendToEventLog(
'NaCl disabled: Native Client is not enabled.<br>' +
'Please go to <b>chrome://plugins</b> and enable Native Client ' +
'plugin.');
updateStatus('NaCl NOT ENABLED');
break;
case browser_version.BrowserChecker.StatusValues.NOT_USING_SERVER:
appendToEventLog(
'file: URL detected, please use a web server to host Native ' +
'Client applications.');
updateStatus('NaCl NOT ENABLED');
default:
appendToEventLog('Unknown error: Unable to detect browser and/or ' +
'Native Client support.');
updateStatus('UNKNOWN ERROR');
break;
}
</script>
<!-- Load the published .nexe. This includes the 'src' attribute which
shows how to load multi-architecture modules. Each entry in the "nexes"
object in the .nmf manifest file is a key-value pair: the key is the runtime
('x86-32', 'x86-64', etc.); the value is a URL for the desired NaCl module.
To load the debug versions of your .nexes, set the 'src' attribute to the
_dbg.nmf version of the manifest file.
Note: The <EMBED> element is wrapped inside a <DIV>, which has both a 'load'
and a 'message' event listener attached. This wrapping method is used
instead of attaching the event listeners directly to the <EMBED> element to
ensure that the listeners are active before the NaCl module 'load' event
fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or
pp::Instance.PostMessage() (in C++) from within the initialization code in
your NaCl module.
-->
<embed name="nacl_module"
id="load_progress"
width=0 height=0
src="osmand.nmf"
type="application/x-nacl" />
<script type="text/javascript">
loadProgressModule = document.getElementById('load_progress');
// Futher diagnose NaCl loading.
if (loadProgressModule == null ||
typeof loadProgressModule.readyState == 'undefined') {
switch (browserSupportStatus) {
case browser_version.BrowserChecker.StatusValues.NACL_ENABLED:
// The NaCl plugin is enabled and running, it's likely that the flag
// isn't set.
appendToEventLog(
'NaCl flag disabled: The Native Client flag is not enabled.<br>' +
'Please go to <b>chrome://flags</b> enable Native Client and ' +
'relaunch your browser. See also: ' +
'<a href="http://code.google.com/chrome/nativeclient/docs/' +
'running.html">Running Web Applications that Use Native Client' +
'</a>');
updateStatus('NaCl NOT ENABLED');
break;
case browser_version.BrowserChecker.StatusValues.UNKNOWN_BROWSER:
appendToEventLog('Native Client applications are not supported by ' +
'this browser.');
break;
default:
appendToEventLog('Unknown error when loading Native Client ' +
'application.');
}
}
</script>
</div>
</body>
</html>

View file

@ -0,0 +1,11 @@
{
"program": {
"x86-64": {
"url": "osmand-x64.nexe"
},
"x86-32": {
"url": "osmand-x86.nexe"
}
}
}

View file

@ -68,7 +68,7 @@ static PP_Bool Instance_DidCreate(PP_Instance instance,
const char* argn[],
const char* argv[]) {
ppb_messaging_interface->PostMessage(instance,
CStrToVar("Hello a World (GLIBC)"));
CStrToVar("Osmand application"));
return PP_TRUE;
}

View file

@ -1,6 +1,7 @@
OSMAND_PNG_LOC := ./png_library
OSMAND_PNG_ABS := $(LOCAL_PATH)/png_library
OSMAND_ZLIB_ABS := $(LOCAL_PATH)/../zlib/zlib_library
LOCAL_SRC_FILES:= \
$(OSMAND_PNG_LOC)/png.c \
@ -22,7 +23,6 @@ LOCAL_SRC_FILES:= \
$(OSMAND_PNG_LOC)/pngwutil.c
LOCAL_C_INCLUDES += \
$(OSMAND_EXPAT_ABS) \
$(OSMAND_EXPAT_ABS)/lib
$(OSMAND_ZLIB_ABS)/