This commit is contained in:
Doug MacEachern 2009-01-18 03:08:44 +00:00
parent 1cd800ff6e
commit e787667e91
10 changed files with 2002 additions and 0 deletions

View File

@ -0,0 +1,522 @@
<!--
Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
This file is part of SIGAR.
SIGAR is free software; you can redistribute it and/or modify
it under the terms version 2 of the GNU General Public License as
published by the Free Software Foundation. This program is distributed
in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
-->
<property environment="env"/>
<property name="build" location="build"/>
<property name="jni.bin" location="${build}"/>
<property name="jni.define.name" value="JNI"/>
<property name="jni.source.dir" value="src"/>
<property name="jni.src.java" value="src"/>
<property name="jni.libprefix" value="java"/>
<property name="jni.libversion" value=""/>
<property name="uni.sdk.version" value="4u"/>
<property name="osx.min" value="-mmacosx-version-min=10.3"/>
<property name="cpptasks.jar" location="lib/cpptasks.jar"/>
<taskdef name="cc" classname="net.sf.antcontrib.cpptasks.CCTask">
<classpath location="${cpptasks.jar}"/>
</taskdef>
<target name="jni-init">
<mkdir dir="${build}/classes"/>
<available property="libproc.h" file="/usr/include/libproc.h"/>
<condition property="jni.debug" value="true">
<isset property="jni.dmalloc"/>
</condition>
<condition property="jni.optim" value="true">
<not>
<istrue value="${jni.debug}"/>
</not>
</condition>
<condition property="static.gcc">
<os arch="i386"/><!-- only for x86 solaris -->
</condition>
<condition property="jni.javahome" value="${env.JAVA_HOME}">
<isset property="env.JAVA_HOME"/>
</condition>
<condition property="jni.javahome" value="${java.home}">
<not>
<isset property="jni.javahome"/>
</not>
</condition>
<echo>java.home=${jni.javahome}</echo>
<checksum file="${jni.javahome}/include/jni.h" property="jni.md5"/>
<condition property="linux">
<equals arg1="${os.name}" arg2="Linux"/>
</condition>
<condition property="solaris">
<equals arg1="${os.name}" arg2="SunOS"/>
</condition>
<condition property="win32">
<os family="windows"/>
</condition>
<condition property="hpux">
<equals arg1="${os.name}" arg2="HP-UX"/>
</condition>
<condition property="aix">
<equals arg1="${os.name}" arg2="AIX"/>
</condition>
<condition property="darwin">
<equals arg1="${os.name}" arg2="Mac OS X"/>
</condition>
<condition property="freebsd">
<equals arg1="${os.name}" arg2="FreeBSD"/>
</condition>
<condition property="openbsd">
<equals arg1="${os.name}" arg2="OpenBSD"/>
</condition>
<condition property="netbsd">
<equals arg1="${os.name}" arg2="NetBSD"/>
</condition>
<condition property="osf1">
<equals arg1="${os.name}" arg2="OSF1"/>
</condition>
<condition property="jni.os" value="linux">
<isset property="linux"/>
</condition>
<condition property="jni.os" value="win32">
<isset property="win32"/>
</condition>
<condition property="jni.os" value="solaris">
<isset property="solaris"/>
</condition>
<condition property="jni.os" value="aix">
<isset property="aix"/>
</condition>
<condition property="jni.os" value="hpux">
<isset property="hpux"/>
</condition>
<condition property="jni.os" value="darwin">
<isset property="darwin"/>
</condition>
<condition property="jni.os" value="freebsd">
<isset property="freebsd"/>
</condition>
<condition property="jni.os" value="openbsd">
<isset property="openbsd"/>
</condition>
<condition property="jni.os" value="netbsd">
<isset property="netbsd"/>
</condition>
<!-- darwin and freebsd use the same source files -->
<condition property="jni.src" value="darwin">
<isset property="freebsd"/>
</condition>
<condition property="jni.src" value="darwin">
<isset property="openbsd"/>
</condition>
<condition property="jni.src" value="darwin">
<isset property="netbsd"/>
</condition>
<condition property="jni.os" value="osf1">
<isset property="osf1"/>
</condition>
<condition property="jni.jdk.os" value="${jni.os}">
<and>
<isfalse value="${hpux}"/>
<isfalse value="${osf1}"/>
</and>
</condition>
<condition property="jni.jdk.os" value="hp-ux">
<istrue value="${hpux}"/>
</condition>
<condition property="jni.jdk.os" value="alpha">
<istrue value="${osf1}"/>
</condition>
<condition property="jni.src" value="${jni.os}">
<isfalse value="${jni.src}"/>
</condition>
<echo message="jni.src=${jni.src}, jni.jdk.os=${jni.jdk.os}, ${sun.arch.data.model}-bit"/>
<javac srcdir="${jni.src.java}" destdir="${build}/classes" debug="true"
source="1.4" target="1.4"
includes="org/hyperic/jni/*.java"/>
<taskdef name="libarch" classname="org.hyperic.jni.ArchNameTask">
<classpath location="${build}/classes"/>
</taskdef>
<taskdef name="copydep" classname="org.hyperic.jni.CopyDependsTask">
<classpath location="${build}/classes"/>
</taskdef>
<libarch/>
<property name="jni.project.archname"
value="${project.name}-${jni.libarch}"/>
<condition property="jni.libname"
value="${jni.libprefix}${jni.project.archname}${jni.libversion}">
<isfalse value="${jni.libname}"/>
</condition>
<property name="jni.libname.full"
value="${jni.libpre}${jni.libname}${jni.libext}"/>
<property name="jni.objdir" value="${build}/obj/${jni.libarch}"/>
<condition property="uni.sdk"
value="/Developer/SDKs/MacOSX10.${uni.sdk.version}.sdk">
<istrue value="${darwin}"/>
</condition>
<condition property="jni.cc" value="uni-cc">
<isset property="darwin"/>
</condition>
<property name="jni.cc" value="jni-cc"/>
<condition property="cc.runtime" value="static">
<isset property="win32"/>
</condition>
<condition property="cc.runtime" value="dynamic">
<not>
<isset property="win32"/>
</not>
</condition>
</target>
<target name="jni-lib-copy" if="jni.libarch">
<mkdir dir="${jni.bin}/lib"/>
<copy toDir="${jni.bin}/lib" overwrite="true">
<fileset dir="${jni.objdir}/lib"/>
</copy>
<chmod perm="a+x">
<fileset dir="${jni.bin}/lib">
<include name="*.sl"/>
</fileset>
</chmod>
</target>
<target name="jni-compile" if="jni.libarch">
<antcall target="${jni.cc}" inheritRefs="true"/>
</target>
<!-- run jni-cc twice {ppc,i386}, then feed both to lipo to build a universal binary -->
<target name="uni-cc" if="jni.libarch">
<property name="shlib" value="${jni.objdir}/lib/lib${jni.libname}.dylib"/>
<!-- ppc -->
<echo message="build 'ppc' arch"/>
<antcall target="jni-cc" inheritRefs="true">
<param name="uni.arch" value="ppc"/>
</antcall>
<copy file="${shlib}" tofile="${shlib}.ppc"/>
<!-- i386 -->
<echo message="build 'i386' arch"/>
<delete>
<fileset dir="${jni.objdir}" includes="*.o"/>
</delete>
<antcall target="jni-cc" inheritRefs="true">
<param name="uni.arch" value="i386"/>
</antcall>
<copy file="${shlib}" tofile="${shlib}.i386"/>
<echo message="lipo 'ppc'+'i386'"/>
<exec executable="lipo">
<arg line="-create ${shlib}.ppc ${shlib}.i386 -output ${jni.objdir}/lib/lib${jni.libname}.dylib"/>
</exec>
<delete>
<fileset dir="${jni.objdir}/lib" includes="*.ppc,*.i386"/>
</delete>
</target>
<target name="jni-cc" if="jni.libarch">
<mkdir dir="${jni.objdir}/lib"/>
<echo message="jni libname=${jni.libname}"/>
<cc outtype="shared"
outfile="${jni.objdir}/lib/${jni.libname}"
objdir="${jni.objdir}"
runtime="${cc.runtime}"
relentless="false">
<!-- HPUX -->
<compiler name="hp" if="hpux">
<compilerarg value="+Z"/>
<defineset>
<define name="${jni.define.name}_HPUX"/>
<define name="_HPUX_SOURCE"/>
<define name="_REENTRANT"/>
</defineset>
</compiler>
<linker name="hp" if="hpux">
<libset if="jni.libset.libs"
dir="${jni.libset.dir}"
libs="${jni.libset.libs}"/>
<syslibset libs="nsl"/>
<syslibset libs="nm"/>
</linker>
<!-- Solaris -->
<compiler name="gcc" if="solaris">
<compilerarg value="-O2" if="jni.optim"/>
<compilerarg value="-g" if="jni.debug"/>
<compilerarg value="-Wall"/>
<compilerarg value="-Werror" if="jni.werror"/>
<compilerarg value="-m64" if="jni.arch64"/>
<defineset>
<define name="${jni.define.name}_SOLARIS"/>
<define name="_REENTRANT"/>
<define name="_POSIX_PTHREAD_SEMANTICS"/>
<define name="DMALLOC" if="jni.dmalloc"/>
</defineset>
</compiler>
<linker name="gcc" if="solaris">
<!-- required for modern gcc to avoid libgcc_s.so dependency -->
<!-- this arg is ignored by older gcc -->
<linkerarg value="-static-libgcc"/>
<linkerarg value="-m64" if="jni.arch64"/>
<libset if="jni.libset.libs"
dir="${jni.libset.dir}"
libs="${jni.libset.libs}"/>
<libset if="jni.dmalloc"
dir="${jni.dmalloc}/lib"
libs="dmallocth"/>
</linker>
<!-- Linux -->
<compiler name="gcc" debug="${jni.debug}" if="linux">
<compilerarg value="-O2" if="jni.optim"/>
<compilerarg value="-g" if="jni.debug"/>
<compilerarg value="-Wall"/>
<compilerarg value="-Werror" if="jni.werror"/>
<compilerarg value="-m64" if="jni.usem64"/>
<defineset>
<define name="${jni.define.name}_LINUX"/>
<define name="_REENTRANT"/>
<define name="DMALLOC" if="jni.dmalloc"/>
</defineset>
</compiler>
<linker name="gcc" if="linux">
<libset if="jni.libset.libs"
dir="${jni.libset.dir}"
libs="${jni.libset.libs}"/>
<libset if="jni.dmalloc"
dir="${jni.dmalloc}/lib"
libs="dmallocth"/>
<linkerarg value="-m64" if="jni.usem64"/>
</linker>
<!-- Darwin -->
<compiler name="gcc" if="darwin">
<compilerarg value="-Wall"/>
<compilerarg value="-Werror" if="jni.werror"/>
<compilerarg value="-m64" if="jni.arch64"/>
<compilerarg value="-O2" if="jni.optim"/>
<compilerarg value="-g" if="jni.debug"/>
<compilerarg value="-isysroot"/>
<compilerarg value="${uni.sdk}"/>
<compilerarg value="-arch"/>
<compilerarg value="${uni.arch}"/>
<compilerarg value="${osx.min}"/>
<sysincludepath location="/Developer/Headers/FlatCarbon"/>
<defineset>
<define name="DARWIN"/>
<define name="DARWIN_HAS_LIBPROC_H" if="libproc.h"/>
</defineset>
</compiler>
<linker name="gcc" if="darwin">
<linkerarg value="-m64" if="jni.arch64"/>
<linkerarg value="-Wl,-syslibroot,${uni.sdk}"/>
<linkerarg value="-arch"/>
<linkerarg value="${uni.arch}"/>
<linkerarg value="${osx.min}"/>
<!-- for Gestalt() -->
<linkerarg value="-framework"/>
<linkerarg value="CoreServices"/>
<linkerarg value="-sectcreate,__TEXT,__info_plist,${jni.info.plist}" if="jni.info.plist"/>
<libset if="jni.libset.libs"
dir="${jni.libset.dir}"
libs="${jni.libset.libs}"/>
<syslibset libs="IOKit"/>
</linker>
<!-- Freebsd -->
<compiler name="gcc" if="freebsd">
<compilerarg value="-O2" if="jni.optim"/>
<compilerarg value="-g" if="jni.debug"/>
<compilerarg value="-Wall"/>
<compilerarg value="-Werror" if="jni.werror"/>
<defineset>
<define name="${jni.define.name}_FREEBSD"/>
</defineset>
</compiler>
<linker name="gcc" if="freebsd">
<libset if="jni.libset.libs"
dir="${jni.libset.dir}"
libs="${jni.libset.libs}"/>
<syslibset libs="kvm"/>
</linker>
<!-- OpenBSD -->
<compiler name="gcc" if="openbsd">
<compilerarg value="-O2" if="jni.optim"/>
<compilerarg value="-g" if="jni.debug"/>
<compilerarg value="-Wall"/>
<!-- <compilerarg value="-Werror" if="jni.werror"/> -->
<defineset>
<define name="${jni.define.name}_OPENBSD"/>
</defineset>
</compiler>
<linker name="gcc" if="openbsd">
<libset if="jni.libset.libs"
dir="${jni.libset.dir}"
libs="${jni.libset.libs}"/>
<syslibset libs="kvm"/>
</linker>
<!-- NetBSD -->
<compiler name="gcc" if="netbsd">
<compilerarg value="-O2" if="jni.optim"/>
<compilerarg value="-g" if="jni.debug"/>
<compilerarg value="-Wall"/>
<!-- <compilerarg value="-Werror" if="jni.werror"/> -->
<defineset>
<define name="${jni.define.name}_NETBSD"/>
</defineset>
</compiler>
<linker name="gcc" if="netbsd">
<libset if="jni.libset.libs"
dir="${jni.libset.dir}"
libs="${jni.libset.libs}"/>
<syslibset libs="kvm"/>
</linker>
<!-- AIX -->
<compiler name="xlc_r" if="aix">
<defineset>
<define name="${jni.define.name}_AIX"/>
<define name="_ALL_SOURCE"/>
<define name="_ANSI_C_SOURCE"/>
<define name="_POSIX_SOURCE"/>
</defineset>
</compiler>
<linker name="xlc_r" if="aix">
<libset if="jni.libset.libs"
dir="${jni.libset.dir}"
libs="${jni.libset.libs}"/>
</linker>
<!-- WIN32 -->
<linker name="msvc" debug="${jni.debug}" if="win32">
<libset if="jni.libset.libs"
dir="${jni.libset.dir}"
libs="${jni.libset.libs}"/>
<linkerarg value="/MACHINE:X64" if="jni.arch64"/>
<linkerarg value="${jni.info.res}" if="jni.info.res"/>
<syslibset libs="kernel32,user32,advapi32,ws2_32,netapi32,shell32,pdh,version"/>
</linker>
<compiler name="msvc" debug="${jni.debug}" if="win32">
<defineset>
<define name="WIN32"/>
<define name="_CRT_SECURE_NO_DEPRECATE"/>
<!-- XXX 2008 MSC express/SDK does not include atl headers -->
<define name="SIGAR_NO_ATL" if="jni.noatl"/>
</defineset>
</compiler>
<!-- OSF1 -->
<compiler name="gcc" if="osf1">
<compilerarg value="-Wall"/>
<compilerarg value="-pthread"/>
<defineset>
<define name="${jni.define.name}_OSF1"/>
</defineset>
</compiler>
<linker name="gcc" if="osf1">
<libset if="jni.libset.libs"
dir="${jni.libset.dir}"
libs="${jni.libset.libs}"/>
<syslibset libs="mach"/>
</linker>
<!-- C sources -->
<fileset dir="${jni.source.dir}">
<patternset refid="jni.source.files"/>
</fileset>
<includepath>
<path refid="jni.include.dirs"/>
</includepath>
<sysincludepath location="${jni.javahome}/include"/>
<sysincludepath location="${jni.javahome}/include/${jni.jdk.os}"/>
<sysincludepath location="${jni.dmalloc}/include"
if="jni.dmalloc"/>
</cc>
</target>
<target name="jni-clean">
<delete dir="${jni.objdir}"/>
</target>

