# @(#)makefile	1.2 99/01/26
#
# This is the makefile for building the installer bundles after compiling
# the jdk sources. Listed below are some general notes in using this makefile.
#
# 1) Requires InstallShield 5.1 West and East which is defined as $(ISHIELD).
# 2) Requires InstallShield Package for the Web 2 which is defined as $(IPFW).
# 3) Requires MKS Toolkit (should be first thing in your PATH).
# 4) Assumes $(TEMP) is in c:\TEMP which is the temporary building directory.
# 5) Assumes $(IMAGE) is the newly built binaries in ..\..\jre-image-win32.
# 6) $(BUILDDIR) is two directories above this directory.
# 7) $(INSTALL_NAME) is the name of the InstallShield installation.
# 8) $(MAKEDIR) is this directory.
# 9) This build is not incremental as it builds the English first followed
#    by the International version.
#
# Unique target : all
#

# 
# Override the following environment variables if neccessary.
#
!IF "$(ISHIELD)" == ""
ISHIELD=C:\Program Files\InstallShield\InstallShield 5.1 Professional Edition
!MESSAGE No InstallShield 5.1 directory specified, using default $(ISHIELD)
!ENDIF

!IF "$(IPFW)" == ""
IPFW=C:\Program Files\InstallShield\PackageForTheWeb 2
!MESSAGE No PackageForTheWeb directory specified, using default $(IPFW)
!ENDIF

#
# These environment variables are relative paths to this makefile
# and shouldn't be changed.
#
!IF "$(BUILDDIR)" == ""
BUILDDIR=..\..
!ENDIF

!IF "$(IMAGE)" == ""
IMAGE=..\..\jre-image-win32
!ENDIF

!IF "$(INSTALL_NAME)" == ""
INSTALL_NAME=Java Runtime Environment
!ENDIF

# We rely on $(TEMP) being C:\TEMP
!IF "$(TEMP)" == ""
TEMP=C:\TEMP
!ENDIF
TEMP_INSTALL=$(TEMP)\$(INSTALL_NAME)

!IF "$(SIGN_FLAG)"== ""
SIGN_FLAG=1
!MESSAGE Signing required
!ENDIF

make_all: all

###################### clean #############################
#
# Remove all produced files.
#
clean: 
	@rm -f $(BUILDDIR)\jre1_2_2-win.exe
	@rm -f $(BUILDDIR)\jre1_2_2-win-i.exe
	@rm -f *.out *.tmp *.jar *.log errs errs.*
	cd crunch
	$(MAKE) /nologo clean
	@cd ..
	cd uncrunch
	$(MAKE) /nologo clean
	@cd ..

######################### rt.out ########################
#
# Rules for compacting JARs
#
rt.out: $(IMAGE)\lib\rt.jar
	cp $(IMAGE)\lib\rt.jar rt.jar
	@echo ==== Generating compacted rt.out file.
	@echo ==== This will take several minutes.
	@set CLASSPATH=crunch;
	$(BUILDDIR)\bin\java sun.tools.crunch.Crunch rt.jar > rt.log

jaws.out: $(IMAGE)\lib\jaws.jar
	cp $(IMAGE)\lib\jaws.jar jaws.jar
	@set CLASSPATH=crunch;
	$(BUILDDIR)\bin\java sun.tools.crunch.Crunch jaws.jar > jaws.log

i18n.out: $(IMAGE)\lib\i18n.jar
	cp $(IMAGE)\lib\i18n.jar i18n.jar
	@set CLASSPATH=crunch;
	$(BUILDDIR)\bin\java sun.tools.crunch.Crunch i18n.jar > i18n.log


###################### copy_install ######################
#
# Copy the installation script and the jre-image-win32 directory in $(TEMP).
#
copy_install: FORCE
	@echo Copying installation files	
	@if exist "$(TEMP_INSTALL)" rm -r "$(TEMP_INSTALL)"
	@if exist "$(TEMP)\jre-image-win32" rm -r "$(TEMP)\jre-image-win32"
	@cd $(TEMP)
	@mkdir "$(TEMP_INSTALL)"
	@cd "$(TEMP_INSTALL)"
	@tar -x -f "$(MAKEDIR)\jre_is5_1.tar"
	@cd $(MAKEDIR)
	@cp -r "$(IMAGE)" "$(TEMP)\jre-image-win32"

