-
Notifications
You must be signed in to change notification settings - Fork 6
/
jnigen.php
82 lines (66 loc) · 3.64 KB
/
jnigen.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/app.class.php"); require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/nav.class.php"); require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/menu.class.php"); $App = new App(); $Nav = new Nav(); $Menu = new Menu(); include($App->getProjectCommon());
$pageTitle = "Generating the SWT JNI Code";
ob_start();
?>
<div id="midcolumn">
<h1>Generating the SWT JNI Code</h1>
<p>All of the C code used by SWT is generated by the <b>JNIGeneratorApp</b>
application included in the SWT Tools bundle and available on the
<a href="updatesite.php">SWT Tools Update Sites</a>.
This page describes how to use this tool when fixing bugs or adding
features to SWT.</p>
<b>Note</b> that this process has changed for SWT 3.5. For older versions see <a href="jnigen_34.php">Generating the SWT JNI Code for SWT 3.4</a>.
<p></p>
<h3>Adding native methods</h3>
<ol>
<li>Add the function prototype in <tt>OS.java</tt>, copying the style and structure
of the other functions in that file. Note that for Mac/Cocoa, portions of <tt>OS.java</tt>
are also <a href="macgen.php">generated</a>.
<p></p>
<li>Install the latest SWT Tools from the <a href="updatesite.php">SWT Tools Update Site</a>.
<p></p>
<li>Restart Eclipse.
<p></p>
<li>Use code assist templates like <b>jni*</b> (i.e. <i>jnifield</i> and <i>jnimethod</i>) to add javadoc tags that describe flags and casts for any primitive types. See <a href="jnigen_metadata.php">metadata</a> for more documentation.
<p></p>
<center><img src="images/jnitemplates.png" alt="build.xml"></center>
<p></p>
<li>Save the file. This should build the appropriate C files.
<p></p>
<li>Compile the new C code and copy the new libraries to the appropriate fragment. Steps:
<ul>
<li>right-click on the <tt>build.xml</tt> file of the appropriate fragment (i. e. org.eclipse.swt.<ws>.<os>.<arch>) depending on the os, platform and architecture being built</li>
<li>select "Run As -> Ant Build..."</li>
<li>on the Targets tab check the <tt>build_libraries</tt> target</li>
<li>on the JRE tab select "Run in the same JRE as the workspace"</li>
<li>on the Refresh tab check "Refresh resources upon completion" to refresh your workspace
after running the build; this ensures that Eclipse will pick up the fresh binaries</li>
<li>press the "Run" button to begin</li>
<p></p>
</ol>
<h3>Adding structs</h3>
<p>Often, methods return values or require parameters as a C struct. To
add a new structure, simply add a new class in the same package as
the OS.java file which matches the definition of the C structure.
This will be picked up and correctly handled by <i>JNIGeneratorApp</i>.</p>
<p>If a struct is input-only or output-only, this information can be used
by <i>JNIGeneratorApp</i> to generate more efficient C code. Use the
<b>flags</b> attribute of the native function to indicate this in the
metadata.</p>
<h3>More Hints</h3>
<ul>
<li>For GTK+ and Motif, all native functions must be wrapped in locking
code. When adding functions, simply copy the style and structure of the
other native functions.
<li>Many functions on Mac OS X return structs which use <b>unions</b>. For
an example of how to add the markup for a union, see the
<b>ControlFontStyleRec</b> structure and its metadata.
</ul>
<p>And there you go! If you're having trouble, please post to the SWT
mailing list or file a new bug in bugzilla.</p>
</div>
<?php
$html = ob_get_clean();
# Generate the web page
$App->generatePage($theme, $Menu, $Nav, $pageAuthor, $pageKeywords, $pageTitle, $html);
?>