# Makefile.in for hapm

CC 		= gcc
SYSCONFDIR      = /etc/ha.d
INITDIR		= /etc/init.d
INSTALL 	= cp
INSTALLDIR	= /usr/sbin
MANDIR		= /usr/share/man/man8
CFLAGS 		= -O2 -g -w

INSTALL_PROGRAM = $(INSTALL)

SRCS = hapm.c

DISTFILES = $(SRCS)

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.\n"; \
		exit 1; \
	fi
	-@if test ! -d $(SYSCONFDIR); then \
		echo "creating $(SYSCONFDIR)"; \
		mkdir $(SYSCONFDIR); \
	fi
	@if test ! -f $(SYSCONFDIR)/hapm.conf; then \
		echo "cp hapm.conf $(SYSCONFDIR)/hapm.conf"; \
		cp hapm.conf $(SYSCONFDIR)/hapm.conf; \
	else \
		cp hapm.conf $(SYSCONFDIR)/hapm.conf.new; \
	fi
	
	$(INSTALL_PROGRAM) hapm $(INSTALLDIR)
	chmod 0755 $(INSTALLDIR)/hapm
	$(INSTALL_PROGRAM) init.d/hapm $(INITDIR)/hapm
	chmod 0755 $(INITDIR)/hapm
	$(INSTALL_PROGRAM) 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


