# compilation and packing of the 'common' native library of tritonus
#

SHELL = /bin/sh

prefix=@prefix@
JAVADIR=$(prefix)
REL_JAVAEXTLIBPATH=@REL_JAVAEXTLIBPATH@
JAVAEXTLIBPATH=$(JAVADIR)/$(REL_JAVAEXTLIBPATH)
OSNAME=@OSNAME@
ARCHNAME=@ARCHNAME@
CC=@CC@
CPPFLAGS=-g -Wall -Werror -I$(JAVADIR)/include -I$(JAVADIR)/include/$(OSNAME) -fPIC -D_REENTRANT #-pedantic
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
LN_S=@LN_S@
RM_F=@RM_F@
MKDIR_P=@MKDIR_P@


LIBBASENAME=libtritonuscommon
LIBDEST=$(LIBBASENAME).so.1.0

#
# ATTENTION: not adapted field in the next line !!!
#

LIBDEST_ABSOLUTE=@SRC_ABSOLUTE_PATH@/src/lib/alsa/$(LIBDEST)
#or LIBDEST_ABSOLUTE=$(CURDIR)/$(LIBDEST)

OBJ=\
	common.o

#----------------- rules -------------------

.PHONY: all
all: $(LIBDEST)

$(LIBDEST):	$(OBJ)
	$(CC) -nostartfiles -shared -Wl,-soname,$(LIBBASENAME).so.1 -o $(LIBDEST) $(OBJ) -L/usr/lib $(LIBS)
	$(RM_F) $(LIBBASENAME).so.1
	$(LN_S) $(LIBBASENAME).so.1.0 $(LIBBASENAME).so.1
	$(RM_F) $(LIBBASENAME).so
	$(LN_S) $(LIBBASENAME).so.1 $(LIBBASENAME).so

.PHONY: install
install:
	@echo "Installing $(LIBBASENAME) in $(JAVAEXTLIBPATH)"
	@$(MKDIR_P) $(JAVAEXTLIBPATH)
	@$(RM_F) $(JAVAEXTLIBPATH)/$(LIBBASENAME).so.1.0
	@$(RM_F) $(JAVAEXTLIBPATH)/$(LIBBASENAME).so.1
	@$(RM_F) $(JAVAEXTLIBPATH)/$(LIBBASENAME).so
	$(INSTALL_PROGRAM) $(LIBDEST) $(JAVAEXTLIBPATH)
	@(cd $(JAVAEXTLIBPATH) && $(LN_S) $(LIBBASENAME).so.1.0 $(LIBBASENAME).so.1)
	@(cd $(JAVAEXTLIBPATH) && $(LN_S) $(LIBBASENAME).so.1 $(LIBBASENAME).so)

.PHONY: install-link
install-link:
	@echo "Creating links for $(LIBBASENAME) in $(JAVAEXTLIBPATH)"
	@$(MKDIR_P) $(JAVAEXTLIBPATH)
	@$(RM_F) $(JAVAEXTLIBPATH)/$(LIBBASENAME).so.1.0
	@$(RM_F) $(JAVAEXTLIBPATH)/$(LIBBASENAME).so.1
	@$(RM_F) $(JAVAEXTLIBPATH)/$(LIBBASENAME).so
	@(cd  $(JAVAEXTLIBPATH) && $(LN_S) $(LIBDEST_ABSOLUTE) $(LIBBASENAME).so.1.0)
	@(cd $(JAVAEXTLIBPATH) && $(LN_S) $(LIBBASENAME).so.1.0 $(LIBBASENAME).so.1)
	@(cd $(JAVAEXTLIBPATH) && $(LN_S) $(LIBBASENAME).so.1 $(LIBBASENAME).so)

.PHONY: uninstall
uninstall:
	@echo "Removing $(LIBBASENAME) from $(JAVAEXTLIBPATH)"
	@$(RM_F) $(JAVAEXTLIBPATH)/$(LIBBASENAME).so.1.0
	@$(RM_F) $(JAVAEXTLIBPATH)/$(LIBBASENAME).so.1
	@$(RM_F) $(JAVAEXTLIBPATH)/$(LIBBASENAME).so

.PHONY: uninstall-link
uninstall-link: uninstall


.PHONY: clean
clean:
	rm -rf $(LIBDEST) *.o *~
