CC = @CC@
LN_S = @LN_S@
AR = @AR@
AS = @AS@
RANLIB = @RANLIB@
CPP = @CPP@
CFLAGS = -Wall @CFLAGS@ @DEFS@
CPPFLAGS = @CPPFLAGS@ @DEFS@
LDFLAGS = @LDFLAGS@ @LIBS@
INSTALL = @INSTALL@
EXEEXT = @EXEEXT@
OBJEXT = @OBJEXT@
PATH_SEPARATOR = @PATH_SEPARATOR@
SHOBJFLAGS = @SHOBJFLAGS@
SHOBJLDFLAGS = @SHOBJLDFLAGS@
SHOBJEXT = @SHOBJEXT@
AREXT = @AREXT@
PKGVERS = @PACKAGE_VERSION@
PKGVERSMAJOR = `echo $(PKGVERS) | cut -f 1 -d .`

prefix = @prefix@
mandir = @mandir@
sysconfdir = @sysconfdir@
datadir = @datadir@
exec_prefix = @exec_prefix@
bindir = @bindir@
libdir = @libdir@
includedir = @includedir@

LIBS = libopennet.$(SHOBJEXT) libopennet.$(AREXT)
BINS =
# The following two lines need to be kept syncronised.
LIBOPENNET_OBJS = buffer.o crc.o opennet.o parse.o @LIBOBJS@
LIBOPENNET_SHOBJS = buffer_shr.o crc_shr.o opennet_shr.o parse_shr.o @SHLIBOBJS@

all: $(LIBS) $(BINS)

libopennet.$(SHOBJEXT): $(LIBOPENNET_SHOBJS)
	$(CC) $(CPPFLAGS) $(CFLAGS) $(SHOBJFLAGS) -o $@ $(LIBOPENNET_SHOBJS) $(LDFLAGS) $(SHOBJLDFLAGS)

libopennet.$(AREXT): $(LIBOPENNET_OBJS)
	$(AR) rcu $@ $(LIBOPENNET_OBJS)
	-$(RANLIB) $@

%_shr.o: %.c
	$(CC) $(CPPFLAGS) $(CFLAGS) $(SHOBJFLAGS) -c -o $@ $?

.PHONY: clean distclean install all
clean:
	rm -f *.o $(BINS) $(LIBS) *.def *~ libopennet.dll.a
distclean: clean
	rm -f Makefile config.h config.status config.log fopen_net.3 fseek_net.3 lseek_net.3 open_net.3 opennet.3 opennet_init.3 read_net.3

install: all
	-$(INSTALL) -d $(libdir)
	-$(INSTALL) -d $(includedir)
	-$(INSTALL) -d $(mandir)
	-$(INSTALL) -d $(mandir)/man3
	-$(INSTALL) -m 644 libopennet.$(SHOBJEXT).def $(libdir)/libopennet.$(SHOBJEXT).def
	-$(INSTALL) -m 644 libopennet.$(SHOBJEXT).a $(libdir)/libopennet.$(SHOBJEXT).a
	$(INSTALL) -m 755 libopennet.$(SHOBJEXT) $(libdir)/libopennet.$(SHOBJEXT).$(PKGVERS)
	$(INSTALL) -m 644 libopennet.$(AREXT) $(libdir)/libopennet.$(AREXT)
	$(INSTALL) -m 644 opennet.h $(includedir)/opennet.h
	$(INSTALL) -m 644 opennet_init.3 $(mandir)/man3/opennet_init.3
	$(INSTALL) -m 644 fopen_net.3 $(mandir)/man3/fopen_net.3
	$(INSTALL) -m 644 lseek_net.3 $(mandir)/man3/lseek_net.3
	$(INSTALL) -m 644 fseek_net.3 $(mandir)/man3/fseek_net.3
	$(INSTALL) -m 644 open_net.3 $(mandir)/man3/open_net.3
	$(INSTALL) -m 644 read_net.3 $(mandir)/man3/read_net.3
	$(INSTALL) -m 644 opennet.3 $(mandir)/man3/opennet.3
	-( cd $(libdir) && rm -f libopennet.$(SHOBJEXT).$(PKGVERSMAJOR) && $(LN_S) libopennet.$(SHOBJEXT).$(PKGVERS) libopennet.$(SHOBJEXT).$(PKGVERSMAJOR) )
	-( cd $(libdir) && rm -f libopennet.$(SHOBJEXT) && $(LN_S) libopennet.$(SHOBJEXT).$(PKGVERS) libopennet.$(SHOBJEXT) )

