JInput for ARM linux

Here I come again… ;D

The pandora got 2 analogic stick so I start to look for a port of JInput. I begin to look to the source code but I don’t even know how to setup the dev environment and to build it :persecutioncomplex:

The port by itself should be “easy” : just to recompile the x86 linux lib for ARM, and load the good lib at JInput start.

Yeah, thar be dragons. :slight_smile:

You’ll need to set up a toolchain and a VM to compile and test with. Here’s one guide specifically for Pandora:
http://www.rjmitchell.ca/~jeff/blog2009/2010/06/02/getting-up-and-going-with-a-crosscompiler-for-pandora-arm-in-5-minutes/

I’ve done this once before for another ARM device and following a similar set of instructions worked out fine for me.

I know, I know… but after I download the CVS of jinput, I’m lost. I had never use ANT without an editor.

I have take a better look to it. It seems that the ant script is not made for crossplatform compiling, am I wrong ?

Ok, first time without modification :

C:\jinput>ant
Buildfile: C:\jinput\build.xml

init:

dist:

init:

compile:
    [javac] C:\jinput\coreAPI\build.xml:13: warning: 'includeantruntime' was not
 set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 21 source files to C:\jinput\coreAPI\classes
    [javac] C:\jinput\coreAPI\src\java\net\java\games\input\DefaultControllerEnv
ironment.java:54: package net.java.games.util.plugins does not exist
    [javac] import net.java.games.util.plugins.*;
    [javac] ^
    [javac] C:\jinput\coreAPI\src\java\net\java\games\input\DefaultControllerEnv
ironment.java:202: cannot find symbol
    [javac] symbol  : class Plugins
    [javac] location: class net.java.games.input.DefaultControllerEnvironment
    [javac]             Plugins plugins = new Plugins(file);
    [javac]             ^
    [javac] C:\jinput\coreAPI\src\java\net\java\games\input\DefaultControllerEnv
ironment.java:202: cannot find symbol
    [javac] symbol  : class Plugins
    [javac] location: class net.java.games.input.DefaultControllerEnvironment
    [javac]             Plugins plugins = new Plugins(file);
    [javac]                                   ^
    [javac] 3 errors

BUILD FAILED
C:\jinput\build.xml:110: The following error occurred while executing this line:

C:\jinput\build.xml:69: The following error occurred while executing this line:
C:\jinput\coreAPI\build.xml:13: Compile failed; see the compiler error output fo
r details.

Total time: 0 seconds

Just find out this post : http://www.java-gaming.org/index.php/topic,21320.0.html

Ok, I have to understand the ANT script now to modify it…

I manage to compile it for ARM and it seems to work fine on the Pandora ;D

Modification on LinuxEnvironmentPlugin.java was simple :


        private final static String LIBNAME = "jinput-linux";
	private final static String POSTFIX64BIT = "64";
	private final static String POSTFIXARM = "ARM";
	private static boolean supported = false;

...

static {
		String osName = getPrivilegedProperty("os.name", "").trim();
		if(osName.equals("Linux")) {
            supported = true;
			if("i386".equals(getPrivilegedProperty("os.arch"))) {
				loadLibrary(LIBNAME);
			}
                        else if("arm".equals(getPrivilegedProperty("os.arch"))) 
                        {
			  loadLibrary(LIBNAME + POSTFIXARM);
			}
                        else
                        {
			  loadLibrary(LIBNAME + POSTFIX64BIT);
			}
		}
	}

I didn’t need to do any modification on the native code. For the ant script, I don’t like what I have done. It is more an hack than an elegant solution. I have modify the build.xml for Linux native by replacing the Linux x86 compilation by the ARM compilation (since I use an x86 to compile the ARM code) :


  <?xml version="1.0" ?> 
- <!--  Written to assume that classpath is rooted in the current directory. 
  --> 
- <!--  So this should be OK if you make this script in the root of a filesystem. 
  --> 
- <!--  If not, you may prefer to adjust the basedir, or move some directories around. 
  --> 
- <!--  The idea is that both Ant and NetBeans have to know what the package root is 
  --> 
- <!--  for the classes in your application. 
  --> 
- <project name="JInput Linux port, Native code" basedir="." default="compileNativeJinputLib">
  <property name="libname64" value="libjinput-linux64.so" /> 
  <property name="libname32" value="libjinput-linux.so" /> 
  <property name="libnameARM value="libjinput-linuxARM.so" /> 
- <target name="createNativeDefinitions.java">
- <exec dir="." executable="gawk" os="Linux" output="../java/net/java/games/input/NativeDefinitions.java">
  <arg line="-f" /> 
  <arg line="getDefinitions" /> 
  <arg line="/usr/include/linux/input.h" /> 
  </exec>
  </target>
- <target name="clean">
- <delete>
  <fileset dir="." includes="*.o" /> 
  <fileset dir="." includes="*.so" /> 
  </delete>
  </target>
- <target name="compileNativeJinputLib">
- <exec executable="uname" outputproperty="hwplatform">
  <arg value="-m" /> 
  </exec>
- <condition property="libname" value="${libnameARM}" else="${libnameARM}">
  <equals arg1="${hwplatform}" arg2="x86_64" /> 
  </condition>
- <apply dir="." executable="arm-none-linux-gnueabi-gcc" os="Linux" dest="." skipemptyfilesets="true" failonerror="true">
  <arg line="-O2 -Wall -c -fPIC" /> 
  <arg value="-I${java.home}/include" /> 
  <arg value="-I${java.home}/include/linux" /> 
  <arg value="-I${java.home}/../include" /> 
  <arg value="-I${java.home}/../include/linux" /> 
  <arg value="-I../../../common/src/native" /> 
  <mapper type="glob" from="*.c" to="*.o" /> 
  <fileset dir="." includes="*.c" /> 
  <fileset dir="../../../common/src/native" includes="*.c" /> 
  </apply>
- <apply dir="." parallel="true" executable="arm-none-linux-gnueabi-gcc" os="Linux" failonerror="true">
  <arg line="-shared -O2 -Wall -o ${libname}" /> 
  <fileset dir="." includes="*.o" /> 
  </apply>
- <apply dir="." parallel="true" executable="arm-none-linux-gnueabi-strip" os="Linux" failonerror="true">
  <fileset file="${libname}" /> 
  </apply>
  </target>
  </project>

I will make binaries available after testing them more.

Hi

if you can upload a .patch file with your changes I will take a look and maybe include them in core jinput. It’s not something I have access too, so won’t be maintaining, but if someone has done the ground work and finds it useful, then it ought to be in jinput :slight_smile:

Cheers

Endolf

I will make a better ANT script first. (After I have to understand how to make the patch ;))