#
# Makefile for tiltstick library
# This also installs the udev rule necessary for access to the event interface
#

MAJOR = 1
MINOR = 0

LIB = libtiltstick
STLIB = $(LIB).a
SHLIB = $(LIB).so
HDRDIR = /usr/include
LIBDIR = /usr/lib

CFLAGS = -fno-builtin -g -c -W -Wreturn-type -Wcomment
OBJS = tiltstick.o

all: static shared

.c.o:
	$(CC) $(INCS) $(CFLAGS) -c -o$@ $<

static: $(STLIB)
shared: $(SHLIB).$(MAJOR).$(MINOR)

$(STLIB): $(OBJS)
	rm -f $(STLIB)
	ar rcv $(STLIB) $(OBJS)
	-ranlib $(STLIB)

$(SHLIB).$(MAJOR).$(MINOR): $(OBJS)
	rm -f $(SHLIB)
	gcc -shared -Wl,-soname,$(SHLIB).$(MAJOR) -o $(SHLIB).$(MAJOR).$(MINOR) $(OBJS)

tiltstick.o: tiltstick.h

install: $(STLIB)
	install -d $(DESTDIR)/$(LIBDIR)
	install $(STLIB) $(SHLIB).$(MAJOR).$(MINOR) $(DESTDIR)/$(LIBDIR)
	install -d $(DESTDIR)/$(HDRDIR)
	install tiltstick.h $(DESTDIR)/$(HDRDIR)
	install -d $(DESTDIR)/etc/udev/rules.d
	install tiltstick.rules $(DESTDIR)/etc/udev/rules.d

clean:
	rm -f *.[oa] *~ $(SHLIB) $(STLIB)
