
#
# Directories for installation
#

DESTDIR  =
PREFIX   = /usr/local

INCDIR   = $(PREFIX)/include
LIBDIR   = $(PREFIX)/lib
L32DIR   = $(PREFIX)/lib32
L64DIR   = $(PREFIX)/lib64
L_64DIR  = $(PREFIX)/lib/64
BINDIR   = $(PREFIX)/bin
DOCDIR   = $(PREFIX)/share/doc/sllib

#
# Compiler and libraries
#

CXX      = g++

LIBPRIVATE = -lreadline -lcurses -lbz2 -lz

#
# Settings for `make'
#

# You can build 32-bit or 64-bit library by ...
#  $ make CCFLAGS=-m32
# or
#  $ make CCFLAGS=-m64

CCFLAGS  =
# for 32-bit library on 64-bit Linux
#CCFLAGS = -m32
# for 64-bit library on MacOSX
#CCFLAGS = -m64

# DO NOT CHANGE
IINC     = 
ALL_CCFLAGS = -O2 -Wall $(CCFLAGS) $(EXAMFLAGS)
SINCDIR  = $(INCDIR)/sli

.cc.o:   ; sh s++.sh $(ALL_CCFLAGS) $(IINC) -c $*.cc

all::	s++.sh s++ static

s++.sh:
	cat s++.src | sed -e 's|^CPPC=[^=]*|CPPC='"$(CXX)"'|' > s++.sh

#sli_endian.h:
#	sh mk_sli_endian.sh > $@

@OLIST0@

static::	@OLIST1@
	ar cru libsllib.a $?
	ranlib libsllib.a

shared::	@OLIST1@
	sh s++.sh -shared -o libsllib.so $? -lz -lbz2 -lreadline

s++:	s++.sh
	if [ -d /usr/lib/64 ]; then \
	  cat s++.sh | sed -e 's|^XARG_IINC=|XARG_IINC=-I'"$(INCDIR)"'|' \
	   -e 's|^DOCDIR=|DOCDIR=\"'"$(DOCDIR)"'\"|' \
	   -e 's|^XARG_LIBSLLIB=|XARG_LIBSLLIB=-lsllib|' \
	   -e 's|^XARG_LIBPRIVATE=|XARG_LIBPRIVATE=\"'"$(LIBPRIVATE)"'\"|' \
	   -e 's|^XARG_LLIB=|XARG_LLIB=\"-L'"$(LIBDIR)"' -L'$(L_64DIR)'\"|' > s++ ; \
	elif [ -d /lib64 ]; then \
	  cat s++.sh | sed -e 's|^XARG_IINC=|XARG_IINC=-I'"$(INCDIR)"'|' \
	   -e 's|^DOCDIR=|DOCDIR=\"'"$(DOCDIR)"'\"|' \
	   -e 's|^XARG_LIBSLLIB=|XARG_LIBSLLIB=-lsllib|' \
	   -e 's|^XARG_LIBPRIVATE=|XARG_LIBPRIVATE=\"'"$(LIBPRIVATE)"'\"|' \
	   -e 's|^XARG_LLIB=|XARG_LLIB=\"-L'"$(LIBDIR)"' -L'$(L64DIR)'\"|' > s++ ; \
	else \
	  cat s++.sh | sed -e 's|^XARG_IINC=|XARG_IINC=-I'"$(INCDIR)"'|' \
	   -e 's|^DOCDIR=|DOCDIR=\"'"$(DOCDIR)"'\"|' \
	   -e 's|^XARG_LIBSLLIB=|XARG_LIBSLLIB=-lsllib|' \
	   -e 's|^XARG_LIBPRIVATE=|XARG_LIBPRIVATE=\"'"$(LIBPRIVATE)"'\"|' \
	   -e 's|^XARG_LLIB=|XARG_LLIB=-L'"$(LIBDIR)"'|' > s++ ; \
	fi

clean::
	rm -f s++ s++.sh \
		*.o *.lo *.la *.a *.so *.dylib *.dll
	rm -f config.status config.log libtool sllib.pc
	rm -rf .deps .libs

install::
	sh install_help.sh $(LIBDIR) $(L32DIR) $(L64DIR) $(L_64DIR)

install32::	install_common install_lib_32

install64::	install_common install_lib_64

installany::	install_common install_lib_64


