#
# BEGIN COPYRIGHT BLOCK
# Copyright (C) 2001 Sun Microsystems, Inc.  Used by permission.
# Copyright (C) 2005 Red Hat, Inc.
# All rights reserved.
# 
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation version
# 2.1 of the License.
#                                                                                  
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#                                                                                  
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# END COPYRIGHT BLOCK
#
#
#   Makefile to build/package Admin Util
#

# Relative path to the top of the build tree (i.e., where the DS source tree is checked out)
BUILD_ROOT=.

# define COMPONENT_DEPS here so that components are pulled in this makefile
COMPONENT_DEPS := 1

include nsconfig.mk

all: buildAndPkgAdminUtil

help:
	@echo
	@echo The following are build targets that you can choose from:
	@echo
	@echo "   gmake buildAdminUtil"
	@echo "   gmake pkgAdminUtil"
	@echo "   gmake with no arguments will do buildAndPkgAdminUtil, which "
	@echo "         is usually what you want to do"
	@echo

ifeq ($(INTERNAL_BUILD), 1)
COMPONENT_DEPENDENCIES = $(NSPR_DEP) $(SECURITY_DEP) $(ICU_DEP) $(LDAPSDK_DEP) 

$(RELTOOLS): 
	cd $(ABS_ROOT_PARENT) ; cvs co RelToolsLite

versionAdminUtil: $(RELTOOLS)
	@echo ==== Versioning AdminUtil ==========
	$(PERL5) $(RELTOOLSPATH)/brandver.pl -i branding/fedora/brandver.dat
	@echo ==== Finished Versioning AdminUtil ==========

normalizeAdminUtil: $(RELTOOLS)
	@echo ==== Normalizing Admin Util ==========
	$(PERL5) $(RELTOOLSPATH)/brandver.pl -i branding/fedora/normalize.dat
	@echo ==== Finished Normalizing Admin Util ==========
endif

components: $(COMPONENT_DEPENDENCIES)
	-@echo "The components are up to date"

pumpkin:
	$(PERL5) pumpkin.pl $(PUMPKIN_AGE) pumpkin.dat

buildnum:
	if test ! -d $(NSPLATFORM_ID); then mkdir $(NSPLATFORM_ID); fi;
	$(PERL5) buildnum.pl -p $(NSPLATFORM_ID)
	@mybuildnum=`cat $(NSPLATFORM_ID)/buildnum.dat`; \
	sed -e "s/\(ADMSDK_BUILDNUM\).*/\1 $$mybuildnum/" include/version.h > include/version.h.tmp; \
	mv include/version.h.tmp include/version.h

$(DIRVER_H):
	if test ! -d $(DIRVERDIR); then mkdir -p $(DIRVERDIR); fi;
	$(PERL5) dirver.pl -v "$(ADMSDK_VERSION)" -o $@

buildAndPkgAdminUtil:   buildAdminUtil pkgAdminUtil

buildAdminUtil:   buildnum pumpkin $(DIRVER_H) components
	@echo
	@echo ==== Building AdminUtil  ==========
	@echo
	cd lib/libadminutil; 	$(MAKE)
	cd lib/libadmsslutil; 	$(MAKE)
	@echo ============== Finished ============================

pkgAdminUtil:
	@echo
	@echo ==== Start Admin Util Package ==========
	@echo
	$(MAKE) -f pkgadminutil.mk
	@echo ==== Finished  Admin Util Package ==========
	@echo

$(ADMINUTILSPEC):
	sed -e 's/@PLATFORM@/$(NSOS_ARCH)$(NSOS_RELEASE)/g' \
		-e 's/@GEN-VERSION@/1.0/g' \
		-e 's/@GEN-VERSION-NODOT@/10/g' \
		-e 's/@PRODUCT-NAME@/Admin Util/g' \
		-e 's/@PRODUCT-SHORT-NAME@/adminutil/g' \
		-e 's+@COMPANY-URL@+http://directory.fedora.redhat.com/+g' \
		adminutil.spec.tmpl > $@
