diff options
author | noelallen@google.com <noelallen@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-13 21:01:21 +0000 |
---|---|---|
committer | noelallen@google.com <noelallen@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-13 21:01:21 +0000 |
commit | a8a902d0e0655c4efd8c6d828b5fce1256f57954 (patch) | |
tree | bfd2c0d9f0c8a7a95fad91a8871c529ab2bb5917 /native_client_sdk/src | |
parent | eca944ad221dddb2d3e8d13233a7e5a2867d2168 (diff) | |
download | chromium_src-a8a902d0e0655c4efd8c6d828b5fce1256f57954.zip chromium_src-a8a902d0e0655c4efd8c6d828b5fce1256f57954.tar.gz chromium_src-a8a902d0e0655c4efd8c6d828b5fce1256f57954.tar.bz2 |
Add ability to build both glibc and newlib versions
These will replace the current method for copying projects over
and defining their makefiles. The makefiles will be removed
in a different CL to atomically switch between the two versions.
Fixes several minor issues.
Disables debugging, and dlopen
BUG=130618
R=binji@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10541134
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141968 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk/src')
14 files changed, 318 insertions, 504 deletions
diff --git a/native_client_sdk/src/build_tools/build_sdk.py b/native_client_sdk/src/build_tools/build_sdk.py index e28c3cf..67b5fc5 100755 --- a/native_client_sdk/src/build_tools/build_sdk.py +++ b/native_client_sdk/src/build_tools/build_sdk.py @@ -328,14 +328,15 @@ def BuildToolchains(pepperdir, platform, arch, pepper_ver, toolchains): EXAMPLE_MAP = { 'newlib': [ - 'debugging', +# 'debugging', 'file_histogram', - 'file_io', +# 'file_io', 'fullscreen_tumbler', 'gamepad', 'geturl', 'hello_world_interactive', 'hello_world_newlib', +# 'hello_world_gles', 'input_events', 'load_progress', 'mouselock', @@ -347,10 +348,10 @@ EXAMPLE_MAP = { 'websocket' ], 'glibc': [ - 'dlopen', +# 'dlopen', ], 'pnacl': [ - 'hello_world_pnacl', +# 'hello_world_pnacl', ], } diff --git a/native_client_sdk/src/build_tools/generate_make.py b/native_client_sdk/src/build_tools/generate_make.py index 322cb44..97f632c 100755 --- a/native_client_sdk/src/build_tools/generate_make.py +++ b/native_client_sdk/src/build_tools/generate_make.py @@ -19,11 +19,23 @@ PPAPI_DIR = os.path.join(SRC_DIR, 'ppapi') ARCHITECTURES = ['32', '64'] +SRC_EXT = { + 'c': 'CC', + 'cc' : 'CXX', + '.so' : '.so', + '.nexe': '.nexe' +} -def WriteMakefile(srcpath, dstpath, replacements): - text = open(srcpath, 'rb').read() + +def Replace(text, replacements): for key in replacements: text = text.replace(key, replacements[key]) + return text + + +def WriteMakefile(srcpath, dstpath, replacements): + text = open(srcpath, 'rb').read() + text = Replace(text, replacements) open(dstpath, 'wb').write(text) @@ -35,8 +47,8 @@ def GetExtType(desc): return ext -def GenPatsubst(arch, macro, ext, EXT): - return '$(patsubst %%.%s,%%_%s.o,$(%s_%s))' % (ext, arch, macro, EXT) +def GenPatsubst(arch, tool, macro, ext, EXT): + return '$(patsubst %%.%s,%s/%%_%s.o,$(%s_%s))' % (ext, tool, arch, macro, EXT) def SetVar(varname, values): @@ -70,7 +82,77 @@ def GenerateCopyList(desc): return sources +def BuildToolDict(tc, proj, arch='', ext='.nexe', OBJS='', TARG='', REMAP=''): + TC = tc.upper() + PROJ = proj.upper() + + if not OBJS: + OBJS = '%s_%s_%s_%s_O' % (TC, PROJ, arch, ext) + + if not TARG: + TARG = '%s_x86_%s%s' % (proj,arch,ext) + + replace = { + '<ARCH>': arch, + '<CC>': '%s_%s' % (TC, SRC_EXT[ext]), + '<DUMP>': '%s_DUMP' % TC, + '<ext>' : ext, + '<EXT>' : SRC_EXT[ext], + '<LINK>': '%s_LINK' % TC, + '<OBJS>' : OBJS, + '<proj>': proj, + '<PROJ>': PROJ, + '<REMAP>': REMAP, + '<TARG>': TARG, + '<TAB>': '\t', + '<tc>' : tc, + '<TC>' : TC + } + return replace + + +def GenerateNEXE(toolchain, name, ext, cc_sources, cxx_sources): + COMPILE_RULE = """ +<OBJS>:=$(patsubst %.<ext>, <tc>/%_<ARCH>.o,$(<PROJ>_<EXT>)) +$(<OBJS>) : <tc>/%_<ARCH>.o : %.<ext> $(THIS_MAKE) | <tc> +<TAB>$(<CC>) -o $@ $< -m<ARCH> $(<PROJ>_<EXT>FLAGS) -DTCNAME=\\"<tc>\\" +""" + LINK_RULE = """ +<tc>/<TARG> : $(<OBJS>) +<TAB>$(<LINK>) -o $@ $^ -m<ARCH> $(<PROJ>_LDFLAGS) +""" + rules = '' + targs = [] + for arch in ARCHITECTURES: + object_sets = [] + remap = '' + if cc_sources: + replace = BuildToolDict(toolchain, name, arch, 'c') + rules += Replace(COMPILE_RULE, replace) + object_sets.append(replace['<OBJS>']) + + if cxx_sources: + replace = BuildToolDict(toolchain, name, arch, 'cc') + rules += Replace(COMPILE_RULE, replace) + object_sets.append(replace['<OBJS>']) + + objs = ' '.join(object_sets) + replace = BuildToolDict(toolchain, name, arch, ext, OBJS=objs) + rules += Replace(LINK_RULE, replace) + if ext == '.so': + remap = ' -n %s,%s.so' % (replace['<TARG>'], name) + rules += '%s_NMF+=%s/%s\n' % (replace['<TC>'], toolchain, replace['<TARG>']) + if remap: + rules += '%s_REMAP+=%s\n' % (replace['<TC>'], remap) + return rules + + def GenerateReplacements(desc): + NMF_RULE = """ +<tc>/<proj>.nmf : $(<TC>_NMF) +<TAB>$(NMF) -D $(<DUMP>) -o $@ $(<TC>_PATHS) $^ -t <tc> -s <tc> $(<TC>_REMAP) + +""" # Generate target settings tools = desc['TOOLS'] @@ -106,38 +188,28 @@ def GenerateReplacements(desc): flags = target.get('LDFLAGS', ['$(NACL_LDFLAGS)']) settings += SetVar(macro + '_LDFLAGS', flags) - for arch in ARCHITECTURES: - object_sets = [] - if cc_sources: - objs = '%s_%s_CC_O' % (macro, arch) - rules += '%s:=%s\n' % (objs, GenPatsubst(arch, macro, 'c', 'CC')) - rules += '$(%s) : %%_%s.o : %%.c $(THIS_MAKEFILE)\n' % (objs, arch) - rules += '\t$(NACL_CC) -o $@ $< -m%s $(%s_CCFLAGS)\n\n' % (arch, macro) - object_sets.append('$(%s)' % objs) - if cxx_sources: - objs = '%s_%s_CXX_O' % (macro, arch) - rules += '%s:=%s\n' % (objs, GenPatsubst(arch, macro, 'cc', 'CXX')) - rules += '$(%s) : %%_%s.o : %%.cc $(THIS_MAKEFILE)\n' % (objs, arch) - rules += '\t$(NACL_CXX) -o $@ $< -m%s $(%s_CXXFLAGS)\n\n' % (arch, - macro) - object_sets.append('$(%s)' % objs) - target_name = '%s_x86_%s%s' % (name, arch, ext) - targets.append(target_name) - rules += '%s : %s\n' % (target_name, ' '.join(object_sets)) - rules += '\t$(NACL_LINK) -o $@ $^ -m%s $(%s_LDFLAGS)\n\n' % (arch, macro) - if target['TYPE'] == 'so': - remaps += ' -n %s,%s.so' % (target_name, name) - - nmf = desc['NAME'] + '.nmf' - nmfs = '%s : %s\n' % (nmf, ' '.join(targets)) - nmfs +='\t$(NMF) $(NMF_ARGS) -o $@ $(NMF_PATHS) $^%s\n' % remaps - - targets = 'all : '+ ' '.join(targets + [nmf]) + for tc in tools: + rules += '#\n# Rules for %s toolchain\n#\n%s:\n\t$(MKDIR) %s\n' % ( + tc, tc, tc) + for target in desc['TARGETS']: + name = target['NAME'] + ext = GetExtType(target) + sources = target['SOURCES'] + cc_sources = [fname for fname in sources if fname.endswith('.c')] + cxx_sources = [fname for fname in sources if fname.endswith('.cc')] + rules += GenerateNEXE(tc, name, ext, cc_sources, cxx_sources) + if target['TYPE'] == 'main': + nexe = name + targets.append('%s/%s.nmf' % (tc, name)) + replace = BuildToolDict(tc, nexe) + rules += Replace(NMF_RULE, replace) + + + targets = 'all : '+ ' '.join(targets) return { '__PROJECT_SETTINGS__' : settings, '__PROJECT_TARGETS__' : targets, '__PROJECT_RULES__' : rules, - '__PROJECT_NMFS__' : nmfs, '__PROJECT_PRELAUNCH__' : prelaunch, '__PROJECT_PRERUN__' : prerun, '__PROJECT_POSTLAUNCH__' : postlaunch diff --git a/native_client_sdk/src/build_tools/template.mk b/native_client_sdk/src/build_tools/template.mk index 77d2200..e178a15 100644 --- a/native_client_sdk/src/build_tools/template.mk +++ b/native_client_sdk/src/build_tools/template.mk @@ -8,6 +8,16 @@ # # +# Get pepper directory for toolchain and includes. +# +# If NACL_SDK_ROOT is not set, then assume it can be found a two directories up, +# from the default example directory location. +# +THIS_MAKEFILE:=$(abspath $(lastword $(MAKEFILE_LIST))) +NACL_SDK_ROOT?=$(abspath $(dir $(THIS_MAKEFILE))../..) +CHROME_PATH?=Undefined + +# # Defaults # NACL_WARNINGS:=-Wno-long-long -Wall -Wswitch-enum -Werror -pedantic @@ -15,7 +25,6 @@ NACL_CCFLAGS:=-O0 -g -pthread $(NACL_WARNINGS) NACL_CXXFLAGS:= -O0 -g -pthread -std=gnu++98 $(NACL_WARNINGS) NACL_LDFLAGS:=-Wl,-as-needed -g -pthread -lppapi_cpp -lppapi - # # Project Settings # @@ -28,17 +37,6 @@ __PROJECT_TARGETS__ # -# Get pepper directory for toolchain and includes. -# -# If NACL_SDK_ROOT is not set, then assume it can be found a two directories up, -# from the default example directory location. -# -THIS_MAKEFILE:=$(abspath $(lastword $(MAKEFILE_LIST))) -NACL_SDK_ROOT?=$(abspath $(dir $(THIS_MAKEFILE))../..) -CHROME_PATH?=Undefined - - -# # Alias for standard commands # CP:=python $(NACL_SDK_ROOT)/tools/oshelpers.py cp @@ -59,14 +57,7 @@ endif # Compute path to requested NaCl Toolchain # OSNAME:=$(shell python $(NACL_SDK_ROOT)/tools/getos.py) -TC_PATH:=$(abspath $(NACL_SDK_ROOT)/toolchain/$(OSNAME)_x86_$(TOOLCHAIN)) - - -# -# Compute path to requested NaCl Toolchain -# -OSNAME:=$(shell python $(NACL_SDK_ROOT)/tools/getos.py) -TC_PATH:=$(abspath $(NACL_SDK_ROOT)/toolchain/$(OSNAME)_x86_$(TOOLCHAIN)) +TC_PATH:=$(abspath $(NACL_SDK_ROOT)/toolchain) # @@ -92,9 +83,28 @@ export CYGWIN # # NaCl Tools # -NACL_CC?=$(TC_PATH)/bin/i686-nacl-gcc -c -NACL_CXX?=$(TC_PATH)/bin/i686-nacl-g++ -c -NACL_LINK?=$(TC_PATH)/bin/i686-nacl-g++ +NEWLIB_CC?=$(TC_PATH)/$(OSNAME)_x86_newlib/bin/i686-nacl-gcc -c +NEWLIB_CXX?=$(TC_PATH)/$(OSNAME)_x86_newlib/bin/i686-nacl-g++ -c +NEWLIB_LINK?=$(TC_PATH)/$(OSNAME)_x86_newlib/bin/i686-nacl-g++ +NEWLIB_DUMP?=$(TC_PATH)/$(OSNAME)_x86_newlib/x86_64-nacl/bin/objdump +NEWLIB_PATHS:= + +GLIBC_CC?=$(TC_PATH)/$(OSNAME)_x86_glibc/bin/i686-nacl-gcc -c +GLIBC_CXX?=$(TC_PATH)/$(OSNAME)_x86_glibc/bin/i686-nacl-g++ -c +GLIBC_LINK?=$(TC_PATH)/$(OSNAME)_x86_glibc/bin/i686-nacl-g++ +GLIBC_DUMP?=$(TC_PATH)/$(OSNAME)_x86_glibc/x86_64-nacl/bin/objdump +GLIBC_PATHS:=-L $(TC_PATH)/$(OSNAME)_x86_glibc/x86_64-nacl/lib32 +GLIBC_PATHS+=-L $(TC_PATH)/$(OSNAME)_x86_glibc/x86_64-nacl/lib + +# +# 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_PATHS:=-L $(TC_PATH)/x86_64-nacl/lib32 -L $(TC_PATH)/x86_64-nacl/lib # @@ -111,27 +121,12 @@ endif __PROJECT_RULES__ -# -# 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 -s . -NMF_PATHS:=-L $(TC_PATH)/x86_64-nacl/lib32 -L $(TC_PATH)/x86_64-nacl/lib - -__PROJECT_NMFS__ - __PROJECT_PRERUN__ RUN: all python ../httpd.py -__PROJECT_PRELAUNCH__ - LAUNCH_NEXE: CHECK_FOR_CHROME all - $(CHROME_PATH) $(NEXE_ARGS) "localhost:5103/$(PROJECT).html" - + $(CHROME_PATH) $(NEXE_ARGS) "localhost:5103/$(PROJECT).html?tool=$(TOOLCHAIN)" +__PROJECT_POSTLAUNCH__ diff --git a/native_client_sdk/src/examples/debugging/debugging.html b/native_client_sdk/src/examples/debugging/debugging.html index 72d8a02..65b66da 100644 --- a/native_client_sdk/src/examples/debugging/debugging.html +++ b/native_client_sdk/src/examples/debugging/debugging.html @@ -11,6 +11,8 @@ <title>Logging and Stack Trace</title> <script type="text/javascript"> statusText = 'NO-STATUS'; + + tick = ''; boomTime = null; crashed = false; diff --git a/native_client_sdk/src/examples/dlopen/dlopen.html b/native_client_sdk/src/examples/dlopen/dlopen.html index d964c0e..cd454bb 100644 --- a/native_client_sdk/src/examples/dlopen/dlopen.html +++ b/native_client_sdk/src/examples/dlopen/dlopen.html @@ -1,71 +1,125 @@ <!DOCTYPE html> <html> <!-- - Copyright (c) 2011 The Chromium Authors. All rights reserved. + 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. --> <head> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> <title>Magic Eightball</title> <script type="text/javascript"> + naclModule = null; // Global application object. + statusText = 'NO-STATUSES'; - function moduleDidLoad() { - } + function ExtractSearchParameter(name, def_value) { + var nameIndex = window.location.search.indexOf(name + "="); + if (nameIndex != -1) { + var value = location.search.substring(nameIndex + name.length + 1); + var endIndex = value.indexOf("&"); + if (endIndex != -1) + value = value.substring(0, endIndex); + return value; + } + return def_value; + } - function handleMessage(message_event) { - if(message_event.data=='Eightball loaded!') - { - document.getElementById('consolec').innerHTML = " \ -Eightball loaded, type a question below, press the button, and get a response. \ -<br /> \ -<form name='form' Value='Hello Me' onSubmit='return askBall()'> \ - <input type='textarea' size='64' name='inputtext' /> \ - <input type='button' NAME='button' Value='ASK!' onClick='askBall()' /> \ -</form>"; + function createNaClModule(name, tool, width, height) { + var listenerDiv = document.getElementById('listener'); + var naclModule = document.createElement('embed'); + naclModule.setAttribute('name', 'nacl_module'); + naclModule.setAttribute('id', 'nacl_module'); + naclModule.setAttribute('width', width); + naclModule.setAttribute('height',height); + naclModule.setAttribute('src', tool + '/' + name + '.nmf'); + naclModule.setAttribute('type', 'application/x-nacl'); + listenerDiv.appendChild(naclModule); } - else - { - if(message_event.data[0]=='!') - { + + // Indicate success when the NaCl module has loaded. + function moduleDidLoad() { + updateStatus('SUCCESS'); + naclModule = document.getElementById('nacl_module'); + } + + function handleMessage(message_event) { + var consolec = document.getElementById('consolec'); + if(message_event.data[0]=='!') { + document.getElementById('answerlog').innerHTML += + (consolec.value + ": " + message_event.data +"<br />"); + } else { document.getElementById('answerlog').innerHTML += - (document.form.inputtext.value + ": " + message_event.data +"<br />"); + (message_event.data +"<br />"); } - else - { - document.getElementById('consolec').innerHTML += - message_event.data + "<br />"; - console.log(message_event.data); + updateStatus(message_event.data); + } + + function pageDidUnload() { + clearInterval(paintInterval); + } + + // If the page loads before the Native Client module loads, then set the + // status message indicating that the module is still loading. Otherwise, + // do not change the status message. + function pageDidLoad() { + updateStatus('Page loaded.'); + if (naclModule == null) { + tool = ExtractSearchParameter('tool', 'glibc'); + updateStatus('Creating embed: ' + tool) + createNaClModule('dlopen', tool, 100, 100) + } else { + // It's possible that the Native Client module onload event fired + // before the page's onload event. In this case, the status message + // will reflect 'SUCCESS', but won't be displayed. This call will + // display the current message. + updateStatus('Waiting.'); } } - } - function pageDidUnload() { - clearInterval(paintInterval); - } + // Set the global status message. If the element with id 'statusField' + // exists, then set its HTML to the status message as well. + // opt_message The message test. If this is null or undefined, then + // attempt to set the element with id 'statusField' to the value of + // |statusText|. + function updateStatus(opt_message) { + if (opt_message) + statusText = opt_message; + var statusField = document.getElementById('statusField'); + var answerLog = document.getElementById('answerlog'); + if (statusField) { + statusField.innerHTML = statusText; + } + if (answerLog) { + answerLog.innerHTML += (message_event.data +"<br />"); + } + } - function askBall() - { - dlopen.postMessage('query'); - return false; - } + function askBall() + { + naclModule = document.getElementById('nacl_module'); + updateStatus('Posing...'); + naclModule.postMessage('query'); + return false; + } </script> </head> -<body id="bodyId" onunload="pageDidUnload()"> -<div id="listener"> - <script type="text/javascript"> - var listener = document.getElementById('listener') - listener.addEventListener('load', moduleDidLoad, true); - listener.addEventListener('message', handleMessage, true); - </script> -<h1>The Magic 8 Ball </h1> -<embed name="nacl_module" - id="dlopen" - width=1 height=1 - src="dlopen.nmf" - type="application/x-nacl" /> -</div> +<body id="bodyId" onload="pageDidLoad()"> + <h2>Status: <code id="statusField">NO-STATUS</code></h2> + <div id="listener"> + <script type="text/javascript"> + var listener = document.getElementById('listener') + listener.addEventListener('load', moduleDidLoad, true); + listener.addEventListener('message', handleMessage, true); + </script> + <h1>The Magic 8 Ball </h1> + </div> <br /> - <div id="consolec">..loading dynamic libraries...</div> + <div>Eightball loaded, type a question below, press the button, and get a response.</div> + <input type="text" id="consolec" value=""/> + <input type="button" id="button" value="ASK!" onclick="return askBall()"/> + </form> +<br /> <div id="answerlog"></div> </body> </html> diff --git a/native_client_sdk/src/examples/file_io/example.dsc b/native_client_sdk/src/examples/file_io/example.dsc index cb1b465..965932b 100644 --- a/native_client_sdk/src/examples/file_io/example.dsc +++ b/native_client_sdk/src/examples/file_io/example.dsc @@ -1,5 +1,5 @@ { - 'TOOLS': ['newlib', 'glibc'], + 'TOOLS': ['newlib'], 'TARGETS': [ { 'NAME' : 'file_io', diff --git a/native_client_sdk/src/examples/file_io/file_io.cc b/native_client_sdk/src/examples/file_io/file_io.cc index 4df8209..f046356 100644 --- a/native_client_sdk/src/examples/file_io/file_io.cc +++ b/native_client_sdk/src/examples/file_io/file_io.cc @@ -5,6 +5,8 @@ /// @file file_io.cc /// This example demonstrates the use of persistent file I/O +#include <limits.h> +#include <stddef.h> #include <stdio.h> #include <sstream> diff --git a/native_client_sdk/src/examples/file_io/file_io.html b/native_client_sdk/src/examples/file_io/file_io.html index 009c2e8..8ce0934 100644 --- a/native_client_sdk/src/examples/file_io/file_io.html +++ b/native_client_sdk/src/examples/file_io/file_io.html @@ -1,5 +1,4 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<!DOCTYPE html> <html> <!-- Copyright (c) 2012 The Chromium Authors. All rights reserved. @@ -7,45 +6,57 @@ found in the LICENSE file. --> <head> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> <title>File I/O Example</title> - <script type="text/javascript"> - FileIoModule = null; // Global application object. - statusText = 'NO-STATUS'; - - // Request file system space and indicate successful load - function moduleDidLoad() { - FileIoModule = document.getElementById('file_io'); + naclModule = null; // Global application object. + statusText = 'NO-STATUSES'; + + function ExtractSearchParameter(name, def_value) { + var nameIndex = window.location.search.indexOf(name + "="); + if (nameIndex != -1) { + var value = location.search.substring(nameIndex + name.length + 1); + var endIndex = value.indexOf("&"); + if (endIndex != -1) + value = value.substring(0, endIndex); + return value; + } + return def_value; } - function createNaClModule() { - // Dynamically generate this HTML: - // <embed name="nacl_module" - // id="file_io" - // width=0 height=0 - // src="file_io.nmf" - // type="application/x-nacl" /> + function createNaClModule(name, tool, width, height) { var listenerDiv = document.getElementById('listener'); var naclModule = document.createElement('embed'); naclModule.setAttribute('name', 'nacl_module'); naclModule.setAttribute('id', 'file_io'); - naclModule.setAttribute('width', 0); - naclModule.setAttribute('height', 0); - naclModule.setAttribute('src', 'file_io.nmf'); + naclModule.setAttribute('width', width); + naclModule.setAttribute('height',height); + naclModule.setAttribute('src', tool + '/' + name + '.nmf'); naclModule.setAttribute('type', 'application/x-nacl'); listenerDiv.appendChild(naclModule); } + // Indicate success when the NaCl module has loaded. + function moduleDidLoad() { + naclModule = document.getElementById('nacl_module'); + updateStatus('SUCCESS'); + } + // If the page loads before the Native Client module loads, then set the // status message indicating that the module is still loading. Otherwise, // do not change the status message. function pageDidLoad() { + updateStatus('Page loaded.'); + // Request file system space updateStatus('Allocating storage...'); window.webkitStorageInfo.requestQuota(window.PERSISTENT, 1024*1024, function(bytes) { updateStatus('Allocated '+bytes+' bytes of persistant storage.'); - createNaClModule(); + tool = ExtractSearchParameter('tool', 'newlib'); + updateStatus('Creating embed: ' + tool); + createNaClModule('hello_world', tool, 200, 200); }, function(e) { alert('Failed to allocate space') }); } diff --git a/native_client_sdk/src/examples/hello_world_glibc/Makefile b/native_client_sdk/src/examples/hello_world_glibc/Makefile deleted file mode 100644 index a7938d8..0000000 --- a/native_client_sdk/src/examples/hello_world_glibc/Makefile +++ /dev/null @@ -1,77 +0,0 @@ -# Copyright (c) 2012 The Native Client Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# -# GNU Make based build file. For details on GNU Make see: -# http://www.gnu.org/software/make/manual/make.html -# - - -# -# Get pepper directory for toolchain and includes. -# -# If NACL_SDK_ROOT is not set, then assume it can be found a two directories up, -# from the default example directory location. -# -THIS_MAKEFILE:=$(abspath $(lastword $(MAKEFILE_LIST))) -NACL_SDK_ROOT?=$(abspath $(dir $(THIS_MAKEFILE))../..) - - -# -# Project Build flags -# -# Turns on warnings (-Wxxx), builds with zero optimization (-O0) and adds debug -# information (-g) for correctness and ease of debugging. -WARNINGS:=-Wno-long-long -Wall -CFLAGS:=-pthread -O0 -g $(WARNINGS) - - -# -# Compute path to compiler -# -OSNAME:=$(shell python $(NACL_SDK_ROOT)/tools/getos.py) -TC_PATH:=$(abspath $(NACL_SDK_ROOT)/toolchain/$(OSNAME)_x86_glibc) - - -# Alias for C++ compiler -CC:=$(TC_PATH)/bin/i686-nacl-gcc - - -# -# Disable DOS PATH warning when using Cygwin based tools Windows -# -CYGWIN ?= nodosfilewarning -export CYGWIN - - -# Default target is everything -all : hello_world_x86_32.nexe hello_world_x86_64.nexe hello_world.nmf - -# Define compile and link rule for 32 bit (-m32) nexe -hello_world_x86_32.nexe : hello_world.c $(THIS_MAKE) - $(CC) -o $@ $< -m32 -O0 -g $(CFLAGS) -lppapi - -# Define compile and link rule for 64 bit (-m64) nexe -hello_world_x86_64.nexe : hello_world.c $(THIS_MAKE) - $(CC) -o $@ $< -m64 -O0 -g $(CFLAGS) -lppapi - -# -# 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 - -hello_world.nmf : hello_world_x86_64.nexe hello_world_x86_32.nexe - echo $(NMF) $(NMF_ARGS) -s . -o $@ $(NMF_PATHS) $^ - $(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 - python ../httpd.py diff --git a/native_client_sdk/src/examples/hello_world_glibc/hello_world.c b/native_client_sdk/src/examples/hello_world_glibc/hello_world.c deleted file mode 100644 index ab13e83..0000000 --- a/native_client_sdk/src/examples/hello_world_glibc/hello_world.c +++ /dev/null @@ -1,182 +0,0 @@ -/* 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. - */ - -/** @file hello_world.c - * This example demonstrates loading, running and scripting a very simple - * NaCl module. - */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "ppapi/c/pp_errors.h" -#include "ppapi/c/pp_module.h" -#include "ppapi/c/pp_var.h" -#include "ppapi/c/ppb.h" -#include "ppapi/c/ppb_instance.h" -#include "ppapi/c/ppb_messaging.h" -#include "ppapi/c/ppb_var.h" -#include "ppapi/c/ppp.h" -#include "ppapi/c/ppp_instance.h" -#include "ppapi/c/ppp_messaging.h" - -static PPB_Messaging* ppb_messaging_interface = NULL; -static PPB_Var* ppb_var_interface = NULL; - - -/** - * Creates new string PP_Var from C string. The resulting object will be a - * refcounted string object. It will be AddRef()ed for the caller. When the - * caller is done with it, it should be Release()d. - * @param[in] str C string to be converted to PP_Var - * @return PP_Var containing string. - */ -static struct PP_Var CStrToVar(const char* str) { - if (ppb_var_interface != NULL) { - return ppb_var_interface->VarFromUtf8(str, strlen(str)); - } - return PP_MakeUndefined(); -} - - -/** - * Called when the NaCl module is instantiated on the web page. The identifier - * of the new instance will be passed in as the first argument (this value is - * generated by the browser and is an opaque handle). This is called for each - * instantiation of the NaCl module, which is each time the <embed> tag for - * this module is encountered. - * - * If this function reports a failure (by returning @a PP_FALSE), the NaCl - * module will be deleted and DidDestroy will be called. - * @param[in] instance The identifier of the new instance representing this - * NaCl module. - * @param[in] argc The number of arguments contained in @a argn and @a argv. - * @param[in] argn An array of argument names. These argument names are - * supplied in the <embed> tag, for example: - * <embed id="nacl_module" dimensions="2"> - * will produce two arguments, one named "id" and one named "dimensions". - * @param[in] argv An array of argument values. These are the values of the - * arguments listed in the <embed> tag. In the above example, there will - * be two elements in this array, "nacl_module" and "2". The indices of - * these values match the indices of the corresponding names in @a argn. - * @return @a PP_TRUE on success. - */ -static PP_Bool Instance_DidCreate(PP_Instance instance, - uint32_t argc, - const char* argn[], - const char* argv[]) { - ppb_messaging_interface->PostMessage(instance, - CStrToVar("Hello a World (GLIBC)")); - return PP_TRUE; -} - - -/** - * Called when the NaCl module is destroyed. This will always be called, - * even if DidCreate returned failure. This routine should deallocate any data - * associated with the instance. - * @param[in] instance The identifier of the instance representing this NaCl - * module. - */ -static void Instance_DidDestroy(PP_Instance instance) { -} - -/** - * Called when the position, the size, or the clip rect of the element in the - * browser that corresponds to this NaCl module has changed. - * @param[in] instance The identifier of the instance representing this NaCl - * module. - * @param[in] position The location on the page of this NaCl module. This is - * relative to the top left corner of the viewport, which changes as the - * page is scrolled. - * @param[in] clip The visible region of the NaCl module. This is relative to - * the top left of the plugin's coordinate system (not the page). If the - * plugin is invisible, @a clip will be (0, 0, 0, 0). - */ -static void Instance_DidChangeView(PP_Instance instance, - PP_Resource view_resource) { -} - -/** - * Notification that the given NaCl module has gained or lost focus. - * Having focus means that keyboard events will be sent to the NaCl module - * represented by @a instance. A NaCl module's default condition is that it - * will not have focus. - * - * Note: clicks on NaCl modules will give focus only if you handle the - * click event. You signal if you handled it by returning @a true from - * HandleInputEvent. Otherwise the browser will bubble the event and give - * focus to the element on the page that actually did end up consuming it. - * If you're not getting focus, check to make sure you're returning true from - * the mouse click in HandleInputEvent. - * @param[in] instance The identifier of the instance representing this NaCl - * module. - * @param[in] has_focus Indicates whether this NaCl module gained or lost - * event focus. - */ -static void Instance_DidChangeFocus(PP_Instance instance, - PP_Bool has_focus) { -} - -/** - * Handler that gets called after a full-frame module is instantiated based on - * registered MIME types. This function is not called on NaCl modules. This - * function is essentially a place-holder for the required function pointer in - * the PPP_Instance structure. - * @param[in] instance The identifier of the instance representing this NaCl - * module. - * @param[in] url_loader A PP_Resource an open PPB_URLLoader instance. - * @return PP_FALSE. - */ -static PP_Bool Instance_HandleDocumentLoad(PP_Instance instance, - PP_Resource url_loader) { - /* NaCl modules do not need to handle the document load function. */ - return PP_FALSE; -} - - - -/** - * Entry points for the module. - * Initialize needed interfaces: PPB_Core, PPB_Messaging and PPB_Var. - * @param[in] a_module_id module ID - * @param[in] get_browser pointer to PPB_GetInterface - * @return PP_OK on success, any other value on failure. - */ -PP_EXPORT int32_t PPP_InitializeModule(PP_Module a_module_id, - PPB_GetInterface get_browser) { - ppb_messaging_interface = - (PPB_Messaging*)(get_browser(PPB_MESSAGING_INTERFACE)); - ppb_var_interface = (PPB_Var*)(get_browser(PPB_VAR_INTERFACE)); - return PP_OK; -} - - -/** - * Returns an interface pointer for the interface of the given name, or NULL - * if the interface is not supported. - * @param[in] interface_name name of the interface - * @return pointer to the interface - */ -PP_EXPORT const void* PPP_GetInterface(const char* interface_name) { - if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0) { - static PPP_Instance instance_interface = { - &Instance_DidCreate, - &Instance_DidDestroy, - &Instance_DidChangeView, - &Instance_DidChangeFocus, - &Instance_HandleDocumentLoad, - }; - return &instance_interface; - } - return NULL; -} - - -/** - * Called before the plugin module is unloaded. - */ -PP_EXPORT void PPP_ShutdownModule() { -} diff --git a/native_client_sdk/src/examples/hello_world_glibc/hello_world.html b/native_client_sdk/src/examples/hello_world_glibc/hello_world.html deleted file mode 100644 index 60f3722..0000000 --- a/native_client_sdk/src/examples/hello_world_glibc/hello_world.html +++ /dev/null @@ -1,87 +0,0 @@ -<!DOCTYPE html> -<html> - <!-- - 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. - --> -<head> - <title>Hello, World!</title> - <script type="text/javascript"> - helloWorldModule = null; // Global application object. - statusText = 'NO-STATUS'; - - // Indicate success when the NaCl module has loaded. - function moduleDidLoad() { - helloWorldModule = document.getElementById('hello_world'); - updateStatus('SUCCESS'); - } - - // Handle a message coming from the NaCl module. - function handleMessage(message_event) { - alert(message_event.data); - } - - // If the page loads before the Native Client module loads, then set the - // status message indicating that the module is still loading. Otherwise, - // do not change the status message. - function pageDidLoad() { - if (helloWorldModule == null) { - updateStatus('LOADING...'); - } else { - // It's possible that the Native Client module onload event fired - // before the page's onload event. In this case, the status message - // will reflect 'SUCCESS', but won't be displayed. This call will - // display the current message. - updateStatus(); - } - } - - // Set the global status message. If the element with id 'statusField' - // exists, then set its HTML to the status message as well. - // opt_message The message test. If this is null or undefined, then - // attempt to set the element with id 'statusField' to the value of - // |statusText|. - function updateStatus(opt_message) { - if (opt_message) - statusText = opt_message; - var statusField = document.getElementById('statusField'); - if (statusField) { - statusField.innerHTML = statusText; - } - } - </script> -</head> -<body onload="pageDidLoad()"> - -<h1>Native Client Simple Module</h1> -<h2>Status: <code id="statusField">NO-STATUS</code></h2> - <!-- 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. - - The src points to a manifest file, which provides the Native Client plug-in - a mapping between architecture and NaCl Executable (NEXE). - - We use a non-zero sized embed to give Chrome space to place the bad plug-in - graphic, if there is a problem. - --> - <div id="listener"> - <script type="text/javascript"> - var listener = document.getElementById('listener') - listener.addEventListener('load', moduleDidLoad, true); - listener.addEventListener('message', handleMessage, true); - </script> - - <embed name="nacl_module" - id="hello_world" - width=200 height=200 - src="hello_world.nmf" - type="application/x-nacl" /> - </div> -</body> -</html> diff --git a/native_client_sdk/src/examples/hello_world_interactive/hello_world.html b/native_client_sdk/src/examples/hello_world_interactive/hello_world_interactive.html index 516a995..516a995 100644 --- a/native_client_sdk/src/examples/hello_world_interactive/hello_world.html +++ b/native_client_sdk/src/examples/hello_world_interactive/hello_world_interactive.html diff --git a/native_client_sdk/src/examples/hello_world_newlib/hello_world.c b/native_client_sdk/src/examples/hello_world_newlib/hello_world.c index 72c7a4a..79ecc75 100644 --- a/native_client_sdk/src/examples/hello_world_newlib/hello_world.c +++ b/native_client_sdk/src/examples/hello_world_newlib/hello_world.c @@ -22,6 +22,7 @@ #include "ppapi/c/ppp_instance.h" #include "ppapi/c/ppp_messaging.h" + static PPB_Messaging* ppb_messaging_interface = NULL; static PPB_Var* ppb_var_interface = NULL; @@ -68,7 +69,7 @@ static PP_Bool Instance_DidCreate(PP_Instance instance, const char* argn[], const char* argv[]) { ppb_messaging_interface->PostMessage(instance, - CStrToVar("Hello a World (NEWLIB)")); + CStrToVar("Hello World: " TCNAME)); return PP_TRUE; } diff --git a/native_client_sdk/src/examples/hello_world_newlib/hello_world.html b/native_client_sdk/src/examples/hello_world_newlib/hello_world.html index 60f3722..982fe7a 100644 --- a/native_client_sdk/src/examples/hello_world_newlib/hello_world.html +++ b/native_client_sdk/src/examples/hello_world_newlib/hello_world.html @@ -6,14 +6,39 @@ found in the LICENSE file. --> <head> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> <title>Hello, World!</title> <script type="text/javascript"> - helloWorldModule = null; // Global application object. - statusText = 'NO-STATUS'; + naclModule = null; // Global application object. + statusText = 'NO-STATUSES'; - // Indicate success when the NaCl module has loaded. + function ExtractSearchParameter(name, def_value) { + var nameIndex = window.location.search.indexOf(name + "="); + if (nameIndex != -1) { + var value = location.search.substring(nameIndex + name.length + 1); + var endIndex = value.indexOf("&"); + if (endIndex != -1) + value = value.substring(0, endIndex); + return value; + } + return def_value; + } + + function createNaClModule(name, tool, width, height) { + var listenerDiv = document.getElementById('listener'); + var naclModule = document.createElement('embed'); + naclModule.setAttribute('name', 'nacl_module'); + naclModule.setAttribute('id', 'file_io'); + naclModule.setAttribute('width', width); + naclModule.setAttribute('height',height); + naclModule.setAttribute('src', tool + '/' + name + '.nmf'); + naclModule.setAttribute('type', 'application/x-nacl'); + listenerDiv.appendChild(naclModule); + } + // Indicate success when the NaCl module has loaded. function moduleDidLoad() { - helloWorldModule = document.getElementById('hello_world'); + naclModule = document.getElementById('nacl_module'); updateStatus('SUCCESS'); } @@ -26,14 +51,17 @@ // status message indicating that the module is still loading. Otherwise, // do not change the status message. function pageDidLoad() { - if (helloWorldModule == null) { - updateStatus('LOADING...'); + updateStatus('Page loaded.'); + if (naclModule == null) { + tool = ExtractSearchParameter('tool', 'newlib'); + updateStatus('Creating embed: ' + tool) + createNaClModule('hello_world', tool, 200, 200) } else { // It's possible that the Native Client module onload event fired // before the page's onload event. In this case, the status message // will reflect 'SUCCESS', but won't be displayed. This call will // display the current message. - updateStatus(); + updateStatus('Waiting.'); } } @@ -76,12 +104,6 @@ listener.addEventListener('load', moduleDidLoad, true); listener.addEventListener('message', handleMessage, true); </script> - - <embed name="nacl_module" - id="hello_world" - width=200 height=200 - src="hello_world.nmf" - type="application/x-nacl" /> </div> </body> </html> |