install_common::
	if [ ! -d $(DESTDIR)$(BINDIR) ];then sh install-sh -d $(DESTDIR)$(BINDIR); fi
	sh install-sh -m 755 s++ $(DESTDIR)$(BINDIR)
	if [ ! -d $(DESTDIR)$(SINCDIR) ];then sh install-sh -d $(DESTDIR)$(SINCDIR); fi
	sh install-sh -m 644 `echo ' ' *.h | sed -e 's/ config[.]h//'` $(DESTDIR)$(SINCDIR)
	if [ ! -d $(DESTDIR)$(DOCDIR)/examples ];then sh install-sh -d $(DESTDIR)$(DOCDIR)/examples; fi
	sh install-sh -m 644 README $(DESTDIR)$(DOCDIR)
	sh install-sh -m 644 LICENSE $(DESTDIR)$(DOCDIR)
	sh install-sh -m 644 LICENSE.GPL $(DESTDIR)$(DOCDIR)
	sh install-sh -m 644 LICENSE.MIT $(DESTDIR)$(DOCDIR)
	sh install-sh -m 644 examples/*.cc $(DESTDIR)$(DOCDIR)/examples

install_lib_32::
	if [ -d /usr/lib32 ]; then \
	 if [ ! -d $(DESTDIR)$(L32DIR) ];then sh install-sh -d $(DESTDIR)$(L32DIR); fi ; \
	 if [ -f libsllib.a ];then sh install-sh -m 644 *.a $(DESTDIR)$(L32DIR); fi ; \
	 if [ -f libsllib.so ];then sh install-sh -m 755 *.so $(DESTDIR)$(L32DIR); fi ; \
	 if [ -f libsllib.dylib ];then sh install-sh -m 755 *.dylib $(DESTDIR)$(L32DIR); fi ; \
	 if [ -f libsllib.dll ];then sh install-sh -m 755 *.dll $(DESTDIR)$(L32DIR); fi ; \
	else \
	 if [ ! -d $(DESTDIR)$(LIBDIR) ];then sh install-sh -d $(DESTDIR)$(LIBDIR); fi ; \
	 if [ -f libsllib.a ];then sh install-sh -m 644 *.a $(DESTDIR)$(LIBDIR); fi ; \
	 if [ -f libsllib.so ];then sh install-sh -m 755 *.so $(DESTDIR)$(LIBDIR); fi ; \
	 if [ -f libsllib.dylib ];then sh install-sh -m 755 *.dylib $(DESTDIR)$(LIBDIR); fi ; \
	 if [ -f libsllib.dll ];then sh install-sh -m 755 *.dll $(DESTDIR)$(LIBDIR); fi ; \
	fi

install_lib_64::
	if [ -d /lib64 ]; then \
	 if [ ! -d $(DESTDIR)$(L64DIR) ];then sh install-sh -d $(DESTDIR)$(L64DIR); fi ; \
	 if [ -f libsllib.a ];then sh install-sh -m 644 *.a $(DESTDIR)$(L64DIR); fi ; \
	 if [ -f libsllib.so ];then sh install-sh -m 755 *.so $(DESTDIR)$(L64DIR); fi ; \
	 if [ -f libsllib.dylib ];then sh install-sh -m 755 *.dylib $(DESTDIR)$(L64DIR); fi ; \
	 if [ -f libsllib.dll ];then sh install-sh -m 755 *.dll $(DESTDIR)$(L64DIR); fi ; \
	elif [ -d /usr/lib/64 ]; then \
	 if [ ! -d $(DESTDIR)$(L_64DIR) ];then sh install-sh -d $(DESTDIR)$(L_64DIR); fi ; \
	 if [ -f libsllib.a ];then sh install-sh -m 644 *.a $(DESTDIR)$(L_64DIR); fi ; \
	 if [ -f libsllib.so ];then sh install-sh -m 755 *.so $(DESTDIR)$(L_64DIR); fi ; \
	 if [ -f libsllib.dylib ];then sh install-sh -m 755 *.dylib $(DESTDIR)$(L_64DIR); fi ; \
	 if [ -f libsllib.dll ];then sh install-sh -m 755 *.dll $(DESTDIR)$(L_64DIR); fi ; \
	else \
	 if [ ! -d $(DESTDIR)$(LIBDIR) ];then sh install-sh -d $(DESTDIR)$(LIBDIR); fi ; \
	 if [ -f libsllib.a ];then sh install-sh -m 644 *.a $(DESTDIR)$(LIBDIR); fi ; \
	 if [ -f libsllib.so ];then sh install-sh -m 755 *.so $(DESTDIR)$(LIBDIR); fi ; \
	 if [ -f libsllib.dylib ];then sh install-sh -m 755 *.dylib $(DESTDIR)$(LIBDIR); fi ; \
	 if [ -f libsllib.dll ];then sh install-sh -m 755 *.dll $(DESTDIR)$(LIBDIR); fi ; \
	fi
