#!gmake
#
# Copyright (C) 2000 Michal Kara.  All Rights Reserved.
# 
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Fondation.
# 
# This program is distributed in the hope that it would be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  Further, any license provided herein,
# whether implied or otherwise, is limited to this program in accordance with
# the express provisions of the GNU General Public License.  Patent licenses,
# if any, provided herein do not apply to combinations of this program with
# other product or programs, or any other product whatsoever.  This program is
# distributed without any warranty that the program is delivered free of the
# rightful claim of any third person by way of infringement or the like.  See
# the GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along with
# this program; if not, write the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston MA 02111-1307, USA.
#

TOPDIR = ../../..
include $(TOPDIR)/src/include/builddefs


IAM	= mysql
DOMAIN	= MYSQLD
TARGETS	= $(IAM)
CFILES	= mysql.c
SCRIPTS	= Install Remove
DFILES	= README
LSRCFILES= $(SCRIPTS) pmns help root Mysql.pmchart $(DFILES)

PMDADIR	= $(PCP_PMDAS_DIR)/$(IAM)
PMCHART	= $(PCP_VAR_DIR)/config/pmchart

LDIRT	= domain.h *.o $(IAM).log pmda$(IAM) pmda_$(IAM).so $(TARGETS) \
	$(DFILES:%=%.post)
LLDLIBS	= -lpcp_pmda -lpcp -L/usr/local/lib/mysql -lmysqlclient

default: $(TARGETS) $(DFILES:%=%.post)

include $(BUILDRULES)

install: default
	$(INSTALL) -m 755 -d $(PMDADIR)
	$(INSTALL) -m 555 $(IAM) $(PMDADIR)/pmda$(IAM)
	$(INSTALL) -m 555 $(SCRIPTS) $(PMDADIR)
	$(INSTALL) -m 444 pmns help root domain.h $(PMDADIR)
	for df in `echo $(DFILES)`; do \
	    $(INSTALL) -m 444 $$df.post $(PMDADIR)/$$df; \
	done
	$(INSTALL) -m 755 -d $(PMCHART)
	$(INSTALL) -m 444 Mysql.pmchart $(PMCHART)/Mysql

$(IAM):	$(OBJECTS)

mysql.o: domain.h

domain.h:	../../pmns/stdpmid
	rm -f domain.h
	echo "/*" >domain.h
	echo " * built from $(PCP_VAR_DIR)/pmns/stdpmid" >>domain.h
	echo " */" >>domain.h
	$(PCP_AWK_PROG) < $< >> $@ '$$1=="#define" && $$2=="$(DOMAIN)" { print "#define $(DOMAIN) " $$3 }'
