# Makefile for hapm

CC 		= gcc
SYSCONFDIR      = $(DESTDIR)/etc/ha.d
INITDIR		= $(DESTDIR)/etc/init.d
INSTALL 	= cp
INSTALLDIR	= $(DESTDIR)/usr/sbin
MANDIR		= $(DESTDIR)/usr/share/man/man8
SRCS 		= hapm.c

all: hapm

hapm: 
	$(CC) $(SRCS) -o $@
	#
	# -------------------------------------
	# Run "# make install" to install hapm.
	# -------------------------------------
	#

install:
	@if test ! -e hapm; then \
		echo -e '\nERROR: Run "# make" before "# make install".\n'; \
		exit 1; \
	fi
	@if test  -e $(INSTALLDIR)/hapm; then \
		echo -e "\nERROR: hapm already installed.\nRun \"# make uninstall\" before reinstall.\n"; \
		echo -e "(don't fotget to make a backup of the hapm.conf file)" \
		exit 1; \
	fi
	@if test ! -d $(SYSCONFDIR); then \
		echo "creating $(SYSCONFDIR)"; \
		mkdir $(SYSCONFDIR); \
	fi
	
	$(INSTALL) hapm.conf $(SYSCONFDIR)/hapm.conf
	$(INSTALL) hapm $(INSTALLDIR)
	chmod 0755 $(INSTALLDIR)/hapm
	$(INSTALL) init.d/hapm $(INITDIR)/hapm
	chmod 0755 $(INITDIR)/hapm
	$(INSTALL) hapm.8 $(MANDIR)
	#
	# ---------------
	# hapm installed.
	# ---------------
	#

uninstall:
	@if test ! -e $(INSTALLDIR)/hapm; then \
		echo -e "\nERROR: hapm isn't installed.\n"; \
		exit 1; \
	fi
	rm -f $(INSTALLDIR)/hapm
	rm -f $(INITDIR)/hapm
	rm -rf $(SYSCONFDIR)/hapm.conf
	rm -f $(MANDIR)/hapm.8
	#
	# -----------------
	# hapm uninstalled.
	# -----------------
	#

clean:
	@if test -e hapm; then \
		rm -rf hapm; \
	fi
