###############################
# Makefile for contrib software
###############################

CC=@CC@
CFLAGS=@CFLAGS@ @DEFS@
LDFLAGS=@LDFLAGS@ @LIBS@

# Source code directories
SRC_INCLUDE=../include
SRC_COMMON=../common
SRC_CGI=../cgi

# Generated automatically from configure script
SNPRINTF_O=@SNPRINTF_O@
INSTALL=@INSTALL@
INSTALL_OPTS=@INSTALL_OPTS@


prefix=@prefix@
exec_prefix=@exec_prefix@
CGIDIR=@sbindir@
BINDIR=@bindir@
LIBDIR=@libdir@

UTILS=mini_epn new_mini_epn
ALL=$(CGIS) $(UTILS)
DST=dst

###############################
# Debug
###############################
ENABLE_DEBUG=@ENABLE_DEBUG@

# Compiler flags for use with Valgrind - set when debug is enabled
ifeq ('$(ENABLE_DEBUG)', 'yes')
        CFLAGS+=-O0 -g
endif

##############################################################################
# standard targets (all, clean, distclean, devclean, install)

all: $(ALL)

clean:
	rm -f mini_epn new_mini_epn core dst *.o
	rm -f */*/*~
	rm -f */*~
	rm -f *~

distclean: clean
	rm -f Makefile
	rm -f eventhandlers/disable_active_service_checks eventhandlers/disable_notifications eventhandlers/enable_active_service_checks eventhandlers/enable_notifications eventhandlers/submit_check_result


devclean: distclean

install:
	$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(BINDIR)
	for f in $(UTILS); do $(INSTALL) -m 775 $(INSTALL_OPTS) $$f $(DESTDIR)$(BINDIR); done

##############################################################################
# rules and dependencies for actual target programs

mini_epn: mini_epn.c
	perl -MExtUtils::Embed -e xsinit
	$(CC) $(CFLAGS) -c perlxsi.c  `perl -MExtUtils::Embed -e ccopts`
	$(CC) $(CFLAGS) -c mini_epn.c `perl -MExtUtils::Embed -e ccopts`
	$(CC) $(CFLAGS) $(LDFLAGS) perlxsi.o mini_epn.o `perl -MExtUtils::Embed -e ccopts -e ldopts` -o $@

new_mini_epn: new_mini_epn.c
	perl -MExtUtils::Embed -e xsinit
	$(CC) $(CFLAGS) -c perlxsi.c  `perl -MExtUtils::Embed -e ccopts`
	$(CC) $(CFLAGS) -c new_mini_epn.c `perl -MExtUtils::Embed -e ccopts`
	$(CC) $(CFLAGS) $(LDFLAGS) perlxsi.o new_mini_epn.o `perl -MExtUtils::Embed -e ccopts -e ldopts` -o $@
dst: dst.c
	$(CC) $(CFLAGS) -o $@ $< 
