GCJ Guidelines

GCJ AOT bits SHOULD be built and included in packages. If GCJ-specific issues prevent you from building the package, it is permissible to simply omit GCJ support and build using OpenJDK. However, please file a bug against the gcc component in Red Hat bugzilla. Compilation into native code must be optional and enabled by default, if present.

In some rare cases Java packages might not contain any executable code whatsoever so AOT-compiling for gcj would not be required. An example of such a package would be one that contained only annotation definitions.

Note: For Fedora versions < 8, no JDK was available other than GCJ so java packages with executable code MUST have the GCJ AOT bits.

How to add GCJ AOT bits to a Java package

Like other Java runtimes, libgcj can load classes from bytecode class files. Unlike other Java runtimes, libgcj can also load classes that have been compiled to native machine code using GCJ.

  • For packages in which all JAR files are in the main package:

\1. Add the following definition:

%global with_gcj %{!?_without_gcj:1}%{?_without_gcj:0}

\1. Conditionalize dependencies and be architecture dependent

%if %{with_gcj}
BuildRequires:    java-gcj-compat-devel >= 1.0.31
Requires(post):   java-gcj-compat >= 1.0.31
Requires(postun): java-gcj-compat >= 1.0.31
%else
BuildArch:      noarch
%endif

\1. Add the following to the end of %install section:

%if %{with_gcj}
%{_bindir}/aot-compile-rpm
%endif

\1. Add the following to the package’s %post and %postun sections, creating the sections if necessary:

%if %{with_gcj}
  if [ -x %{_bindir}/rebuild-gcj-db ]
  then
    %{_bindir}/rebuild-gcj-db
  fi
%endif

\1. Add the following to the %files section:

%if %{with_gcj}
%attr(-,root,root) %{_libdir}/gcj/%{name}
%endif
  • For packages in which all JAR files are in one subpackage, the Requires(), %post, %postun and %files lines should refer to that subpackage.

  • For packages in which more than one subpackage (including the main package) contains JAR files, then each subpackage should have its own Requires(), %post and %postun lines, and the %files lists should be split such that the subpackage that contains /path/to/foo-x.y.z.jar should have the following %files line:

%if %{with_gcj}
%attr(-,root,root) %{_libdir}/gcj/%{name}/foo-x.y.z.jar.*
%endif

Note that the path has been stripped and .* has been appended.