include ../Makefile.conf

STATIC_LIB=libgnatjni.a
RELOCATABLE_LIB=$(LIB_PREFIX)gnatjni.$(RELOCATABLE_LIB_SUFFIX)

all: setup static relocatable

static: lib/$(STATIC_LIB)

lib/$(STATIC_LIB):
	$(GPRBUILD) $(GPRBUILD_FLAGS) -p -XLibrary_Kind=static -P jni.gpr

relocatable: lib/$(RELOCATABLE_LIB)

lib/$(RELOCATABLE_LIB):
	$(GPRBUILD) $(GPRBUILD_FLAGS) -p -XLibrary_Kind=relocatable -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 $(target) in \
	   windows) \
	      $(PATCH) $(PATCH_FLAGS) -p0 < i-javjni-win32.diff; \
	      sleep 2; \
	      sed 's/External ("OS", "linux")/External ("OS", "Windows_NT")/' distrib/jni.gpr.tmpl > distrib/jni.gpr ; \
	      ;; \
	   darwin) \
	      sed 's/External ("OS", "linux")/External ("OS", "Darwin")/' distrib/jni.gpr.tmpl > distrib/jni.gpr ; \
	      ;; \
	   linux) \
	      $(COPY) distrib/jni.gpr.tmpl distrib/jni.gpr \
	      ;; \
	esac)

install: all
	$(MKDIR) -p $(INSTALL_DIR)/lib/gnat
	$(MKDIR) -p $(INSTALL_DIR)/include/gnatjni
	$(MKDIR) -p $(INSTALL_DIR)/lib/gnatjni/static
	$(MKDIR) -p $(INSTALL_DIR)/lib/gnatjni/relocatable
	$(MKDIR) -p $(INSTALL_LIB_DIR)
	$(COPY) -pf lib/static/$(STATIC_LIB) $(INSTALL_DIR)/lib/gnatjni/static
	$(COPY) -pf lib/relocatable/$(RELOCATABLE_LIB) $(INSTALL_DIR)/lib/gnatjni/relocatable
	$(REMOVE) -f $(INSTALL_LIB_DIR)/$(RELOCATABLE_LIB)
	$(LINK) $(INSTALL_DIR)/lib/gnatjni/relocatable/$(RELOCATABLE_LIB) $(INSTALL_LIB_DIR)/.
	$(COPY) -pf distrib/jni.gpr $(INSTALL_DIR)/lib/gnat
	$(COPY) -pf lib/static/*.ali $(INSTALL_DIR)/lib/gnatjni/static
	$(COPY) -pf lib/relocatable/*.ali $(INSTALL_DIR)/lib/gnatjni/relocatable
	$(COPY) -pf *.ad* $(INSTALL_DIR)/include/gnatjni

clean:
	$(GPRCLEAN_FLAGS) -P jni.gpr
