SNARE-VERSION=0.9.8
bindir = $(prefix)/usr/bin
sharedir = $(prefix)/usr/share/snarelinux
confdir = $(prefix)/etc

CC = gcc
# Include BUILD cflags if they exist (from spec file)
CFLAGS = -Wall -O2 $(BCFLAGS)

all: xlate

xlate: SnareTranslationTable.o
	$(CC) $(LDFLAGS) -l audit -o SnareTranslationTable $^

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

install:
	cp SnareDispatcher.pl $(bindir)/SnareDispatcher
	if [ ! -d $(sharedir) ]; then mkdir -p $(sharedir);fi
	cp SnareWebServer.pl $(sharedir)/SnareWebServer.pl
	cp SnareTranslationTable $(sharedir)/SnareTranslationTable
	if [ ! -d $(confdir) ]; then mkdir -p $(confdir);fi
	cp snare.conf $(confdir)
	chmod 700 $(confdir) $(confdir)/snare.conf
	grep "^dispatcher" $(confdir)/auditd.conf; \
	./Installer.sh -i $(confdir) $(bindir) $(sharedir)

uninstall:
	if [ -f $(confdir)/snare.conf ]; then rm -f $(confdir)/snare.conf;fi
	if [ -d $(sharedir) ]; then rm -f $(sharedir)/*;rmdir $(sharedir);fi
	./Installer.sh -u $(confdir) $(bindir) $(sharedir)
	if [ -f $(confdir)/snare-xlate.conf ]; then rm -f $(confdir)/snare-xlate.conf; fi

clean:
	rm -f SnareTranslationTable core.* *.o
