INSTALL_DIR=/usr/local

ifeq ($(OS),Windows_NT)
   INSTALL_LIB_DIR=$(INSTALL_DIR)/bin
else
   INSTALL_LIB_DIR=$(INSTALL_DIR)/lib
endif

all:
	gprbuild -P jni.gpr

# note: we force a sleep after the patch in order to be sure that, on windows,
# the timestamp of the subsequent ali files will be different.	
setup:	
	(case `uname -s` in \
	   CYGWIN*) \
	      patch -p0 < i-javjni-win32.diff; \
	      sleep 2; \
	      sed 's/External ("OS", "linux")/External ("OS", "Windows_NT")/' distrib/jni.gpr > distrib/jni.gpr.new ; \
	      cp distrib/jni.gpr.new distrib/jni.gpr \
	      ;; \
	   Darwin) \
	      sed 's/External ("OS", "linux")/External ("OS", "Darwin")/' distrib/jni.gpr > distrib/jni.gpr.new ; \
	      cp distrib/jni.gpr.new distrib/jni.gpr \
	      ;; \
	esac)

install: all
	mkdir -p $(INSTALL_DIR)
	mkdir -p $(INSTALL_DIR)/lib
	mkdir -p $(INSTALL_DIR)/lib/gnat
	mkdir -p $(INSTALL_DIR)/include
	mkdir -p $(INSTALL_DIR)/include/gnatjni
	mkdir -p $(INSTALL_DIR)/lib/gnatjni
	mkdir -p $(INSTALL_LIB_DIR)
	for ext in so dll dylib ; do \
		if [ -f lib/*.$$ext ]; then \
			cp -pf lib/*.$$ext $(INSTALL_LIB_DIR) ; \
		fi \
	done
	cp -pf distrib/jni.gpr $(INSTALL_DIR)/lib/gnat
	cp -pf lib/*.ali $(INSTALL_DIR)/lib/gnatjni
	cp -pf *.ad* $(INSTALL_DIR)/include/gnatjni
