# file: src/common/etc/Makefile
#
#  2001 OpenCA Group

TOP	= ../../..
include $(TOP)/Makefile.global-vars

SUBDIRS	= \
	bp		\
	database	\
	openssl		\
	rbac

ETC_DIRS = \
	access_control/		\
	bp/			\
	database/		\
	init.d/			\
	openssl/		\
	openssl/openssl/	\
	openssl/extfiles/	\
	rbac/			\
	rbac/cmds/		\
	scep/			\
	servers/

STATIC_FILES	= \

AC_FILES	= \
	config.xml	\
	log.xml		\
	token.xml	\
	loa.xml

TEMPLATE_FILES = \
	backup.xml.template	\
	ldap.xml.template	\
	menu.xml.template

FILES = $(STATIC_FILES) $(AC_FILES) $(TEMPLATE_FILES)

PROGS	= \
	configure_etc.sh	\
	openca_start.template	\
	openca_stop.template	\
	openca_rc               \
        utf8_latin1_selector.sh.template

#---- variable settings above, rules below ----

.PHONY:	default test install install-conf clean distclean

default::	openssl

test::

install::	$(etc_prefix)

install-conf::	$(FILES) $(PROGS)

install-conf:: $(ETC_DIRS)

install-conf::
		$(MAKE) $(SUBDIRS) SUBTARGET=install

clean distclean::
		$(MAKE) $(SUBDIRS) SUBTARGET=$@

$(etc_prefix)::
	@if [ -d $@ ]; then \
		echo "$@ already exists, skipping configuration"; \
	else \
		set -x; \
		$(MAKE) __install_dir USER=${httpd_user} GROUP=${httpd_group} DIR=$@; \
		$(MAKE) install-conf; \
	fi

$(ETC_DIRS)::
	$(MAKE) __install_dir USER=${httpd_user} GROUP=${httpd_group} DIR=$(etc_prefix)/$@

$(SUBDIRS)::
		cd $@ && $(MAKE) $(SUBTARGET)

$(FILES)::
		$(INSTALL) -o ${openca_user} -g ${openca_group} -m 644 $@ $(etc_prefix)/$@

$(PROGS)::
		$(INSTALL) -o ${openca_user} -g ${openca_group} -m 755 $@ $(etc_prefix)/$@

distclean::
		$(RM) $(AC_FILES)
