#
# 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 for AdminServer 5.x, Console SDK 5.x, and SetupUtil 4.x
#

# 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 $(BUILD_ROOT)/nsconfig.mk

ifeq ($(INTERNAL_BUILD), 1)
COMPONENT_DEPENDENCIES = $(LDAPSDK_DEP) 
endif

all: buildAndPkgInstaller

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

ifeq ($(INTERNAL_BUILD), 1)
$(RELTOOLSPATH): 
	cd $(ABS_ROOT_PARENT) ; cvs co RelToolsLite

brandSetupUtil: $(RELTOOLSPATH)
	@echo ==== Branding SetupUtil ==========
ifeq ($(ARCH), WINNT)
	$(PERL5) $(RELTOOLSPATH)/brandver.pl -i branding/rh/brandverNT.dat
else
	$(PERL5) $(RELTOOLSPATH)/brandver.pl -i branding/rh/brandver.dat
endif

debrandSetupUtil: $(RELTOOLSPATH)
	@echo ==== Branding SetupUtil ==========
ifeq ($(ARCH), WINNT)
	$(PERL5) $(RELTOOLSPATH)/brandver.pl -i branding/fedora/brandverNT.dat
else
	$(PERL5) $(RELTOOLSPATH)/brandver.pl -i branding/fedora/brandver.dat
	$(PERL5) $(RELTOOLSPATH)/brandver.pl -i branding/fedora/spec.dat
endif
	@echo ==== Finished Branding SetupUtil ==========

normalizeSetupUtil: $(RELTOOLSPATH)
	@echo ==== Normalizing SetupUtil ==========
	$(PERL5) $(RELTOOLSPATH)/brandver.pl -i branding/fedora/normalize.dat 
	@echo ==== Finished Normalizing SetupUtil ==========

endif

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

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

buildnum:
	if test ! -d $(NSPLATFORM_DIR); then mkdir $(NSPLATFORM_DIR); fi;
	$(PERL5) buildnum.pl -p $(NSPLATFORM_DIR)

buildAndPkgInstaller: buildInstaller pkgInstaller

pkgInstaller: infozip
ifneq ($(ARCH), WINNT)
	cd installer; $(MAKE) BUILD_MODULE=SetupSDK $(MFLAGS) package
	@echo
	@echo ============ Finished - UNIX Installer Package   ===================
else
	cd installer; $(MAKE) BUILD_MODULE=SetupSDK $(MFLAGS) package
	cd installer/nt; $(MAKE) $(MFLAGS) package
	@echo
	@echo ============ Finished - Windows NT Setup Package ===================
endif

buildInstaller: buildnum pumpkin $(DIRVER_H) components
	@echo
	@echo ==== Starting Server Installer Build ==========
	@echo
	$(MAKE) BUILD_MODULE=SetupSDK $(MFLAGS) installerSDK
	$(MAKE) BUILD_MODULE=SetupSDK $(MFLAGS) installerBIN
	@echo ==== Finished Server Installer Build ==========

installerSDK:
ifneq ($(ARCH), WINNT)
	cd installer/lib;  $(MAKE) $(MFLAGS) PERL5=$(PERL5)
	cd installer/unix/lib; $(MAKE) $(MFLAGS)
else
	cd installer/nt; $(MAKE) $(MFLAGS)
endif

$(DIRVER_H):
ifeq ($(ARCH), WINNT)
	if test ! -d $(DIRVERDIR); then mkdir -p $(DIRVERDIR); fi;
	$(PERL5) dirver.pl -v "$(SETUP_VERSION)" -o $@
endif

# Applicable to UNIX only
installerBIN:
ifneq ($(ARCH), WINNT)
	cd installer/unix; $(MAKE) $(MFLAGS)
endif

redhat-setuputil.spec: setuputil.spec.tmpl branding/rh/brandver.dat $(RELTOOLSPATH)/brandver.pl
	sed -e s/@PLATFORM@/$(NSOS_ARCH)$(NSOS_RELEASE)/g setuputil.spec.tmpl > $@
	$(RELTOOLSPATH)/brandver.pl -i branding/rh/spec.dat $@
	mv $@ $(OBJDIR)

fedora-setuputil.spec: 
	sed -e s/@PLATFORM@/$(NSOS_ARCH)$(NSOS_RELEASE)/g $@.tmpl > $@
	mv $@ $(OBJDIR)
