Skip to content

Commit

Permalink
Added native libraries to repository.
Browse files Browse the repository at this point in the history
 * Linux x86_64 seems to work
  • Loading branch information
wivlaro committed May 8, 2012
1 parent 6f0a89d commit 12af4f0
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ libs/libpdcsharp.*

# java
nbproject/private/
!java-build/org/puredata/natives/*/*/*.so
40 changes: 32 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ SOLIB_PREFIX = lib

ifeq ($(UNAME), Darwin) # Mac
SOLIB_EXT = dylib
PDNATIVE_PLATFORM = mac
PDNATIVE_ARCH = universal
PLATFORM_CFLAGS = -DHAVE_LIBDL -O3 -arch x86_64 -arch i386 -g \
-I/System/Library/Frameworks/JavaVM.framework/Headers
LDFLAGS = -arch x86_64 -arch i386 -dynamiclib -ldl
Expand All @@ -13,17 +15,20 @@ else
CC = gcc
SOLIB_EXT = dll
SOLIB_PREFIX =
PDNATIVE_PLATFORM = windows
PDNATIVE_ARCH = $(shell $(CC) -dumpmachine | sed -e 's,-.*,,' -e 's,i[3456]86,x86,' -e 's,amd64,x86_64,')
PLATFORM_CFLAGS = -DWINVER=0x502 -DWIN32 -D_WIN32 -DPD_INTERNAL -O3 \
-I"$(JAVA_HOME)/include" -I"$(JAVA_HOME)/include/win32"
MINGW_LDFLAGS = -shared -lws2_32 -lkernel32
LDFLAGS = $(MINGW_LDFLAGS) -Wl,--output-def=libs/libpd.def \
-Wl,--out-implib=libs/libpd.lib
CSHARP_LDFLAGS = $(MINGW_LDFLAGS) -Wl,--output-def=libs/libpdcsharp.def \
-Wl,--out-implib=libs/libpdcsharp.lib
JAVA_LDFLAGS = $(MINGW_LDFLAGS) -Wl,--output-def=libs/$(SOLIB_PREFIX)pdnative.def \
-Wl,--out-implib=libs/$(SOLIB_PREFIX)pdnative.lib
JAVA_LDFLAGS = $(MINGW_LDFLAGS)
else # Assume Linux
SOLIB_EXT = so
PDNATIVE_PLATFORM = linux
PDNATIVE_ARCH = $(shell $(CC) -dumpmachine | sed -e 's,-.*,,' -e 's,i[3456]86,x86,' -e 's,amd64,x86_64,')
JAVA_HOME ?= /usr/lib/jvm/default-java
PLATFORM_CFLAGS = -DHAVE_LIBDL -Wno-int-to-pointer-cast \
-Wno-pointer-to-int-cast -fPIC -I"$(JAVA_HOME)/include" \
Expand Down Expand Up @@ -62,14 +67,27 @@ PD_FILES = \
pure-data/src/x_qlist.c pure-data/src/x_time.c \
libpd_wrapper/s_libpdmidi.c libpd_wrapper/x_libpdreceive.c \
libpd_wrapper/z_libpd.c

PDJAVA_JAR_CLASSES = \
java/org/puredata/core/PdBase.java \
java/org/puredata/core/PdListener.java \
java/org/puredata/core/PdMidiReceiver.java \
java/org/puredata/core/PdReceiver.java \
java/org/puredata/core/utils/IoUtils.java \
java/org/puredata/core/utils/PdDispatcher.java


JNI_FILE = libpd_wrapper/z_jni.c
JNIH_FILE = libpd_wrapper/z_jni.h
JAVA_BASE = java/org/puredata/core/PdBase.java
HOOK_SET = libpd_wrapper/z_hookset.c
LIBPD = libs/libpd.$(SOLIB_EXT)
PDCSHARP = libs/libpdcsharp.$(SOLIB_EXT)
PDJAVA = libs/$(SOLIB_PREFIX)pdnative.$(SOLIB_EXT)

