PACKAGE=@PACKAGE@
VERSION=@VERSION@
MAJOR=0

SHELL = @SHELL@

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@

bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include

DESTDIR =

pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@


CXX=@CXX@
CXXFLAGS=@CXXFLAGS@
RANLIB=@RANLIB@
LN_S=@LN_S@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@

FLAGS=-Wall -W $(CXXFLAGS)
INCL=-I.
LIBS=-l$(PACKAGE) -L.

SHOBJECTS=$(PACKAGE).sho
STOBJECTS=$(PACKAGE).o
HEADERS=$(PACKAGE).h

DOCS=TODO

all: shared static

clean:
	rm -f testopt core *~
	rm -f *.a *.so* *.o *.sho

distclean: clean
	rm -f config.log config.cache config.status
	rm -f Makefile

maintainer-clean: distclean

$(SHOBJECTS): %.sho: %.cpp
	$(CXX) $(FLAGS) -fPIC $(INCL) -c $< -o $@

$(STOBJECTS): %.o: %.cpp
	$(CXX) $(FLAGS) $(INCL) -c $< -o $@

shared: lib$(PACKAGE).so.$(VERSION)
	ln -sf lib$(PACKAGE).so.$(VERSION) lib$(PACKAGE).so.$(MAJOR)
	ln -sf lib$(PACKAGE).so.$(MAJOR) lib$(PACKAGE).so

lib$(PACKAGE).so.$(VERSION): $(SHOBJECTS)
	$(CXX) $(FLAGS) $(INCL) -shared \
	-Wl,-symbolic,-soname,lib$(PACKAGE).so.$(MAJOR) \
	$(SHOBJECTS) -o lib$(PACKAGE).so.$(VERSION)

static: lib$(PACKAGE).a

lib$(PACKAGE).a: $(STOBJECTS)
	ar rc lib$(PACKAGE).a $(STOBJECTS)
	$(RANLIB) lib$(PACKAGE).a

install: install-shared install-static install-headers

install-shared:
	$(INSTALL) -d $(DESTDIR)$(libdir)
	$(INSTALL_DATA) lib$(PACKAGE).so.$(VERSION) $(DESTDIR)$(libdir)
	$(LN_S) lib$(PACKAGE).so.$(VERSION) $(DESTDIR)$(libdir)/lib$(PACKAGE).so.$(MAJOR)
	$(LN_S) lib$(PACKAGE).so.$(MAJOR) $(DESTDIR)$(libdir)/lib$(PACKAGE).so

install-static:
	$(INSTALL) -d $(DESTDIR)$(libdir)
	$(INSTALL_DATA) lib$(PACKAGE).a $(DESTDIR)$(libdir)

install-headers:
	$(INSTALL) -d $(DESTDIR)$(includedir)
	$(INSTALL_DATA) $(HEADERS) $(DESTDIR)$(includedir)

test: testopt
testopt: testopt.cpp cppopt.h
	$(CXX) $(FLAGS) $(INCL) $(LIBS) -o testopt testopt.cpp

.PHONY: all clean distclean maintainer-clean shared static install install-shared install-static install-headers test
