CC = gcc
LD = /usr/ccs/bin/ld
AR = /usr/ccs/bin/ar cru
RANLIB = /usr/ccs/bin/ranlib
MAJOR_VERSION = 1
MINOR_VERSION = 6
PATCH_LEVEL = 8
VERSION = $(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_LEVEL)
LIBDIR = /usr/lib
INCDIR = /usr/include
INCLUDE = -I../include
OUTPUT = libNL.so.$(VERSION)
LIBNAME = NL
STATIC = libNL.a
OPTFLAGS = -funroll-all-loops -ffast-math -fomit-frame-pointer -O2 -D_GNU_SOURCE -D_REENTRANT -DNL_SAFE_COPY -DSOLARIS
CFLAGS = -Wall -fPIC $(INCLUDE) $(OPTFLAGS)
LIBFLAGS = -G -h libNL.so.$(MAJOR_VERSION) -o $(OUTPUT) -lpthread -lnsl -lsocket
OBJECTS = crc.o errorstr.o nl.o sock.o group.o loopback.o err.o thread.o mutex.o condition.o nltime.o

all: $(OBJECTS)
	$(LD) $(LIBFLAGS) $(OBJECTS)
	$(AR) $(STATIC) $(OBJECTS)
	$(RANLIB) $(STATIC)

nl.o : nlinternal.h nl.c
sock.o : nlinternal.h sock.c
errorstr.o : nlinternal.h errorstr.c
crc.o : ../include/nl.h crc.c
group.o : nlinternal.h group.c
loopback.o : nlinternal.h loopback.h loopback.c
err.o : nlinternal.h err.c
thread.o : nlinternal.h thread.c
mutex.o : nlinternal.h mutex.c
condition.0 : nlinternal.h condition.c
nltime.o : nlinternal.h nltime.c

install:
	cp $(OUTPUT) $(LIBDIR)
	cp $(STATIC) $(LIBDIR)
	chmod 755 $(LIBDIR)/$(OUTPUT)
	ln -s $(LIBDIR)/$(OUTPUT) lib$(LIBNAME).so.$(MAJOR_VERSION).$(MINOR_VERSION)
	ln -s $(LIBDIR)/$(OUTPUT) $(LIBDIR)/lib$(LIBNAME).so.$(MAJOR_VERSION)
	ln -s $(LIBDIR)/$(OUTPUT) $(LIBDIR)/lib$(LIBNAME).so
	cp ../include/nl.h $(INCDIR)/nl.h
	chmod 644 $(INCDIR)/nl.h

uninstall:
	rm -f $(LIBDIR)/$(OUTPUT) $(LIBDIR)/lib$(LIBNAME).so.$(MAJOR_VERSION).$(MINOR_VERSION)
	rm -f $(LIBDIR)/lib$(LIBNAME).so.$(MAJOR_VERSION).$(MINOR_VERSION)
	rm -f $(LIBDIR)/lib$(LIBNAME).so.$(MAJOR_VERSION)
	rm -f $(LIBDIR)/lib$(LIBNAME).so
	rm -f $(LIBDIR)/$(STATIC)
	rm -f $(INCDIR)/nl.h

.PHONY : clean
clean:
	rm $(OBJECTS) $(OUTPUT) $(STATIC)