PDJAVA_DIR = java-build/org/puredata/natives/$(PDNATIVE_PLATFORM)/$(PDNATIVE_ARCH)/
PDJAVA_NATIVE = $(PDJAVA_DIR)/$(SOLIB_PREFIX)pdnative.$(SOLIB_EXT)
PDJAVA_JAR = libs/libpd.jar
PDJAVA_BUILD = java-build

CFLAGS = -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src \
-I./libpd_wrapper $(PLATFORM_CFLAGS)
Expand All @@ -79,16 +97,21 @@ CFLAGS = -DPD -DHAVE_UNISTD_H -DUSEAPI_DUMMY -I./pure-data/src \
libpd: $(LIBPD)

$(LIBPD): ${PD_FILES:.c=.o}
gcc -o $(LIBPD) $^ $(LDFLAGS) -lm -lpthread
$(CC) -o $(LIBPD) $^ $(LDFLAGS) -lm -lpthread

javalib: $(JNIH_FILE) $(PDJAVA)
javalib: $(PDJAVA_JAR)

$(JNIH_FILE): $(JAVA_BASE)
javac -classpath java $^
javah -o $@ -classpath java org.puredata.core.PdBase

$(PDJAVA): ${PD_FILES:.c=.o} ${JNI_FILE:.c=.o}
gcc -o $(PDJAVA) $^ -lm -lpthread $(JAVA_LDFLAGS)
$(PDJAVA_NATIVE): ${PD_FILES:.c=.o} ${JNI_FILE:.c=.o}
mkdir -p $(PDJAVA_DIR)
$(CC) -o $(PDJAVA_NATIVE) $^ -lm -lpthread $(JAVA_LDFLAGS)

$(PDJAVA_JAR): $(PDJAVA_NATIVE)
javac -d $(PDJAVA_BUILD) $(PDJAVA_JAR_CLASSES)
jar -cvf $(PDJAVA_JAR) -C $(PDJAVA_BUILD) org/puredata/

csharplib: $(PDCSHARP)

Expand All @@ -99,4 +122,5 @@ clean:
rm -f ${PD_FILES:.c=.o} ${JNI_FILE:.c=.o} ${HOOK_SET:.c=.o}

clobber: clean
rm -f $(LIBPD) $(PDCSHARP) $(PDJAVA)
rm -f $(LIBPD) $(PDCSHARP) $(PDJAVA_NATIVE)
rm -rf $(PDJAVA_BUILD)
28 changes: 28 additions & 0 deletions README.javalib.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Quickstart

Hopefully, you should just be able to include libs/libpd.jar in your project and
you're good to go. Otherwise, you can try and run:

$ make clean javalib

Which should try and build a binary for your platform and add it to the libpd.jar.

## Cross-compilation

### Cross-compiling 32-bit x86 Linux from x86_64 Linux:

$ make CC='gcc -m32' PDNATIVE_ARCH=x86 clean javalib

### Cross-compiling for Windows from Linux:

Using mingw-w64, based on instructions here http://tinyurl.com/mw64-use
Also, install the mingw-w64 pthreads, as http://tinyurl.com/mw64-pthread

#### Cross-compiling for 32-bit Windows from Linux:

$ make OS=Windows_NT CC='i686-w64-mingw32-gcc -m32' JAVA_HOME="/media/WINXP/Program Files/Java/jdk1.7.0_04" clean javalib

#### Cross-compiling for 64-bit Windows from Linux:

$ make OS=Windows_NT CC='x86_64-w64-mingw32-gcc -m64' JAVA_HOME="/media/WINXP/Program Files/Java/jdk1.7.0_04" clean javalib

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion java/org/puredata/core/PdBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private static String getArch(String osName) throws RuntimeException {
throw new RuntimeException("Unknown architecture " + osName);
}
if (arch64) {
osArch += "-64";
osArch += "_64";
}
return osArch;
}
Expand Down

0 comments on commit 12af4f0

Please sign in to comment.