Skip to content

Commit

Permalink
Add support for linux-armhf and linux-ppc64le to system APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
saudet committed Dec 4, 2017
1 parent ae5ea55 commit afc6150
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 30 deletions.
2 changes: 1 addition & 1 deletion systems/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This directory contains the JavaCPP Presets module for system APIs:
* Mac OS X (XNU libc) https://opensource.apple.com/
* Windows (Win32) https://developer.microsoft.com/en-us/windows/

For now, only small portions of the APIs are actually supported. The range will be expanded based on demand, so please make sure to communicate your needs.
For now, basic functionality is supported. The range will be expanded based on demand, so please make sure to communicate your needs.

Please refer to the parent README.md file for more detailed information about the JavaCPP Presets.

Expand Down
44 changes: 30 additions & 14 deletions systems/cppbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,41 @@ if [[ -z "$PLATFORM" ]]; then
exit
fi

mkdir -p $PLATFORM/include
cd $PLATFORM/include
mkdir -p $PLATFORM
cd $PLATFORM

INCLUDE_PATH="/usr/include/"
if [[ ! -d "$INCLUDE_PATH" ]]; then
echo "Please install system development files under the default installation directory"
exit 1
fi

case $PLATFORM in
linux-x86*)
if [[ ! -d "/usr/include/" ]]; then
echo "Please install system development files under the default installation directory"
exit 1
linux-armhf)
CROSS_INCLUDE_PATH=$(echo | arm-linux-gnueabihf-g++ -E -v - 2>&1 | grep -o ' .*/usr/include' | tail -1 | xargs)
if [[ -d "$CROSS_INCLUDE_PATH" ]]; then
INCLUDE_PATH="$CROSS_INCLUDE_PATH"
fi
CPUID_PATH=$(echo '#include <cpuid.h>' | g++ -M -E - | grep -o ' .*cpuid.h')
ln -sf $CPUID_PATH
touch cpuid.h
ln -sf "$INCLUDE_PATH"
ln -sf "$INCLUDE_PATH/arm-linux-gnueabihf"
;;
linux-ppc64le)
touch cpuid.h
ln -sf "$INCLUDE_PATH"
ln -sf "$INCLUDE_PATH/powerpc64le-linux-gnu"
;;
linux-x86*)
CPUID_PATH=$(echo '#include <cpuid.h>' | g++ -M -E - | grep -o ' .*cpuid.h' | xargs)
ln -sf "$CPUID_PATH"
ln -sf "$INCLUDE_PATH"
ln -sf "$INCLUDE_PATH/i386-linux-gnu"
ln -sf "$INCLUDE_PATH/x86_64-linux-gnu"
;;
macosx-*)
if [[ ! -d "/usr/include/" ]]; then
echo "Please install system development files under the default installation directory"
exit 1
fi
CPUID_PATH=$(echo '#include <cpuid.h>' | clang++ -M -E - | grep -o ' .*cpuid.h')
ln -sf $CPUID_PATH
CPUID_PATH=$(echo '#include <cpuid.h>' | clang++ -M -E - | grep -o ' .*cpuid.h' | xargs)
ln -sf "$CPUID_PATH"
ln -sf "$INCLUDE_PATH"
;;
windows-*)
if [[ ! -d "/C/Program Files (x86)/Windows Kits/" ]]; then
Expand Down
14 changes: 13 additions & 1 deletion systems/platform/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@
<version>${project.version}</version>
<classifier>${javacpp.platform.linux-x86_64}</classifier>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${javacpp.moduleId}</artifactId>
<version>${project.version}</version>
<classifier>${javacpp.platform.linux-armhf}</classifier>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${javacpp.moduleId}</artifactId>
<version>${project.version}</version>
<classifier>${javacpp.platform.linux-ppc64le}</classifier>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${javacpp.moduleId}</artifactId>
Expand Down Expand Up @@ -67,7 +79,7 @@
<configuration>
<archive>
<manifestEntries>
<Class-Path>${javacpp.moduleId}.jar ${javacpp.moduleId}-linux-x86.jar ${javacpp.moduleId}-linux-x86_64.jar ${javacpp.moduleId}-macosx-x86_64.jar ${javacpp.moduleId}-windows-x86.jar ${javacpp.moduleId}-windows-x86_64.jar</Class-Path>
<Class-Path>${javacpp.moduleId}.jar ${javacpp.moduleId}-linux-x86.jar ${javacpp.moduleId}-linux-x86_64.jar ${javacpp.moduleId}-linux-armhf.jar ${javacpp.moduleId}-linux-ppc64le.jar ${javacpp.moduleId}-macosx-x86_64.jar ${javacpp.moduleId}-windows-x86.jar ${javacpp.moduleId}-windows-x86_64.jar</Class-Path>
</manifestEntries>
</archive>
</configuration>
Expand Down
9 changes: 9 additions & 0 deletions systems/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@
<value>${javacpp.platform.oldcompiler}</value>
</property>
</propertyKeysAndValues>
<includePaths>
<includePath>${basedir}/cppbuild/${javacpp.platform}/</includePath>
<includePath>${basedir}/cppbuild/${javacpp.platform}/include/</includePath>
<includePath>${basedir}/cppbuild/${javacpp.platform}/arm-linux-gnueabihf/</includePath>
<includePath>${basedir}/cppbuild/${javacpp.platform}/powerpc64le-linux-gnu/</includePath>
<includePath>${basedir}/cppbuild/${javacpp.platform}/i386-linux-gnu/</includePath>
<includePath>${basedir}/cppbuild/${javacpp.platform}/x86_64-linux-gnu/</includePath>
<includePath>${basedir}/target/classes/org/bytedeco/javacpp/include/</includePath>
</includePaths>
</configuration>
<executions>
<execution>
Expand Down
114 changes: 112 additions & 2 deletions systems/src/main/java/org/bytedeco/javacpp/linux.java
Original file line number Diff line number Diff line change
Expand Up @@ -7846,6 +7846,74 @@ public static native int sigaltstack(@Const stack_t __ss,
// #endif /* not signal.h */


// Parsed from asm/ptrace.h

// #ifndef _ASM_X86_PTRACE_H
// #define _ASM_X86_PTRACE_H

/* For */
// #include <asm/ptrace-abi.h>
// #include <asm/processor-faLgs.h>


// #ifndef __ASSEMBLY__

// #ifdef __i386__


// #else /* __i386__ */


public static class pt_regs extends Pointer {
static { Loader.load(); }
/** Default native constructor. */
public pt_regs() { super((Pointer)null); allocate(); }
/** Native array allocator. Access with {@link Pointer#position(long)}. */
public pt_regs(long size) { super((Pointer)null); allocateArray(size); }
/** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
public pt_regs(Pointer p) { super(p); }
private native void allocate();
private native void allocateArray(long size);
@Override public pt_regs position(long position) {
return (pt_regs)super.position(position);
}

public native @Cast("unsigned long") long r15(); public native pt_regs r15(long r15);
public native @Cast("unsigned long") long r14(); public native pt_regs r14(long r14);
public native @Cast("unsigned long") long r13(); public native pt_regs r13(long r13);
public native @Cast("unsigned long") long r12(); public native pt_regs r12(long r12);
public native @Cast("unsigned long") long rbp(); public native pt_regs rbp(long rbp);
public native @Cast("unsigned long") long rbx(); public native pt_regs rbx(long rbx);
/* arguments: non interrupts/non tracing syscalls only save upto here*/
public native @Cast("unsigned long") long r11(); public native pt_regs r11(long r11);
public native @Cast("unsigned long") long r10(); public native pt_regs r10(long r10);
public native @Cast("unsigned long") long r9(); public native pt_regs r9(long r9);
public native @Cast("unsigned long") long r8(); public native pt_regs r8(long r8);
public native @Cast("unsigned long") long rax(); public native pt_regs rax(long rax);
public native @Cast("unsigned long") long rcx(); public native pt_regs rcx(long rcx);
public native @Cast("unsigned long") long rdx(); public native pt_regs rdx(long rdx);
public native @Cast("unsigned long") long rsi(); public native pt_regs rsi(long rsi);
public native @Cast("unsigned long") long rdi(); public native pt_regs rdi(long rdi);
public native @Cast("unsigned long") long orig_rax(); public native pt_regs orig_rax(long orig_rax);
/* end of arguments */
/* cpu exception frame or undefined */
public native @Cast("unsigned long") long rip(); public native pt_regs rip(long rip);
public native @Cast("unsigned long") long cs(); public native pt_regs cs(long cs);
public native @Cast("unsigned long") long eflags(); public native pt_regs eflags(long eflags);
public native @Cast("unsigned long") long rsp(); public native pt_regs rsp(long rsp);
public native @Cast("unsigned long") long ss(); public native pt_regs ss(long ss);
/* top of stack page */
}

// #endif /* !__i386__ */



// #endif /* !__ASSEMBLY__ */

// #endif /* _ASM_X86_PTRACE_H */


// Parsed from sys/ucontext.h

/* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
Expand Down Expand Up @@ -8025,9 +8093,9 @@ public static class mcontext_t extends Pointer {
return (mcontext_t)super.position(position);
}

@MemberGetter public native @Cast("const greg_t*") LongPointer gregs();
@MemberGetter public native @Const LongPointer gregs();
/* Note that fpregs is a pointer. */
public native _libc_fpstate fpregs(); public native mcontext_t fpregs(_libc_fpstate fpregs);
@MemberGetter public native @Const Pointer fpregs();
public native @Cast("unsigned long") long __reserved1(int i); public native mcontext_t __reserved1(int i, long __reserved1);
@MemberGetter public native @Cast("unsigned long*") CLongPointer __reserved1();
}
Expand Down Expand Up @@ -11370,6 +11438,48 @@ public static native int sysctl(@Cast("int*") int[] __name, int __nlen, Pointer
// #endif /* _SYS_SYSCTL_H */


// Parsed from bits/waitflags.h

/* Definitions of flag bits for `waitpid' et al.
Copyright (C) 1992,1996,1997,2000,2004,2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.

The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

The GNU C Library 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
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */

// #if !defined _SYS_WAIT_H && !defined _STDLIB_H
// # error "Never include <bits/waitflags.h> directly; use <sys/wait.h> instead."
// #endif


/* Bits in the third argument to `waitpid'. */
public static final int WNOHANG = 1; /* Don't block waiting. */
public static final int WUNTRACED = 2; /* Report status of stopped children. */

/* Bits in the fourth argument to `waitid'. */
public static final int WSTOPPED = 2; /* Report stopped child (same as WUNTRACED). */
public static final int WEXITED = 4; /* Report dead child. */
public static final int WCONTINUED = 8; /* Report continued child. */
public static final int WNOWAIT = 0x01000000; /* Don't reap, just poll status. */

public static final int __WNOTHREAD = 0x20000000; /* Don't wait on children of other threads
in this group */
public static final int __WALL = 0x40000000; /* Wait for any child. */
public static final int __WCLONE = 0x80000000; /* Wait for cloned process. */


// Parsed from sys/wait.h

/* Copyright (C) 1991-1994,1996-2001,2003,2004,2005,2007,2009,2010
Expand Down
22 changes: 12 additions & 10 deletions systems/src/main/java/org/bytedeco/javacpp/presets/linux.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@
*
* @author Samuel Audet
*/
@Properties(value = {@Platform(value = "linux-x86",
@Properties(value = {@Platform(value = "linux",
exclude = {"bits/locale.h", "bits/socket.h", "bits/siginfo.h", "bits/sigaction.h", "bits/sigcontext.h", "bits/sigstack.h",
"bits/sched.h", "bits/confname.h", "bits/resource.h"},
include = {"cpuid.h", "dlfcn.h", "nl_types.h", "xlocale.h", "bits/locale.h", "langinfo.h", "locale.h",
"bits/uio.h", "sys/uio.h", "bits/sockaddr.h", "bits/socket.h", "sys/socket.h", /*"sys/types.h", "bits/timex.h",*/
"asm-generic/errno-base.h", "asm-generic/errno.h", "bits/errno.h", "errno.h", "string.h", "stdlib.h",
"bits/time.h", "sys/time.h", "time.h", "utime.h", "bits/stat.h", "sys/stat.h", "fcntl.h", "sys/file.h", "grp.h", "pwd.h",
"bits/siginfo.h", "bits/sigset.h", "bits/sigaction.h", "bits/sigcontext.h", "bits/sigstack.h", "signal.h",
"bits/siginfo.h", "bits/sigset.h", "bits/sigaction.h", "bits/sigcontext.h", "bits/sigstack.h", "signal.h", "asm/ptrace.h",
"sys/ucontext.h", "ucontext.h", "bits/sched.h", "sched.h", "spawn.h", "bits/posix_opt.h", "bits/confname.h", "unistd.h",
"sys/poll.h", "sys/reboot.h", "bits/resource.h", "sys/resource.h", "sys/sysctl.h", "sys/wait.h"},
includepath = "/usr/include", link = "dl")}, target = "org.bytedeco.javacpp.linux")
"sys/poll.h", "sys/reboot.h", "bits/resource.h", "sys/resource.h", "sys/sysctl.h", "bits/waitflags.h", "sys/wait.h"},
link = "dl")}, target = "org.bytedeco.javacpp.linux")
public class linux implements BuildEnabled, InfoMapper {

private Logger logger;
Expand All @@ -62,7 +62,7 @@ public void init(Logger logger, java.util.Properties properties, String encoding
this.logger = logger;
this.properties = properties;
this.encoding = encoding;
this.is64bits = properties.getProperty("platform").endsWith("64");
this.is64bits = properties.getProperty("platform").contains("64");
}

public void map(InfoMap infoMap) {
Expand All @@ -71,19 +71,21 @@ public void map(InfoMap infoMap) {
.put(new Info("siginfo.h").linePatterns("# define si_.*").skip())
.put(new Info("sigaction.h").linePatterns("# define sa_.*").skip())
.put(new Info("signal.h").linePatterns("#ifndef\t_SIGNAL_H", "#endif").skip())
.put(new Info("ptrace.h").linePatterns("#define .*regs\\[.*").skip())
.put(new Info("sysinfo.h").linePatterns(".*char _f.*").skip())

.put(new Info("__BEGIN_DECLS").cppText("#define __BEGIN_DECLS"))
.put(new Info("__END_DECLS").cppText("#define __END_DECLS"))
.put(new Info("__NTH").cppText("#define __NTH(a) a"))
.put(new Info("__BEGIN_NAMESPACE_C99").cppText("#define __BEGIN_NAMESPACE_C99"))
.put(new Info("__END_NAMESPACE_C99").cppText("#define __END_NAMESPACE_C99"))
.put(new Info("__USING_NAMESPACE_C99").cppText("#define __USING_NAMESPACE_C99(name)"))
.put(new Info("__BEGIN_NAMESPACE_STD").cppText("#define __BEGIN_NAMESPACE_STD"))
.put(new Info("__END_NAMESPACE_STD").cppText("#define __END_NAMESPACE_STD"))
.put(new Info("__USING_NAMESPACE_STD").cppText("#define __USING_NAMESPACE_STD(name)"))

.put(new Info("__WORDSIZE == 32").define(!is64bits))
.put(new Info("__x86_64__", "__WORDSIZE == 64").define(is64bits))
.put(new Info("__WORDSIZE == 32", "__i386__").define(!is64bits))
.put(new Info("__WORDSIZE == 64", "__aarch64__", "__powerpc64__", "__x86_64__").define(is64bits))

.put(new Info("defined __cplusplus || !__GNUC_PREREQ (2, 7) || !defined __USE_GNU",
"__WORDSIZE == 64 || !defined __USE_FILE_OFFSET64",
Expand Down Expand Up @@ -123,12 +125,13 @@ public void map(InfoMap infoMap) {
"__syscall_slong_t", "__syscall_ulong_t", "__CPU_MASK_TYPE", "__kernel_long_t", "__kernel_ulong_t")
.cast().valueTypes("long").pointerTypes("SizeTPointer"))

.put(new Info("off64_t", "rlim64_t", "__off64_t", "__rlim64_t", "__blkcnt64_t", "greg_t", "__ino64_t", "__uint64_t")
.put(new Info("off64_t", "rlim64_t", "__off64_t", "__rlim64_t", "__blkcnt64_t", "greg_t", "__ino64_t", "__u64", "__uint64_t")
.cast().valueTypes("long").pointerTypes("LongPointer", "LongBuffer", "long[]"))

.put(new Info("__locale_data", "__spawn_action", "timex").cast().pointerTypes("Pointer"))
.put(new Info("__timezone_ptr_t").cast().pointerTypes("timezone"))
.put(new Info("gregset_t").cppTypes("const greg_t*"))
.put(new Info("gregset_t").cppTypes("const long long*"))
.put(new Info("fpregset_t").cppTypes("const void*"))

.put(new Info("__locale_struct").pointerTypes("locale_t"))
.put(new Info("__locale_t").valueTypes("locale_t"))
Expand All @@ -142,7 +145,6 @@ public void map(InfoMap infoMap) {
.put(new Info("sigval_t").pointerTypes("sigval"))
.put(new Info("struct sigstack").pointerTypes("sigstack"))
.put(new Info("sigaltstack").pointerTypes("stack_t"))
.put(new Info("fpregset_t").valueTypes("_libc_fpstate"))
.put(new Info("ucontext").valueTypes("ucontext_t"))

.put(new Info("siginfo_t").javaText("\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void init(Logger logger, java.util.Properties properties, String encoding
this.logger = logger;
this.properties = properties;
this.encoding = encoding;
this.is64bits = properties.getProperty("platform").endsWith("64");
this.is64bits = properties.getProperty("platform").contains("64");
}

public void map(InfoMap infoMap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void init(Logger logger, java.util.Properties properties, String encoding
this.logger = logger;
this.properties = properties;
this.encoding = encoding;
this.is64bits = properties.getProperty("platform").endsWith("64");
this.is64bits = properties.getProperty("platform").contains("64");
}

public void map(InfoMap infoMap) {
Expand Down

0 comments on commit afc6150

Please sign in to comment.