prune: rt.out jaws.out i18n.out FORCE
	@del $(TEMP)\jre-image-win32\lib\rt.jar
	@del $(TEMP)\jre-image-win32\lib\jaws.jar
	@del $(TEMP)\jre-image-win32\lib\i18n.jar
	@cd $(TEMP)\jre-image-win32\lib\fonts
	@mv LucidaSansRegular.ttf Lucida.xxx
	@rm -f *.ttf
	@mv Lucida.xxx LucidaSansRegular.ttf
	@cd $(TEMP)\jre-image-win32\lib\cmm
	@rm -f PYCC.pf
	@cd $(MAKEDIR)
	@mkdir $(TEMP)\jre-image-win32\tmp
	@cp rt.out jaws.out i18n.out uncrunch/uncrunch.exe $(TEMP)\jre-image-win32\tmp

###################### list_files ########################
#
# This is a very sensitive part of the makefile. It looks at all the files
# in the jre-image directory and produce a .fgl file that InstallShield 
# 5.1 is looking for the format of a .fgl file is as follow :
#	
#	[directory_name]
#	file0=..\bin\java.exe
#	file1=..\bin\javaw.exe
#	....
#	fileN=..\bin\awt.dll
#	SubDir0=classic
#	...
#	SubDirN=whatever
#
#	This is repeated for each directory/subdirectories.
#	At the end of the file, the following is added
#
#	[General]
#	Type=FILELIST
#	Version=1.00.000
#
list_files::
#
# Create the Program Executable Files.fgl file
#
	@cd $(TEMP)\jre-image-win32
	@sh $(MAKEDIR)\list.sh  | sed s#/#\\#g >>"$(TEMP_INSTALL)\File Groups\Program Executable Files.fgl"
	@cd $(MAKEDIR)

#
# Create the Shared DLLs.fgl file
#
	@chmod 777 $(TEMP)\jre-image-win32\bin\ActPanel.dll
	@chmod 777 $(TEMP)\jre-image-win32\bin\msvcrt.dll
	@echo [TopDir]>"$(TEMP_INSTALL)\File Groups\Shared DLLs.fgl"
	@echo File0=$(TEMP)\jre-image-win32\bin\msvcrt.dll>>"$(TEMP_INSTALL)\File Groups\Shared DLLs.fgl"
	@echo File1=$(TEMP)\jre-image-win32\bin\ActPanel.dll>>"$(TEMP_INSTALL)\File Groups\Shared DLLs.fgl"
	@echo.>>"$(TEMP_INSTALL)\File Groups\Shared DLLs.fgl"
	@echo [General]>>"$(TEMP_INSTALL)\File Groups\Shared DLLs.fgl"
	@echo Type=FILELIST>>"$(TEMP_INSTALL)\File Groups\Shared DLLs.fgl"
	@echo Version=1.00.000>>"$(TEMP_INSTALL)\File Groups\Shared DLLs.fgl"


###################### copy_files ######################
#
# Copy the necessary files from the jre-image and the custom files 
# into the installation	directory. We recreate the normal IS 5.1 directory
# structure.
#
copy_files::
	@echo Copying installation scripts
	@cp "$(MAKEDIR)\..\setup.bmp" "$(TEMP_INSTALL)\Setup Files\Uncompressed Files\0011-Japanese\OS Independent"
	@cp "$(MAKEDIR)\..\setup.bmp" "$(TEMP_INSTALL)\Setup Files\Uncompressed Files\0009-English\OS Independent"
	@cp "$(MAKEDIR)\..\license\license_jre.txt" "$(TEMP_INSTALL)\Setup Files\Compressed Files\0009-English\OS Independent\license.txt"
	@cp "$(MAKEDIR)\..\license\license_jre_ja.txt" "$(TEMP_INSTALL)\Setup Files\Compressed Files\0011-Japanese\OS Independent\license.txt"
	@cp "$(MAKEDIR)\jrescript.h" "$(TEMP_INSTALL)\Script Files"
	@cp "$(MAKEDIR)\jrescript.rul" "$(TEMP_INSTALL)\Script Files"
	@cp "$(MAKEDIR)\setupjre.rul" "$(TEMP_INSTALL)\Script Files\setup.rul"
	@cp -r $(MAKEDIR)\string_tables\* "$(TEMP_INSTALL)\String Tables"
	@cp "$(MAKEDIR)\default.fdf" "$(TEMP_INSTALL)\File Groups"


###################### create_install ######################
# 
# Compile and build the current installation.
#
create_install: list_files copy_files
	@echo Compiling Script
	@cd "$(TEMP_INSTALL)\Script Files"
	"$(ISHIELD)\Program\compile.exe" -i"$(ISHIELD)\Include" setup.rul -v0
	@cd $(MAKEDIR)
	@echo Creating the installation
	"$(ISHIELD)\Program\isbuild.exe" -p"$(TEMP_INSTALL)" -m"Default"


