# Copyright (c) 2000-2018 Synology Inc. All rights reserved.

# We want to link a library, named "libexportent.so", for libsynonfs.
# But don't want to modified Makefile.in.
# So here we have this Makefile to link this file.

include ../Makefile.inc

# library name
LIBNAME = exportent
LIBEXPORTENT = lib$(LIBNAME).so.$(SHLIB_MAJOR).$(SHLIB_MINOR)
LIBRARIES = lib$(LIBNAME).a lib$(LIBNAME).so
DESCRIPTOR = libexportent.pc

# link files
OBJ_DIR = $(PROJ_DIR)/support/nfs/.libs/
OBJS = $(OBJ_DIR)/exports.o $(OBJ_DIR)/xio.o $(OBJ_DIR)/xlog.o $(OBJ_DIR)/xcommon.o $(OBJ_DIR)/conffile.o

.PHONY: all clean install remoteinstall

all: $(LIBRARIES)

lib$(LIBNAME).a: $(OBJS)
	$(AR) $(ARFLAGS) $@ $(OBJS)
	$(RANLIB) $@

lib$(LIBNAME).so: $(LIBEXPORTENT)
	rm -f $@
	ln -s $(LIBEXPORTENT) lib$(LIBNAME).so

$(LIBEXPORTENT): $(OBJS)
	rm -f $@
	$(CC) -Wl,-soname,$(LIBEXPORTENT) -shared -o $@ $(OBJS) $(LDFLAGS)

clean:
	rm -f $(DESCRIPTOR)
	rm -f core */*~ *~ */*.o */*.po *.a *.o *.so* *.d *.cgi

install: $(DESCRIPTOR)
	[ -d $(INSTALLDIR)/$(libdir) ] || install -d $(INSTALLDIR)/$(libdir)
	@set -e ;\
	install -c -v -m 755 $(LIBEXPORTENT) $(INSTALLDIR)/$(libdir)/lib$(LIBNAME).so

	[ -d $(INSTALLDIR)/$(libdir)/pkgconfig ] || install -d $(INSTALLDIR)/$(libdir)/pkgconfig
	install -D -m 644 $(DESCRIPTOR) $(INSTALLDIR)/$(libdir)/pkgconfig

remoteinstall:
	[ -d $(INSTALLDIR)/$(libdir) ] || install -d $(INSTALLDIR)/$(libdir)
	@set -e ;\
	install -c -v -m 755 $(LIBEXPORTENT) $(INSTALLDIR)/$(libdir)/lib$(LIBNAME).so
ifndef NOSTRIP
	@set -e ;\
	echo "${STRIP} $(INSTALLDIR)/$(libdir)/lib$(LIBNAME).so"; \
	${STRIP} $(INSTALLDIR)/$(libdir)/lib$(LIBNAME).so
endif

$(DESCRIPTOR): $(DESCRIPTOR).in
	rm -f $@
	cat $(DESCRIPTOR).in | sed -e "s%@DEFINES@%$(DEFINES_EXPORT)%g" \
		-e "s%@PREFIX@%$(prefix)%g" \
		-e "s%@REQUIRES@%$(REQUIRES)%g" \
		-e "s%@REQUIRES_PRIVATE@%$(REQUIRES_PRIVATE)%g" \
		-e "s%@LIBS_PRIVATE@%$(LIBS_PRIVATE)%g" > $@
	chmod +x $@