#! gmake
#
#           CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
#              NETSCAPE COMMUNICATIONS CORPORATION
# Copyright (C) 1996 Netscape Communications Corporation.  All Rights
# Reserved.  Use of this Source Code is subject to the terms of the
# applicable license agreement from Netscape Communications Corporation.
# The copyright notice(s) in this Source Code does not indicate actual or
# intended publication of this Source Code.
#
# Installer Makefile for db3.1 in Netscape

# In here, we say "source" for where the stuff is coming from,
# and "target" to talk about where its going to.

# Name of the module---could be in a header file

MODULE=db

LIBDBNAME=libdb31

# Stuff configuring the profile of this distribution process

target_debug_suffix:=_DBG.OBJ
target_opt_suffix:=_OPT.OBJ
source_dirname_prefix:=built/
source_dirname_debug_suffix:=-full
source_dirname_opt_suffix:=-optimize
source_platform_name:=$(PLATFORM)
ifndef TEST
ifndef OEM_BUILDS
##target_parent:=/share/builds/components/$(MODULE)
target_parent:=/h/argon/security/db31/ships/temp/$(MODULE)
else # OEM_BUILDS
#target_parent:=/share/builds/components/$(MODULE)/oem
target_parent:=/share/builds/components/$(MODULE)/oem
endif # OEM_BUILDS
else
ifeq (WINNT,$(PLATFORM))
# what is the whoami command on windows?
USER := dboreham
else
USER := $(shell whoami)
endif
target_parent:=/u/$(USER)/builds/components/$(MODULE)
endif
target_root:=$(target_parent)/$(VERSION)

# Stuff configuring this particular distribution operation (could be in an include file)

leaf_targets:=lib include bin
copy_headers:=db.h
ifeq (WINNT,$(PLATFORM))
copy_bins:=db_archive.exe db_checkpoint.exe db_recover.exe db_load.exe db_dump.exe db_deadlock.exe db_stat.exe db_printlog.exe
else
copy_bins:=db_archive db_checkpoint db_recover db_load db_dump db_deadlock db_stat db_printlog
endif
ifeq (WINNT,$(PLATFORM))
copy_libs:=$(LIBDBNAME).lib $(LIBDBNAME).dll libdbs.lib
else
ifeq (HPUX,$(PLATFORM))
copy_libs:=$(LIBDBNAME).sl libdbs.a
else
ifeq (AIX,$(PLATFORM))
copy_libs:=$(LIBDBNAME).so $(LIBDBNAME).exp libdbs.a
else
copy_libs:=$(LIBDBNAME).so libdbs.a
endif
endif
endif

# weirdness that's platform-specific

# We have a main target, which is a directory with stuff in it
# and we have link targets, which are symlinks to the main, created
# to keep builds on all versions of OSes happy.

ifeq (SOLARIS5.6,$(PLATFORM))
main_target:=SunOS5.6
endif
ifeq (SOLARIS5.5.1,$(PLATFORM))
main_target:=SunOS5.5.1
endif
ifeq (AIX,$(PLATFORM))
main_target:=AIX4.3
endif
ifeq (IRIX,$(PLATFORM))
main_target:=IRIX6.5
link_targets:=IRIX6.5_n32_PTH
endif
ifeq (HPUX,$(PLATFORM))
main_target:=HP-UXB.11.00
endif
ifeq (OSF1,$(PLATFORM))
main_target:=OSF1V4.0
endif
ifeq (WINNT,$(PLATFORM))
main_target:=WIN32
link_targets:=WINNT5.0 WINNT4.0
endif
ifeq (Linux2.1,$(PLATFORM))
main_target:=Linux2.1
link_targets:=Linux2.1_x86_glibc_PTH
endif
ifeq (Linux2.2,$(PLATFORM))
main_target:=Linux2.2
link_targets:=Linux2.2_x86_glibc_PTH
endif
ifeq (ReliantUNIX,$(PLATFORM))
main_target:=ReliantUNIX
link_targets:=ReliantUNIX5.4 ReliantUNIX5.43
endif
ifeq (SOLARISx86,$(PLATFORM))
main_target:=SunOS5.4_i86pc
link_targets:=SunOS5.5_i86pc SunOS5.5.1_i86pc
endif
ifeq (BSDI,$(PLATFORM))
main_target:=BSD_OS
link_targets:=BSD_OS3.0 BSDI3.0
endif
ifeq (SCOOS,$(PLATFORM))
main_target:=SCOOS
link_targets:=SCOOS5.0
endif
ifeq (UnixWare,$(PLATFORM))
main_target:=UnixWare
link_targets:=UnixWare5 UnixWare7
endif

# If you put anything which is platform-specific after this line, I will come and personally kill you.
# ...and I'll help him.

# makeup some helper variables

source_debug_root:=$(source_dirname_prefix)$(PLATFORM)$(source_dirname_debug_suffix)
source_opt_root:=$(source_dirname_prefix)$(PLATFORM)$(source_dirname_opt_suffix)
target_debug_root:=$(target_root)/$(main_target)$(target_debug_suffix)
target_opt_root:=$(target_root)/$(main_target)$(target_opt_suffix)

.PHONY: verify_params make_target_dirs clean $(main_target) $(link_targets) $(leaf_targets) $(copy_headers) $(copy_bins)

all:
	@echo No default target for this makefile, please specify target "dist"

dist: verify_params make_target_dirs copy_files

latest:	
	rm -f $(target_parent)/latest
	ln -s $(target_root) $(target_parent)/latest

# Check that the parameters are OK (important, since we're copying and deleting files onto servers)

verify_params:
ifdef VERSION
ifdef PLATFORM
	@echo Running \"$(MODULE)\" release \"$(VERSION)\" for platform \"$(PLATFORM)\"
else
	@echo You must specify PLATFORM on the command line.
	exit 1
endif
else
	@echo You must specify VERSION on the command line.
	exit 1
endif

# Rules for making the target directories and links

make_target_dirs: $(leaf_targets)

$(target_root):
	mkdir -p $(target_root)
	mkdir -p $(target_root)/src

$(main_target): $(target_root)
	mkdir -p $(target_opt_root)
	mkdir -p $(target_debug_root)

$(link_targets): $(main_target)
	ln -s $(target_opt_root) $(target_root)/$@$(target_opt_suffix)
	ln -s $(target_debug_root) $(target_root)/$@$(target_debug_suffix)

$(leaf_targets): $(link_targets)
	mkdir -p $(target_opt_root)/$@
	mkdir -p $(target_debug_root)/$@

# Rules for copying the files

copy_files: $(copy_libs) $(copy_headers) $(copy_bins)

$(copy_headers): 
	cp $(source_opt_root)/$@ $(target_opt_root)/include/$@
	cp $(source_debug_root)/$@ $(target_debug_root)/include/$@

$(copy_bins):
	cp $(source_opt_root)/$@ $(target_opt_root)/bin/$@
	cp $(source_debug_root)/$@ $(target_debug_root)/bin/$@

$(copy_libs):
	cp $(source_opt_root)/$@ $(target_opt_root)/lib/$@
	cp $(source_debug_root)/$@ $(target_debug_root)/lib/$@

# Cleanup

clean: verify_params
	rm -rf $(target_root)