Binary file not shown.

View File

@ -0,0 +1,22 @@
cpptasks.pat - provides support for HP cc and AIX xlc_r
the classes listed below are copy-n-pastes from existing cpptasks
classes, simply changed program names, flags, etc. the HP classes
were submitted as a patch to ant-contrib-developers on 10/09/2002,
to which there was no response, so have not bothered to submit the aix
patch.
SubsystemEnum patch is for the osf1 javac (aka tru64).
was throwing IllegalAccessError. why clone a final String[] anyhow??
CUtil patch is for jdk 1.3 (StringBuffer.indexOf is 1.4+)
GccLinker patch adds -arch to known flags for building universal binaries
added | derived from
--------------------------
HPCompiler | aCCCompiler
HPLinker | aCCLinker
XlcCompiler | VisualAgeCCompiler
XlcLinker | VisualAgeLinker
cpptasks.pat applies to:
cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/ant-contrib \
co -D"2006/04/28 15:00:00" cpptasks

View File

@ -0,0 +1,696 @@
Index: src/net/sf/antcontrib/cpptasks/CUtil.java
===================================================================
RCS file: /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/CUtil.java,v
retrieving revision 1.28
diff -u -r1.28 CUtil.java
--- src/net/sf/antcontrib/cpptasks/CUtil.java 17 Mar 2006 16:38:12 -0000 1.28
+++ src/net/sf/antcontrib/cpptasks/CUtil.java 29 Apr 2006 02:35:28 -0000
@@ -438,19 +438,19 @@
StringBuffer buf = new StringBuffer (attrValue);
int quotePos;
- for (quotePos = -1; (quotePos = buf.indexOf("\"", quotePos + 1)) >= 0;) {
+ for (quotePos = -1; (quotePos = buf.toString().indexOf("\"", quotePos + 1)) >= 0;) {
buf.deleteCharAt(quotePos);
buf.insert (quotePos, "&quot;");
quotePos += 5;
}
- for (quotePos = -1; (quotePos = buf.indexOf("<", quotePos + 1)) >= 0;) {
+ for (quotePos = -1; (quotePos = buf.toString().indexOf("<", quotePos + 1)) >= 0;) {
buf.deleteCharAt(quotePos);
buf.insert (quotePos, "&lt;");
quotePos += 3;
}
- for (quotePos = -1; (quotePos = buf.indexOf(">", quotePos + 1)) >= 0;) {
+ for (quotePos = -1; (quotePos = buf.toString().indexOf(">", quotePos + 1)) >= 0;) {
buf.deleteCharAt(quotePos);
buf.insert (quotePos, "&gt;");
quotePos += 3;
Index: src/net/sf/antcontrib/cpptasks/CompilerEnum.java
===================================================================
RCS file: /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/CompilerEnum.java,v
retrieving revision 1.18
diff -u -r1.18 CompilerEnum.java
--- src/net/sf/antcontrib/cpptasks/CompilerEnum.java 8 Jul 2004 22:30:53 -0000 1.18
+++ src/net/sf/antcontrib/cpptasks/CompilerEnum.java 29 Apr 2006 02:35:28 -0000
@@ -25,7 +25,9 @@
import net.sf.antcontrib.cpptasks.devstudio.DevStudioResourceCompiler;
import net.sf.antcontrib.cpptasks.gcc.GccCCompiler;
import net.sf.antcontrib.cpptasks.hp.aCCCompiler;
+import net.sf.antcontrib.cpptasks.hp.HPCompiler;
import net.sf.antcontrib.cpptasks.ibm.VisualAgeCCompiler;
+import net.sf.antcontrib.cpptasks.ibm.XlcCompiler;
import net.sf.antcontrib.cpptasks.intel.IntelLinux32CCompiler;
import net.sf.antcontrib.cpptasks.intel.IntelLinux64CCompiler;
import net.sf.antcontrib.cpptasks.intel.IntelWin32CCompiler;
@@ -205,6 +207,8 @@
new ProcessorEnumValue("armcpp", ADSCCompiler.getArmCpp()),
new ProcessorEnumValue("tcc", ADSCCompiler.getThumbCC()),
new ProcessorEnumValue("tcpp", ADSCCompiler.getThumbCpp()),
+ new ProcessorEnumValue("hp", HPCompiler.getInstance()),
+ new ProcessorEnumValue("xlc_r", XlcCompiler.getInstance()),
// GCC Cross Compilers
new ProcessorEnumValue(
"sparc-sun-solaris2-gcc",
Index: src/net/sf/antcontrib/cpptasks/LinkerEnum.java
===================================================================
RCS file: /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/LinkerEnum.java,v
retrieving revision 1.16
diff -u -r1.16 LinkerEnum.java
--- src/net/sf/antcontrib/cpptasks/LinkerEnum.java 8 Jul 2004 22:30:53 -0000 1.16
+++ src/net/sf/antcontrib/cpptasks/LinkerEnum.java 29 Apr 2006 02:35:28 -0000
@@ -25,7 +25,9 @@
import net.sf.antcontrib.cpptasks.gcc.GppLinker;
import net.sf.antcontrib.cpptasks.gcc.LdLinker;
import net.sf.antcontrib.cpptasks.hp.aCCLinker;
+import net.sf.antcontrib.cpptasks.hp.HPLinker;
import net.sf.antcontrib.cpptasks.ibm.VisualAgeLinker;
+import net.sf.antcontrib.cpptasks.ibm.XlcLinker;
import net.sf.antcontrib.cpptasks.intel.IntelLinux32Linker;
import net.sf.antcontrib.cpptasks.intel.IntelLinux64Linker;
import net.sf.antcontrib.cpptasks.intel.IntelWin32Linker;
@@ -72,6 +74,8 @@
new ProcessorEnumValue("armcpp", ADSLinker.getInstance()),
new ProcessorEnumValue("tcc", ADSLinker.getInstance()),
new ProcessorEnumValue("tcpp", ADSLinker.getInstance()),
+ new ProcessorEnumValue("hp", HPLinker.getInstance()),
+ new ProcessorEnumValue("xlc_r", XlcLinker.getInstance()),
// gcc cross compilers
new ProcessorEnumValue(
"sparc-sun-solaris2-gcc",
Index: src/net/sf/antcontrib/cpptasks/SubsystemEnum.java
===================================================================
RCS file: /cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/SubsystemEnum.java,v
retrieving revision 1.7
diff -u -r1.7 SubsystemEnum.java
--- src/net/sf/antcontrib/cpptasks/SubsystemEnum.java 28 Feb 2004 20:04:02 -0000 1.7
+++ src/net/sf/antcontrib/cpptasks/SubsystemEnum.java 29 Apr 2006 02:35:28 -0000
@@ -29,6 +29,6 @@
setValue("gui");
}
public String[] getValues() {
- return (String[]) values.clone();
+ return values;
}
}
Index: src/net/sf/antcontrib/cpptasks/gcc/GccLinker.java
===================================================================
RCS file:
/cvsroot/ant-contrib/cpptasks/src/net/sf/antcontrib/cpptasks/gcc/GccLinker.java,v
retrieving revision 1.32
diff -u -r1.32 GccLinker.java
--- src/net/sf/antcontrib/cpptasks/gcc/GccLinker.java 28 Feb 2004
20:01:15 -0000 1.32
+++ src/net/sf/antcontrib/cpptasks/gcc/GccLinker.java 29 Apr 2006
17:27:50 -0000
@@ -35,7 +35,7 @@
private static String[] linkerOptions = new String[]{"-bundle",
"-dynamiclib", "-nostartfiles", "-nostdlib", "-prebind",
"-s",
"-static", "-shared", "-symbolic", "-Xlinker",
- "--export-all-symbols", "-static-libgcc",};
+ "--export-all-symbols", "-static-libgcc", "-arch"};
private static final GccLinker dllLinker = new GccLinker("gcc",
objFiles,
discardFiles, "lib", ".so", false, new GccLinker("gcc",
objFiles,
discardFiles, "lib", ".so", true, null));
--- /dev/null 2006-04-28 19:36:02.000000000 -0700
+++ src/net/sf/antcontrib/cpptasks/hp/HPCompiler.java 2006-04-28 17:08:22.000000000 -0700
@@ -0,0 +1,161 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Ant-Contrib project. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package net.sf.antcontrib.cpptasks.hp;
+
+import java.io.File;
+import java.util.Vector;
+
+import net.sf.antcontrib.cpptasks.CUtil;
+import net.sf.antcontrib.cpptasks.compiler.LinkType;
+import net.sf.antcontrib.cpptasks.compiler.Linker;
+import net.sf.antcontrib.cpptasks.gcc.GccCompatibleCCompiler;
+import org.apache.tools.ant.types.Environment;
+
+/**
+ * Adapter for the HP compiler
+ *
+ * @author Curt Arnold
+ */
+public final class HPCompiler extends GccCompatibleCCompiler {
+
+ private String identifier;
+ private File[] includePath;
+ private static final HPCompiler instance =
+ new HPCompiler("cc", false, null);
+
+ /**
+ * Private constructor. Use GccCCompiler.getInstance() to get
+ * singleton instance of this class.
+ */
+ private HPCompiler(
+ String command,
+ boolean newEnvironment,
+ Environment env) {
+ super(command, "-help", false, null, newEnvironment, env);
+ }
+
+ public int getMaximumCommandLength() {
+ return Integer.MAX_VALUE;
+ }
+
+ /**
+ * Gets singleton instance of this class
+ */
+ public static HPCompiler getInstance() {
+ return instance;
+ }
+
+ public File[] getEnvironmentIncludePath() {
+ if (includePath == null) {
+ File ccLoc = CUtil.getExecutableLocation("cc");
+ if (ccLoc != null) {
+ File compilerIncludeDir =
+ new File(new File(ccLoc, "../include").getAbsolutePath());
+ if (compilerIncludeDir.exists()) {
+ includePath = new File[2];
+ includePath[0] = compilerIncludeDir;
+ }
+ }
+ if (includePath == null) {
+ includePath = new File[1];
+ }
+ includePath[includePath.length - 1] = new File("/usr/include");
+ }
+ return includePath;
+ }
+
+ public void addImpliedArgs(
+ Vector args,
+ boolean debug,
+ boolean multithreaded,
+ boolean exceptions,
+ LinkType linkType) {
+ args.addElement("-c");
+ if (debug) {
+ args.addElement("-g");
+ }
+ /*
+ if (multithreaded) {
+ args.addElement("-mt");
+ }
+ */
+ if (linkType.isSharedLibrary()) {
+ args.addElement("+z");
+ }
+ }
+
+ public void addWarningSwitch(Vector args, int level) {
+ switch (level) {
+ case 0 :
+ args.addElement("-w");
+ break;
+
+ case 1 :
+ case 2 :
+ args.addElement("+w");
+ break;
+ /*
+ case 3:
+ case 4:
+ case 5:
+ args.addElement("+w2");
+ break;
+ */
+ }
+ }
+
+ public Linker getLinker(LinkType linkType) {
+ return HPLinker.getInstance().getLinker(linkType);
+ }
+}
--- /dev/null 2006-04-28 19:36:02.000000000 -0700
+++ src/net/sf/antcontrib/cpptasks/hp/HPLinker.java 2006-04-28 17:08:22.000000000 -0700
@@ -0,0 +1,153 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Ant-Contrib project. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+package net.sf.antcontrib.cpptasks.hp;
+
+import java.io.File;
+import java.util.Vector;
+
+import net.sf.antcontrib.cpptasks.CUtil;
+import net.sf.antcontrib.cpptasks.compiler.LinkType;
+import net.sf.antcontrib.cpptasks.compiler.Linker;
+import net.sf.antcontrib.cpptasks.gcc.AbstractLdLinker;
+
+/**
+ * Adapter for HP linker
+ *
+ * @author Curt Arnold
+ */
+public final class HPLinker extends AbstractLdLinker
+{
+ private static final String[] objFiles = new String[]
+ { ".o", ".a", ".lib", ".dll", ".so", ".sl" };
+ private static final String[] discardFiles = new String[0];
+
+ private static final HPLinker instance =
+ new HPLinker("ld", objFiles, discardFiles, "", "");
+ private static final HPLinker dllLinker =
+ new HPLinker("ld", objFiles, discardFiles, "lib", ".sl");
+ private static final HPLinker arLinker =
+ new HPLinker("ld", objFiles, discardFiles, "", ".a");
+
+ private File[] libDirs;
+
+ private HPLinker(String command, String[] extensions,
+ String[] ignoredExtensions, String outputPrefix,
+ String outputSuffix) {
+ super(command, "-help", extensions, ignoredExtensions,
+ outputPrefix, outputSuffix,false,null);
+ }
+
+ public static HPLinker getInstance() {
+ return instance;
+ }
+
+ /**
+ * Returns library path.
+ *
+ */
+ public File[] getLibraryPath() {
+ if(libDirs == null) {
+ File CCloc = CUtil.getExecutableLocation("ld");
+ if(CCloc != null) {
+ File compilerLib = new File(
+ new File(CCloc, "../lib").getAbsolutePath());
+ if (compilerLib.exists()) {
+ libDirs = new File[2];
+ libDirs[0] = compilerLib;
+ }
+ }
+ if (libDirs == null) {
+ libDirs = new File[1];
+ }
+ }
+ libDirs[libDirs.length-1] = new File("/usr/lib");
+ return libDirs;
+ }
+
+ public void addImpliedArgs(boolean debug, LinkType linkType, Vector args) {
+/* if(linkType.isStaticRuntime()) {
+ args.addElement("-static");
+ }
+*/
+ if(linkType.isSharedLibrary()) {
+ args.addElement("-b");
+ }
+/*
+ if (linkType.isStaticLibrary()) {
+ args.addElement("-Wl,-noshared");
+ }
+*/
+ }
+
+
+ public Linker getLinker(LinkType type) {
+ if(type.isStaticLibrary()) {
+ return arLinker;
+ }
+ if(type.isSharedLibrary()) {
+ return dllLinker;
+ }
+ return instance;
+ }
+
+ public void addIncremental(boolean incremental, Vector args) {
+ /*
+ if (incremental) {
+ args.addElement("-xidlon");
+ } else {
+ args.addElement("-xidloff");
+ }
+ */
+ }
+}
--- /dev/null 2006-04-28 19:36:02.000000000 -0700
+++ src/net/sf/antcontrib/cpptasks/ibm/XlcCompiler.java 2006-04-28 17:08:22.000000000 -0700
@@ -0,0 +1,138 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Ant-Contrib project. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Ant-Contrib project (http://sourceforge.net/projects/ant-contrib)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "Ant-Contrib"
+ * must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Ant-Contrib"
+ * nor may "Ant-Contrib" appear in their names without prior written
+ * permission of the Ant-Contrib project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE ANT-CONTRIB PROJECT OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ */
+package net.sf.antcontrib.cpptasks.ibm;
+
+import java.io.File;
+import java.util.Vector;
+
+import net.sf.antcontrib.cpptasks.compiler.LinkType;
+import net.sf.antcontrib.cpptasks.compiler.Linker;
+import net.sf.antcontrib.cpptasks.gcc.GccCompatibleCCompiler;
+import org.apache.tools.ant.types.Environment;
+
+
+/**
+ * Adapter for the IBM(r) Visual Age(tm) C++ compiler for AIX(tm)
+ *
+ * @author Curt Arnold
+ */
+public final class XlcCompiler extends GccCompatibleCCompiler {
+ private String identifier;
+ private File[] includePath;
+ private static final XlcCompiler instance =
+ new XlcCompiler("xlc_r", false, null);
+
+ /**
+ * Private constructor. Use getInstance() to get
+ * singleton instance of this class.
+ */
+ private XlcCompiler(String command, boolean newEnvironment, Environment env) {
+ super(command, "-help", false, null, newEnvironment, env);
+ }
+
+ public int getMaximumCommandLength() {
+ return Integer.MAX_VALUE;
+ }
+
+ /**
+ * Gets singleton instance of this class
+ */
+ public static XlcCompiler getInstance() {
+ return instance;
+ }
+
+ public void addImpliedArgs(
+ Vector args,
+ boolean debug,
+ boolean multithreaded,
+ boolean exceptions,
+ LinkType linkType) {
+ args.addElement("-c");
+ if (debug) {
+ args.addElement("-g");
+ }
+ if (linkType.isSharedLibrary()) {
+ args.addElement("-fpic");
+ args.addElement("-qmkshrobj");
+
+ }
+ }
+
+ public void addWarningSwitch(Vector args, int level) {
+ switch (level) {
+ case 0 :
+ args.addElement("-w");
+ break;
+
+ case 1 :
+ args.addElement("-qflag=s:s");
+ break;
+
+ case 2 :
+ args.addElement("-qflag=e:e");
+ break;
+
+ case 3 :
+ args.addElement("-qflag=w:w");
+ break;
+
+ case 4 :
+ args.addElement("-qflag=i:i");
+ break;
+
+ case 5 :
+ args.addElement("-qhalt=w:w");
+ break;
+ }
+ }
+
+ public Linker getLinker(LinkType linkType) {
+ return VisualAgeLinker.getInstance().getLinker(linkType);
+ }
+}
--- /dev/null 2006-04-28 19:36:02.000000000 -0700
+++ src/net/sf/antcontrib/cpptasks/ibm/XlcLinker.java 2006-04-28 17:08:22.000000000 -0700
@@ -0,0 +1,112 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Ant-Contrib project. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Ant-Contrib project (http://sourceforge.net/projects/ant-contrib)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "Ant-Contrib"
+ * must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Ant-Contrib"
+ * nor may "Ant-Contrib" appear in their names without prior written
+ * permission of the Ant-Contrib project.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE ANT-CONTRIB PROJECT OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ */
+package net.sf.antcontrib.cpptasks.ibm;
+
+import java.util.Vector;
+
+import net.sf.antcontrib.cpptasks.compiler.LinkType;
+import net.sf.antcontrib.cpptasks.compiler.Linker;
+import net.sf.antcontrib.cpptasks.gcc.AbstractLdLinker;
+import net.sf.antcontrib.cpptasks.gcc.GccLibrarian;
+
+/**
+ * Adapter for IBM(r) Visual Age(tm) Linker for AIX(tm)
+ *
+ * @author Curt Arnold
+ */
+public final class XlcLinker extends AbstractLdLinker
+{
+ private static final String[] objFiles = new String[]
+ { ".o", ".a", ".lib",".dll", ".so", ".sl"};
+ private static final String[] discardFiles = new String[]
+ { };
+
+ private static final XlcLinker instance =
+ new XlcLinker("ld", objFiles, discardFiles, "", "");
+ private static final XlcLinker dllLinker =
+ new XlcLinker("ld", objFiles, discardFiles, "lib", ".so");
+
+ private XlcLinker(String command, String[] extensions,
+ String[] ignoredExtensions, String outputPrefix,
+ String outputSuffix) {
+ //
+ // just guessing that -? might display something useful
+ //
+ super(command, "-?", extensions, ignoredExtensions,
+ outputPrefix, outputSuffix,false,null);
+ }
+
+ public static XlcLinker getInstance() {
+ return instance;
+ }
+
+ public void addImpliedArgs(boolean debug, LinkType linkType, Vector args) {
+ if(debug) {
+ //args.addElement("-g");
+ }
+ if(linkType.isSharedLibrary()) {
+ args.addElement("-bdynamic");
+ args.addElement("-G");
+ args.addElement("-bnoentry");
+ args.addElement("-bexpall");
+ args.addElement("-lc_r");
+ }
+ }
+
+
+ public Linker getLinker(LinkType type) {
+ if(type.isStaticLibrary()) {
+ return GccLibrarian.getInstance();
+ }
+ if(type.isSharedLibrary()) {
+ return dllLinker;
+ }
+ return instance;
+ }
+}

View File

@ -0,0 +1,442 @@
/*
* Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
* This file is part of SIGAR.
*
* SIGAR is free software; you can redistribute it and/or modify
* it under the terms version 2 of the GNU General Public License as
* published by the Free Software Foundation. This program is distributed
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*/
package org.hyperic.jni;
import java.io.File;
import java.util.StringTokenizer;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
public class ArchLoader {
private Object loadLock = new Object();
private boolean loaded = false;
private final static String osName = System.getProperty("os.name");
public final static boolean IS_WIN32 = osName.startsWith("Windows");
public final static boolean IS_AIX = osName.equals("AIX");
public final static boolean IS_HPUX = osName.equals("HP-UX");
public final static boolean IS_SOLARIS = osName.equals("SunOS");
public final static boolean IS_LINUX = osName.equals("Linux");
public final static boolean IS_DARWIN = osName.equals("Mac OS X") || osName.equals("Darwin");
public final static boolean IS_OSF1 = osName.equals("OSF1");
public final static boolean IS_FREEBSD = osName.equals("FreeBSD");
public final static boolean IS_NETWARE = osName.equals("NetWare");
private String packageName;
private String name;
private String resourcePath;
private Class loaderClass;
private String jarName;
private String libName = null;
private File nativeLibrary;
private String version;
public ArchLoader() { }
public ArchLoader(Class loaderClass) {
setLoaderClass(loaderClass); //e.g. Sigar.class
//argh. possible for loaderClass.getPackage()
//to return null depending on ClassLoader
String pname = loaderClass.getName();
int ix = pname.lastIndexOf(".");
pname = pname.substring(0, ix);
setPackageName(pname); //e.g. org.hyperic.sigar
ix = pname.lastIndexOf(".");
setName(pname.substring(ix+1)); //e.g. sigar
setJarName(getName() + ".jar");
setResourcePath(toResName(pname)); //e.g. org.hyperic/sigar
}
public Class getLoaderClass() {
return this.loaderClass;
}
public void setLoaderClass(Class value) {
this.loaderClass = value;
}
public ClassLoader getClassLoader() {
return getLoaderClass().getClassLoader();
}
public String getName() {
return this.name;
}
public void setName(String value) {
this.name = value;
}
public String getPackageName() {
return this.packageName;
}
public void setPackageName(String value) {
this.packageName = value;
}
public String getResourcePath() {
return this.resourcePath;
}
public void setResourcePath(String value) {
this.resourcePath = value;
}
public String getJarName() {
return this.jarName;
}
public void setJarName(String value) {
this.jarName = value;
}
public String getLibName() {
return this.libName;
}
public void setLibName(String value) {
this.libName = value;
}
public String getArchLibName()
throws ArchNotSupportedException {
return getName() + "-" + ArchName.getName();
}
public String getDefaultLibName()
throws ArchNotSupportedException {
return
System.getProperty(getPackageName() + ".libname",
//e.g. javasigar-x86-linux
"java" + getArchLibName());
}
public File getNativeLibrary() {
return this.nativeLibrary;
}
private String toResName(String name) {
StringBuffer sb = new StringBuffer(name);
for (int i=0; i < sb.length(); i++) {
if (sb.charAt(i) == '.') {
sb.setCharAt(i, '/');
}
}
return sb.toString();
}
public static String getLibraryPrefix() {
if (IS_WIN32 || IS_NETWARE) {
return "";
}
return "lib";
}
public static String getLibraryExtension() {
if (IS_WIN32) {
return ".dll";
}
if (IS_NETWARE) {
return ".nlm";
}
if (IS_DARWIN) {
return ".dylib";
}
if (IS_HPUX) {
return ".sl";
}
return ".so";
}
public String getLibraryName()
throws ArchNotSupportedException {
String libName;
if ((libName = getLibName()) == null) {
libName = getDefaultLibName();
setLibName(libName);
}
String prefix = getLibraryPrefix();
String ext = getLibraryExtension();
return prefix + libName + ext;
}
public String getVersionedLibraryName() {
if (this.version == null) {
return null;
}
try {
getLibraryName();
} catch (ArchNotSupportedException e) {
return null;
}
String prefix = getLibraryPrefix();
String ext = getLibraryExtension();
return prefix + this.libName + '-' + this.version + ext;
}
private boolean isJarURL(URL url) {
if (url == null) {
return false;
}
String name = url.getFile();
String jarName = getJarName();
if (name.indexOf(jarName) != -1) {
return true;
}
int ix = jarName.indexOf(".jar");
if (ix != -1) {
//check for a versioned name-x.x.jar
jarName = jarName.substring(0, ix) + "-";
//lastIndex else could match "sigar-bin/"
ix = name.lastIndexOf(jarName);
if (ix != -1) {
jarName = name.substring(ix);
ix = jarName.indexOf(".jar");
if (ix == -1) {
return false;
}
this.version =
jarName.substring(jarName.indexOf('-')+1, ix);
jarName = jarName.substring(0, ix+4);
setJarName(jarName); //for future reference
return true;
}
else {
return false;
}
}
else {
return false;
}
}
public String findJarPath(String libName)
throws ArchLoaderException {
/*
* native libraries should be installed along side
* ${this.name}.jar, try to find where ${this.name}.jar
* is on disk and use that path.
*/
if (getJarName() == null) {
throw new ArchLoaderException("jarName is null");
}
String path = getResourcePath();
ClassLoader loader = getClassLoader();
URL url = loader.getResource(path);
if (!isJarURL(url)) {
url = null;
}
if ((url == null) && (loader instanceof URLClassLoader)) {
URL[] urls = ((URLClassLoader)loader).getURLs();
for (int i=0; i<urls.length; i++) {
if (isJarURL(urls[i])) {
url = urls[i];
break;
}
}
}
if (url == null) {
throw new ArchLoaderException("Unable to find " +
getJarName());
}
path = url.getFile();
if (path.startsWith("file:")) {
path = path.substring(5);
}
File file = new File(path);
String jarName = getJarName();
while ((file != null) &&
!file.getName().startsWith(jarName))
{
file = file.getParentFile();
}
if (libName == null) {
//return path containing ${this.name}.jar
//which may or may not be -x.x.x.x versioned
libName = jarName;
}
if ((file != null) &&
((file = file.getParentFile()) != null))
{
String dir = URLDecoder.decode(file.toString());
if (findNativeLibrary(dir, libName)) {
return dir;
}
}
return null;
}
//java.lang.ClassLoader does not delegate native linking
//to the parent ClassLoader.
//overriding these methods provides a workaround.
protected void systemLoadLibrary(String name) {
System.loadLibrary(name);
}
protected void systemLoad(String name) {
System.load(name);
}
protected boolean containsNativeLibrary(File dir, String name) {
if (name == null) {
return false;
}
File file = new File(dir, name);
if (file.exists()) {
this.nativeLibrary = file;
return true;
}
return false;
}
protected boolean findNativeLibrary(String dir, String name) {
//must be an absolute path; this allows relative to $PWD
File path = new File(dir).getAbsoluteFile();
if (containsNativeLibrary(path, name)) {
return true;
}
else if (containsNativeLibrary(path, getVersionedLibraryName())) {
return true;
}
//try w/o arch name (e.g. "libsigar.so")
return containsNativeLibrary(path,
getLibraryPrefix() +
getName() +
getLibraryExtension());
}
protected boolean findInJavaLibraryPath(String libName) {
String path = System.getProperty("java.library.path", "");
StringTokenizer tok =
new StringTokenizer(path, File.pathSeparator);
while (tok.hasMoreTokens()) {
path = tok.nextToken();
if (findNativeLibrary(path, libName)) {
return true;
}
}
return false;
}
protected void loadLibrary(String path)
throws ArchNotSupportedException,
ArchLoaderException {
try {
String libName = getLibraryName();
if (path == null) {
//e.g. org.hyperic.sigar.path
path = System.getProperty(getPackageName() + ".path");
}
if (path != null) {
if (path.equals("-")) {
return; //assume library is already loaded
}
findJarPath(null); //check for versioned .jar
findNativeLibrary(path, libName);
}
else {
if (findJarPath(libName) == null) {
findInJavaLibraryPath(libName);
}
}
//nativeLibrary set when findJarPath() calls findNativeLibrary()
if (this.nativeLibrary != null) {
systemLoad(this.nativeLibrary.toString());
}
else {
//LD_LIBRARY_PATH must be set for linux and solaris
//SHLIB_PATH must be set for hpux
//PATH must be set for windows
systemLoadLibrary(libName);
}
} catch (RuntimeException e) {
String reason = e.getMessage();
if (reason == null) {
reason = e.getClass().getName();
}
String msg =
"Failed to load " + libName +
": " + reason;
throw new ArchLoaderException(msg);
}
}
public void load()
throws ArchNotSupportedException,
ArchLoaderException {
load(null);
}
public void load(String path)
throws ArchNotSupportedException,
ArchLoaderException {
/*
* System.loadLibrary() is only supposed to load the library
* once per-classloader. but we make extra sure that is the case.
*/
synchronized (this.loadLock) {
if (this.loaded) {
return;
}
loadLibrary(path);
this.loaded = true;
}
}
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
* This file is part of SIGAR.
*
* SIGAR is free software; you can redistribute it and/or modify
* it under the terms version 2 of the GNU General Public License as
* published by the Free Software Foundation. This program is distributed
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*/
package org.hyperic.jni;
public class ArchLoaderException extends Exception {
public ArchLoaderException() {
super();
}
public ArchLoaderException(String msg) {
super(msg);
}
}

View File

@ -0,0 +1,115 @@
/*
* Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
* This file is part of SIGAR.
*
* SIGAR is free software; you can redistribute it and/or modify
* it under the terms version 2 of the GNU General Public License as
* published by the Free Software Foundation. This program is distributed
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*/
package org.hyperic.jni;
/**
* Helper class for naming the jni library with
* platform/arch name for which it is binary compatible.
*/
public class ArchName {
static boolean useDmalloc =
System.getProperty("jni.dmalloc") != null;
public static String getName() throws ArchNotSupportedException {
String name = getArchName();
if (useDmalloc) {
name += "-dmalloc";
}
return name;
}
public static boolean is64() {
return "64".equals(System.getProperty("sun.arch.data.model"));
}
private static String getArchName() throws ArchNotSupportedException {
String name = System.getProperty("os.name");
String arch = System.getProperty("os.arch");
String version = System.getProperty("os.version");
String majorVersion = version.substring(0, 1); //4.x, 5.x, etc.
if (arch.endsWith("86")) {
arch = "x86";
}
if (name.equals("Linux")) {
return arch + "-linux";
}
else if (name.indexOf("Windows") > -1) {
return arch + "-winnt";
}
else if (name.equals("SunOS")) {
if (arch.startsWith("sparcv") && is64()) {
arch = "sparc64";
}
return arch + "-solaris";
}
else if (name.equals("HP-UX")) {
if (arch.startsWith("IA64")) {
arch = "ia64";
}
else {
arch = "pa";
}
if (version.indexOf("11") > -1) {
return arch + "-hpux-11";
}
}
else if (name.equals("AIX")) {
if (majorVersion.equals("6")) {
//v5 binary is compatible with v6
majorVersion = "5";
}
//arch == "ppc" on 32-bit, "ppc64" on 64-bit
return arch + "-aix-" + majorVersion;
}
else if (name.equals("Mac OS X") || name.equals("Darwin")) {
if (is64()) {
return "universal64-macosx";
}
else {
return "universal-macosx";
}
}
else if (name.equals("FreeBSD")) {
//none of the 4,5,6 major versions are binary compatible
return arch + "-freebsd-" + majorVersion;
}
else if (name.equals("OpenBSD")) {
return arch + "-openbsd-" + majorVersion;
}
else if (name.equals("NetBSD")) {
return arch + "-netbsd-" + majorVersion;
}
else if (name.equals("OSF1")) {
return "alpha-osf1-" + majorVersion;
}
else if (name.equals("NetWare")) {
return "x86-netware-" + majorVersion;
}
String desc = arch + "-" + name + "-" + version;
throw new ArchNotSupportedException("platform (" + desc + ") not supported");
}
private ArchName () { }
}

View File

@ -0,0 +1,76 @@
/*
* Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
* This file is part of SIGAR.
*
* SIGAR is free software; you can redistribute it and/or modify
* it under the terms version 2 of the GNU General Public License as
* published by the Free Software Foundation. This program is distributed
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*/
package org.hyperic.jni;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;
public class ArchNameTask extends Task {
public void execute() throws BuildException {
String osArch = System.getProperty("os.arch");
if (getProject().getProperty("jni.dmalloc") != null) {
ArchName.useDmalloc = true;
}
String archName;
try {
archName = ArchName.getName();
} catch (ArchNotSupportedException e) {
//ok: can still compile *.java
System.out.println(e.getMessage());
return;
}
System.out.println(archName);
getProject().setProperty("jni.libarch", archName);
getProject().setProperty("jni.libpre",
ArchLoader.getLibraryPrefix());
getProject().setProperty("jni.libext",
ArchLoader.getLibraryExtension());
String compiler;
if (ArchLoader.IS_WIN32) {
compiler = "msvc";
}
else if (ArchLoader.IS_HPUX) {
compiler = "hp";
}
else if (ArchLoader.IS_AIX) {
compiler = "xlc_r";
}
else {
compiler = "gcc";
getProject().setProperty("jni.compiler.isgcc", "true");
}
getProject().setProperty("jni.compiler", compiler);
if (ArchName.is64()) {
getProject().setProperty("jni.arch64", "true");
if (ArchLoader.IS_LINUX) {
if (!osArch.equals("ia64")) {
getProject().setProperty("jni.usem64", "true");
}
}
}
}
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
* This file is part of SIGAR.
*
* SIGAR is free software; you can redistribute it and/or modify
* it under the terms version 2 of the GNU General Public License as
* published by the Free Software Foundation. This program is distributed
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*/
package org.hyperic.jni;
public class ArchNotSupportedException extends Exception {
public ArchNotSupportedException() {
super();
}
public ArchNotSupportedException(String msg) {
super(msg);
}
}

View File

@ -0,0 +1,69 @@
/*
* Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
* This file is part of SIGAR.
*
* SIGAR is free software; you can redistribute it and/or modify
* it under the terms version 2 of the GNU General Public License as
* published by the Free Software Foundation. This program is distributed
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*/
package org.hyperic.jni;
import java.io.File;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Copy;
public class CopyDependsTask extends Copy {
private File depends;
protected void validateAttributes()
throws BuildException {
super.validateAttributes();
if (this.depends == null) {
throw new BuildException("missing depends attribute");
}
}
public void execute()
throws BuildException {
if (this.destFile.exists()) {
String state;
if (this.depends.lastModified() >
this.destFile.lastModified())
{
this.setOverwrite(true);
state = "out of date";
}
else {
state = "up to date";
}
log(this.destFile +
" " + state + " with " +
this.depends);
}
super.execute();
}
public File getDepends() {
return this.depends;
}
public void setDepends(String depends) {
this.depends = new File(depends);
}
}