Skip to content

Building Tutorial

Will Hedgecock edited this page Oct 22, 2021 · 42 revisions

Building this library yourself is not advised (at least not for distribution) as it requires native compilation across multiple platforms. It is recommended to simply use the pre-built jSerialComm.jar library in your application. For installation instructions, please refer to the Installation wiki.


Required Tools

If you do choose to build this library for your specific system, the recommended methodology is to use Gradle coupled with two Java SDKs, versions 1.6 and 9.0.4 (for backward compatibility). These tools can be obtained from the following locations:

Please note that there may be alternate methods of obtaining the Java JDK based on your operating system (especially certain Linux distributions).

If you would like to edit any of the source code or view it in an IDE (such as Eclipse), you can automatically create the Eclipse project files by entering the following instruction on a command line or terminal from the base directory of this project:

gradle eclipse

You can then import the project into Eclipse using the built-in "Import->Existing Project into Workspace" tool. (Note that if you use Eclipse as an IDE, you will probably want to install the Eclipse CDT plugin for proper handling of the C source code)

Once the required tools have been installed, refer to the section corresponding to your specific Operating System for further instructions.


Linux

To build the library on Linux, you will need both the 32- and 64-bit header files and libraries associated with the C Standard Library and GCC. On some distributions, these packages can be obtained by installing the multilib versions of the required Linux tools. On other distros, you will have to manually install them by specifying the correct extensions (.i686 and .x86_64) in your package manager.

If you plan to cross-compile for an ARM-based or PowerPC-based architecture (e.g. RaspberryPi, BeagleBone, etc.), you will need to ensure that you have a cross-compiler installed (preferably crosstool-ng) and that the gcc compiler for ARM or PowerPC is available on your PATH.

In all cases, you must first ensure that both the 32- and 64-bit (and optionally ARM and/or PowerPC) versions of the following tools are installed on your Linux system:

  • gcc
  • make
  • glibc (development version)
  • kernel-headers (or linux-headers)

Ensure that the JDK_HOME environment variable has been set for the 9.0.4 version of your Java SDK. The correct directory can usually be found by entering the following command:

readlink -f /usr/bin/java

Export the result of this command up to BUT NOT INCLUDING the "/jre/..." portion using the 'export' command. For example, if 'readlink' produced "/usr/lib/jvm/java-9.0.4/jre/bin/java" as an output, the export command would look like:

export JDK_HOME=/usr/lib/jvm/java-9.0.4

Change directories to jSerialComm/src/main/c/Posix/, and run the following commands in order:

make linux
make arm (optional, if compiling for ARM)
make powerpc (optional, if compiling for PowerPC)
cd ../../../..
gradle build

The resulting jSerialComm library can be found in the project directory jSerialComm/build/libs/ under the name "jSerialComm-{VERSION}.jar"


Solaris

Solaris support requires the presence of two Linux-based Sun cross-compilers: one for x86, and one for the Sparc hardware architecture. If you do not have these cross-compilers installed, instructions for creating them can be found here.

As with the Linux target compilation instructions, you must ensure that the JDK_HOME environment variable has been set for the 9.0.4 version of your Java SDK. The correct directory can usually be found by entering the following command:

readlink -f /usr/bin/java

Export the result of this command up to BUT NOT INCLUDING the "/jre/..." portion using the 'export' command. For example, if 'readlink' produced "/usr/lib/jvm/java-9.0.4/jre/bin/java" as an output, the export command would look like:

export JDK_HOME=/usr/lib/jvm/java-9.0.4

Change directories to jSerialComm/src/main/c/Posix/, and run the following commands in order:

make solaris
cd ../../../..
gradle build

The resulting jSerialComm library can be found in the project directory jSerialComm/build/libs/ under the name "jSerialComm-{VERSION}.jar"


Android

Ensure that the Android NDK is installed on your system. If it is not, it can be downloaded from the Android NDK Web Page. For these instructions, assume that the NDK is installed at {NDK_HOME}.

Change directories to jSerialComm/src/main/c/Posix/, and run the following commands in order:

{NDK_HOME}/ndk-build
cd ../../../..
gradle build

The resulting jSerialComm library can be found in the project directory jSerialComm/build/libs/ under the name "jSerialComm-{VERSION}.jar"


Mac OS X

Ensure that Xcode is installed on your system. If it is not, it can be downloaded via the App Store.

You must also make sure that the Xcode Command Line Tools are installed. This can be done by entering the following command in a terminal: xcode-select --install

Change directories to jSerialComm/src/main/c/Posix/, and run the following commands in order:

make osx
cd ../../../..
gradle build

The resulting jSerialComm library can be found in the project directory jSerialComm/build/libs/ under the name "jSerialComm-{VERSION}.jar"


Windows

Ensure that the Visual Studio C++ Compiler is installed on your system. If it is not, you can download a free version (Visual C++ 2019 Community) from here.

Open a command prompt (Run->'cmd') and change to the following project directory: *jSerialComm\src\main\c\Windows*

On Windows, the Visual Studio Compiler must be configured to build either 32- or 64-bit binaries but never both at the same time. Therefore, you will have to build binaries for the two architectures separately. For the following commands, {VC_DIRECTORY} is the installation directory of your Visual Studio C++ Compiler (for example: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC or C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build). Run the following commands in order:

{VC_DIRECTORY}\vcvarsall.bat x64
nmake win64
{VC_DIRECTORY}\vcvarsall.bat x86
nmake win32
cd ..\..\..\..
gradle build

The resulting jSerialComm library can be found in the project directory *jSerialComm\build\libs* under the name "jSerialComm-{VERSION}.jar"