include ../Makefile.defs 

CFLAGS += -fPIC
#CFLAGS += -DTRACE

MAJOR        = 2
MINOR        = 2.0

ifneq ($(IDSAMODULES),no)
  CFLAGS    += -DIDSAMODULES=\"$(IDSAMODULES)\"
  LIB        = $(DLLIB)
endif

MODSRC       = mod_default.c mod_log.c
MODOBJ       = mod_default.o mod_log.o

LIBSRC       = client.c event.c unit.c types.c protocol.c wire.c risk.c print.c syslog.c escape.c mex.c rule.c module.c parse.c error.c support.c $(MODSRC) 
LIBOBJ       = client.o event.o unit.o types.o protocol.o wire.o risk.o print.o syslog.o escape.o mex.o rule.o module.o parse.o error.o support.o $(MODOBJ)

LIBNAME      = lib$(PROJECT).so
LIBNAMEMAJOR = $(LIBNAME).$(MAJOR)
LIBNAMEMINOR = $(LIBNAME).$(MAJOR).$(MINOR)
LDSOCONF     = /etc/ld.so.conf

INCLUDE      = -I../include

all: $(LIBNAMEMINOR)

install: all
	@$(INSTALL) -d -m 0755 $(LIBDIR)
	@$(INSTALL) -m 0755 $(LIBNAMEMINOR) $(LIBDIR)
	-$(RM) $(LIBDIR)/$(LIBNAMEMAJOR) $(LIBDIR)/$(LIBNAME)
	(cd $(LIBDIR) ; $(LN) $(LIBNAMEMINOR) $(LIBNAMEMAJOR))
	(cd $(LIBDIR) ; $(LN) $(LIBNAMEMINOR) $(LIBNAME))
	@if ! $(GREP) -q $(LIBDIR) $(LDSOCONF) ; then $(WARN) "You might have to add $(LIBDIR) to $(LDSOCONF)" ; fi
	$(LDCONFIG)
	@$(WARN) "You might have to run $(LDCONFIG) to update the cache"

$(LIBNAMEMINOR): $(LIBOBJ)
	$(RM) $(LIBNAME) $(LIBNAMEMAJOR)
	$(CC) -shared -Wl,-x,-soname,$(LIBNAMEMAJOR) $(LIBOBJ) -o $(LIBNAMEMINOR) $(LIB)
	$(LN) $(LIBNAMEMINOR) $(LIBNAMEMAJOR)
	$(LN) $(LIBNAMEMINOR) $(LIBNAME)

%.o: %.c ../include/*.h
	$(CC) $(CFLAGS) $(INCLUDE) -DVERSION=\"$(VERSION)\" -c $<

checkpoint: indent clean
	$(CI) -l *.[ch]

indent:
	$(INDENT) $(LIBSRC)

clean:
	$(RM) *.o *~ core

reallyclean: clean
	$(RM) libidsa*so*