###################### create_bundle ###################### 
# 
# Launch the Package For the Web utility to create the self-executable 
# installation.  This is created using the jre12.pfw template PFW installation. 
# The location of the output file only has to be updated. This is done through 
# the sed statement.
#
create_bundle : create_install
	@echo s/#SIGN_FLAG#/$(SIGN_FLAG)/g>1.tmp
	@echo s/#TEMP_INSTALL#/$(TEMP)/g>>1.tmp
	@sed s/\\/\\\\/g 1.tmp >script.tmp
	@del 1.tmp
	@sed -f script.tmp jre12.pfw >temp.pfw
	@echo Creating the installation bundle
	"$(IPFW)\pftwwiz.exe" "$(MAKEDIR)\temp.pfw"  -a -s
	@del "$(MAKEDIR)\temp.pfw"
	@del script.tmp

###################### prepare_for_international ######################
#
# Called before the international installation starts. This is the time 
# to copy all international specific data.
#
prepare_for_international:
	@cp "$(MAKEDIR)\jre_international.ipr" "$(TEMP)\Java Runtime Environment\Java Runtime Environment.ipr"
	@cp "$(MAKEDIR)\default_international.mda" "$(TEMP_INSTALL)\media\default\default.mda

###################### prepare_for_english ######################
#
# Called before the international installation starts. This is the time for any
# tasks necessary to switch from the international install to the english only
# install. We overwrite the IS 5.1 installation file and remove all the files
# that are not necessary in the english install.
#
prepare_for_english:
	@cp "$(MAKEDIR)\jre_english.ipr" "$(TEMP)\Java Runtime Environment\Java Runtime Environment.ipr"
	@cp "$(MAKEDIR)\default_english.mda" "$(TEMP_INSTALL)\media\default\default.mda
	@rm -f $(TEMP)\jre-image-win32\tmp\i18n.out
	@rm -f $(TEMP)\jre-image-win32\lib\i18n.jar
	@rm -f $(TEMP)\jre-image-win32\lib\ext\iiimp.jar

###################### international_bundle ######################
#
# Create international bundle through its dependency. 
# Copy the bundle to the output directory.
#
international_bundle: prepare_for_international create_bundle
	@mv "$(MAKEDIR)\jre.exe" "$(BUILDDIR)\jre1_2_2-win-i.exe"
	@del "$(TEMP)\Java Runtime Environment\Java Runtime Environment.ipr"


###################### english_bundle ############################
#
# Create english bundle through its dependency. Copy the bundle to the 
# output directory.
#
english_bundle: prepare_for_english create_bundle
	@mv "$(MAKEDIR)\jre.exe" "$(BUILDDIR)\jre1_2_2-win.exe"
	@del "$(TEMP)\Java Runtime Environment\Java Runtime Environment.ipr"


###################### all ################################
# 
# THIS IS THE ONLY VALID TARGET (with clean). Copy the installation scripts
# and jre-image-win32 directory to the TEMP directory so we can delete/add
# files between the English and International installations. Do the two
# installations in succession.
# 
all: crunch uncrunch copy_install prune doit

doit: FORCE
	@nmake  international_bundle 
	@nmake  english_bundle 
	@echo Cleaning temporary files
	@chmod -R 777 "$(TEMP_INSTALL)"
	@chmod -R 777 "$(TEMP)\jre-image-win32"
	@rm -f -r "$(TEMP_INSTALL)"
	@rm -f -r "$(TEMP)\jre-image-win32"

# Auxiliary target.  This may not be necessary.
big-jre: crunch uncrunch copy_install doit

crunch: FORCE
	cd crunch
	$(MAKE) /nologo all
	@cd ..

uncrunch: FORCE
	cd uncrunch
	$(MAKE) /nologo all
	@cd ..


# Test that crunch and uncrunch are behaving correctly.
# Warning: This will take about 10 hours to run!!!
test: crunch uncrunch rt.out jaws.out i18n.out
	uncrunch\uncrunch rt.out rt2.jar
	uncrunch\uncrunch.exe jaws.out jaws2.jar
	uncrunch\uncrunch.exe i18n.out i18n2.jar
	sh compare.sh ../../classes jaws.jar jaws2.jar
	sh compare.sh ../../classes i18n.jar i18n2.jar
	sh compare.sh ../../classes rt.jar rt2.jar

FORCE:

