From 099f2de5b4301c1450d3bc6c1d7c32490793ab83 Mon Sep 17 00:00:00 2001 From: krangelov Date: Tue, 19 Mar 2019 12:43:38 +0100 Subject: [PATCH] support cross-compilation from Linux to Windows --- src/runtime/java/Makefile | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/runtime/java/Makefile b/src/runtime/java/Makefile index 14f350ea4..4af682699 100644 --- a/src/runtime/java/Makefile +++ b/src/runtime/java/Makefile @@ -1,3 +1,5 @@ +INSTALL_PATH = /usr/local + C_SOURCES = jpgf.c jsg.c jni_utils.c JAVA_SOURCES = $(wildcard org/grammaticalframework/pgf/*.java) \ $(wildcard org/grammaticalframework/sg/*.java) @@ -8,23 +10,28 @@ JNI_INCLUDES = $(if $(wildcard /usr/lib/jvm/default-java/include/.*), -I/usr/lib $(if $(wildcard /Library/Java/Home/include/.*), -I/Library/Java/Home/include/ -I/Library/Java/Home/include/darwin, \ $(error No JNI headers found))))) -# For Windows replace the previous line with something like this: +# For compilation on Windows replace the previous line with something like this: # # JNI_INCLUDES = -I "C:/Program Files/Java/jdk1.8.0_171/include" -I "C:/Program Files/Java/jdk1.8.0_171/include/win32" -I "C:/MinGW/msys/1.0/local/include" -# WINDOWS_FLAGS = -L"C:/MinGW/msys/1.0/local/lib" -no-undefined +# WINDOWS_LDFLAGS = -L"C:/MinGW/msys/1.0/local/lib" -no-undefined -INSTALL_PATH = /usr/local/lib -LIBTOOL = glibtool --tag=CC +GCC = gcc +LIBTOOL = $(if $(shell command -v glibtool 2>/dev/null), glibtool, libtool) --tag=CC -LIBTOOL = $(if $(shell command -v glibtool 2>/dev/null), glibtool --tag=CC, libtool) +# For cross-compilation from Linux to Windows replace the previous two lines with: +# +# GCC = x86_64-w64-mingw32-gcc +# LIBTOOL = ../c/libtool +# WINDOWS_CCFLAGS = -I$(INSTALL_PATH)/include +# WINDOWS_LDFLAGS = -L$(INSTALL_PATH)/lib -no-undefined all: libjpgf.la jpgf.jar libjpgf.la: $(patsubst %.c, %.lo, $(C_SOURCES)) - $(LIBTOOL) --mode=link gcc $(CFLAGS) -g -O -o libjpgf.la -shared $^ -rpath $(INSTALL_PATH) -lgu -lpgf -lsg $(WINDOWS_FLAGS) + $(LIBTOOL) --mode=link $(GCC) $(CFLAGS) -g -O -o libjpgf.la -shared $^ -rpath $(INSTALL_PATH)/lib -lgu -lpgf -lsg $(WINDOWS_LDFLAGS) %.lo : %.c - $(LIBTOOL) --mode=compile gcc $(CFLAGS) -g -O -c $(JNI_INCLUDES) -std=c99 -shared $< -o $@ + $(LIBTOOL) --mode=compile $(GCC) $(CFLAGS) -g -O -c $(JNI_INCLUDES) $(WINDOWS_CCFLAGS) -std=c99 -shared $< -o $@ jpgf.jar: $(patsubst %.java, %.class, $(JAVA_SOURCES)) jar -cf $@ org/grammaticalframework/pgf/*.class org/grammaticalframework/sg/*.class @@ -33,8 +40,8 @@ jpgf.jar: $(patsubst %.java, %.class, $(JAVA_SOURCES)) javac $< install: libjpgf.la jpgf.jar - $(LIBTOOL) --mode=install install -s libjpgf.la $(INSTALL_PATH) - install jpgf.jar $(INSTALL_PATH) + $(LIBTOOL) --mode=install install -s libjpgf.la $(INSTALL_PATH)/lib + install jpgf.jar $(INSTALL_PATH)/lib doc: