Bundling JCA

The EPICS archiver appliance bundles a version of JCA and EPICS for linux-x86 and linux-x86_64 platforms. This document outlines the steps used to build the so's and jar's for inclusion. Bear in mind, this is mostly intended for developers; however, this should give you an idea of how we generate the .so's that are bundled with the tarball.
  1. To build 32 bit binaries on 64 bit boxes, we need to install the 32 bit version of the C libraries. On Redhat, this is accomplished by yum -y install glibc-devel.i686 To build 64 bit binaries on 32 bit Redhat, you'd probably need the reverse. yum -y install glibc-devel.x86_64 In addition, we may need to add links to the appropriate versions of readline and ncurses. These packages typically exist on the system but for some reason, Redhat does not link the 32 bit versions on 64 bit Linux.
    ln -s /lib/libncurses.so.5.7 /lib/libncurses.so
    ln -s /lib/libreadline.so.6 /lib/libreadline.so
  2. Download the latest build stable version of EPICS and untar it into a folder called base. You should have a folder like so
    [mshankar@cdlx27 BundleJCA]$ ls -ltrd base/base-
    drwxr-xr-x 7 mshankar cd 4096 Nov 19 11:19 base/base-
    [mshankar@cdlx27 BundleJCA]$ 
  3. Edit configure/CONFIG_SITE and change the CROSS_COMPILER_TARGET_ARCHS to include linux-x86_64-debug linux-x86-debug like so
    # override 
    CROSS_COMPILER_TARGET_ARCHS=linux-x86_64-debug linux-x86-debug
    Also, turn on the generation of static binaries.
    #  Build client objects statically ?
    #        must be either YES or NO
  4. Now run make and make install. This should make and install the required files.
    [mshankar@cdlx27 base-]$ ls -l lib/linux-x86-debug/libca.so lib/linux-x86-debug/libCom.so lib/linux-x86_64-debug/libca.so lib/linux-x86_64-debug/libCom.so bin/linux-x86-debug/caRepeater bin/linux-x86_64-debug/caRepeater 
    -r-xr-xr-x 1 mshankar cd  5268 Nov 19 14:08 bin/linux-x86-debug/caRepeater*
    -r-xr-xr-x 1 mshankar cd 14942 Nov 19 14:07 bin/linux-x86_64-debug/caRepeater*
    lrwxrwxrwx 1 mshankar cd    14 Nov 19 14:07 lib/linux-x86-debug/libCom.so -> libCom.so.3.14
    lrwxrwxrwx 1 mshankar cd    13 Nov 19 14:08 lib/linux-x86-debug/libca.so -> libca.so.3.14
    lrwxrwxrwx 1 mshankar cd    14 Nov 19 14:07 lib/linux-x86_64-debug/libCom.so -> libCom.so.3.14
    lrwxrwxrwx 1 mshankar cd    13 Nov 19 14:07 lib/linux-x86_64-debug/libca.so -> libca.so.3.14
  5. Create the folder for the extensions and download the latest version of JCA.
    mkdir extensions
    cd extensions/
    mkdir extensions-3.14.12
    cd extensions-3.14.12/
    mkdir src
    cd src/
    hg clone "http://epics-jca.hg.sourceforge.net/hgweb/epics-jca/jca"
    cd jca
  6. Determine the tags in the repository and switch to a known tag using
    hg tags
    hg checkout JCA_20120614_2_3_6
  7. First, let's build the 64 bit versions of the JCA JNI files. As we are generating the .so's with debug information, we create and edit a new build.properties file for linux-x86_64-debug.
    cp config/build.linux-x86_64.properties config/build.linux-x86_64-debug.properties
    Edit the newly created config/build.linux-x86_64-debug.properties and add a -G to the g++ compile command like so...
    jni.objs.cmd.args=-c  -G  -fPIC -D_POSIX_C_SOURCE=199506L -D_POSIX_THREADS \
    Similarly, we add a -G to the library command and also replace linux-x86_64 with linux-x86_64-debug
    jni.lib.cmd.args=-shared  -G  -fPIC \
        -L${epics.base}/lib/linux-x86_64-debug -lca -lCom -lpthread -lreadline -lncurses -lm -lrt \
        -Wl,-rpath,. \
        -Wl,-rpath,${epics.base}/lib/linux-x86_64-debug \
        -o ${@target} ${@src}
  8. Change build.xml to manually control the architecture. The JCA ant tasks use the targetarch ant task to determine the architecture. To manually control the architecture, edit build.xml, comment out the targetarch task like so
        <!-- set the property arch to the correct value -->
        <!-- targetarch name="arch"/ -->
    and add a environment variable at the top of build.xml like so
      <property environment="env"/>
      <property name="arch" value="linux-x86_64-debug"/>
  9. We point to the base we generated in the previous steps and also change the LD_LIBRARY_PATH to use this version of base.
    export EPICS_BASE_RELEASE=/scratch/Work/temp/BundleJCA/base/base-
    export EPICS_EXTENSIONS=/scratch/Work/temp/BundleJCA/extensions/extensions-3.14.12
    export LD_LIBRARY_PATH=/opt/local/jdk_latest/jre/lib/i386:/opt/local/lib:/scratch/Work/temp/BundleJCA/base/base-
  10. We then compile.
    ant install
    If all goes well, we should have a jca.jar and a libjca.so.
    [mshankar@cdlx27 jca]$ ls -ltr ../../lib/linux-x86_64-debug/libjca.so ../../javalib/jca.jar 
    -rw-r--r-- 1 mshankar cd  39768 Nov 20 15:04 ../../lib/linux-x86_64-debug/libjca.so
    -rw-r--r-- 1 mshankar cd 240620 Nov 20 15:04 ../../javalib/jca.jar
  11. We change the architecture in build.xml to linux-x86-debug and then repeat. In addition to adding the -G argument, we'll also need to add a -m32 argument to cater to 32 bit architectures.
    cp config/build.linux-x86.properties config/build.linux-x86-debug.properties
    vim config/build.linux-x86-debug.properties
    vim build.xml
    export LD_LIBRARY_PATH=/opt/local/jdk_latest/jre/lib/i386:/opt/local/lib:/scratch/Work/temp/BundleJCA/base/base-
    ant install
    If all goes well, we should have a jca.jar and a libjca.so.
    [mshankar@cdlx27 jca]$ ls -ltr ../../lib/linux-x86-debug/libjca.so ../../javalib/jca.jar
    -rw-r--r-- 1 mshankar cd  38973 Nov 20 16:02 ../../lib/linux-x86-debug/libjca.so
    -rw-r--r-- 1 mshankar cd 240631 Nov 20 16:02 ../../javalib/jca.jar
  12. After copying the .so files and caRepeater to the appropriate folder in the EPICS archiver appliance source respository, delete the folders used to build the JCA .so's. This is to make sure any RPATH's in the .so will not be accidentally honored during any testing and only the embedded .so's are picked up.