# @(#)makefile	1.5 99/04/01
#
# This is the makefile for building the installer bundle 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 ..\..\jdk-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.
#
# 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=..\..\jdk-image-win32
!ENDIF

!IF "$(INSTALL_NAME)" == ""
INSTALL_NAME=Java Development Kit
!ENDIF

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


###################### clean #############################
#
# Remove all produced files.
#
clean: 
	@del $(BUILDDIR)\jdk1_2_2-win.exe


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


###################### list_files ########################
#
# This is a very sensitive part of the makefile. It looks at all the files
# in the jdk-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::
	@echo Copying list.sh from ..\jre
	@cp "..\jre\list.sh" "$(MAKEDIR)"
	@cd $(MAKEDIR)

#
# Create the bin.fgl file
# 
	@echo Creating bin.fgl file
	@mkdir "$(TEMP)\jdk-image-win32"
	@cp -r "$(IMAGE)\bin" "$(TEMP)\jdk-image-win32\bin"
	@cd $(TEMP)\jdk-image-win32
	@sh $(MAKEDIR)\list.sh | sed s#/#\\#g >>"$(TEMP_INSTALL)\File Groups\bin.fgl"
	@chmod -R 777 "$(TEMP)\jdk-image-win32\bin"
	@rm -r "$(TEMP)\jdk-image-win32\bin"
	@cd $(MAKEDIR)


#
# Create the demos.fgl file
#
	@echo Creating demos.fgl file
	@cp -r "$(IMAGE)\demo" "$(TEMP)\jdk-image-win32\demo"
	@cd $(TEMP)\jdk-image-win32
	@sh $(MAKEDIR)\list.sh | sed s#/#\\#g >>"$(TEMP_INSTALL)\File Groups\demos.fgl"
	@chmod -R 777 "$(TEMP)\jdk-image-win32\demo"
	@rm -r "$(TEMP)\jdk-image-win32\demo"
	@cd $(MAKEDIR)


#
# Create the include.fgl file
#
	@echo Creating include.fgl file
	@cp -r "$(IMAGE)\include" "$(TEMP)\jdk-image-win32\include"
	@cd $(TEMP)\jdk-image-win32
	@sh $(MAKEDIR)\list.sh | sed s#/#\\#g >>"$(TEMP_INSTALL)\File Groups\include.fgl"
	@chmod -R 777 "$(TEMP)\jdk-image-win32\include"
	@rm -r "$(TEMP)\jdk-image-win32\include"
	@cd $(MAKEDIR)


#
# Create the include-old.fgl file
#
	@echo Creating include-old.fgl file
	@cp -r "$(IMAGE)\include-old" "$(TEMP)\jdk-image-win32\include-old"
	@cd $(TEMP)\jdk-image-win32
	@sh $(MAKEDIR)\list.sh | sed s#/#\\#g >>"$(TEMP_INSTALL)\File Groups\include-old.fgl"
	@chmod -R 777 "$(TEMP)\jdk-image-win32\include-old"
	@rm -r "$(TEMP)\jdk-image-win32\include-old
	@cd $(MAKEDIR)


#
# Create the jre.fgl file
#
	@echo Creating jre.fgl file
	@cp -r "$(IMAGE)\jre" "$(TEMP)\jdk-image-win32\jre"
	@cd $(TEMP)\jdk-image-win32
	@sh $(MAKEDIR)\list.sh | sed s#/#\\#g >>"$(TEMP_INSTALL)\File Groups\jre.fgl"
	@chmod -R 777 "$(TEMP)\jdk-image-win32\jre"
	@rm -r "$(TEMP)\jdk-image-win32\jre"
	@cd $(MAKEDIR)


#
# Create the lib.fgl file
#
	@echo Creating lib.fgl file
	@cp -r "$(IMAGE)\lib" "$(TEMP)\jdk-image-win32\lib"
	@cd $(TEMP)\jdk-image-win32
	@sh $(MAKEDIR)\list.sh | sed s#/#\\#g >>"$(TEMP_INSTALL)\File Groups\lib.fgl"
	@chmod -R 777 "$(TEMP)\jdk-image-win32\lib"
	@rm -r "$(TEMP)\jdk-image-win32\lib"
	@cd $(MAKEDIR)


###################### create_files ########################
#
# This section manually creates the files.fgl, shared.fgl
# and src.fgl which aren't created from the list_files target above.
#	
create_files::
#
# Copy copy the full image
#
	@rm -r "$(TEMP)\jdk-image-win32"
	@cp -r "$(IMAGE)" "$(TEMP)\jdk-image-win32"
	@cd $(MAKEDIR)


#
# Create the files.fgl file
#

	@echo Creating files.fgl file
	@echo [TopDir]>"$(TEMP_INSTALL)\File Groups\files.fgl"
	@echo File0=$(TEMP)\jdk-image-win32\README>>"$(TEMP_INSTALL)\File Groups\files.fgl"
	@echo File1=$(TEMP)\jdk-image-win32\LICENSE>>"$(TEMP_INSTALL)\File Groups\files.fgl"
	@echo File2=$(TEMP)\jdk-image-win32\COPYRIGHT>>"$(TEMP_INSTALL)\File Groups\files.fgl"
	@echo File3=$(TEMP)\jdk-image-win32\readme.html>>"$(TEMP_INSTALL)\File Groups\files.fgl"
	@echo.>>"$(TEMP_INSTALL)\File Groups\files.fgl"
	@echo [General]>>"$(TEMP_INSTALL)\File Groups\files.fgl"
	@echo Type=FILELIST>>"$(TEMP_INSTALL)\File Groups\files.fgl"
	@echo Version=1.00.000>>"$(TEMP_INSTALL)\File Groups\files.fgl"


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


#
# Create the src.fgl file
#
	@echo Creating src.fgl file
	@echo [TopDir]>"$(TEMP_INSTALL)\File Groups\src.fgl"
	@echo File0=$(TEMP)\jdk-image-win32\src.jar>>"$(TEMP_INSTALL)\File Groups\src.fgl"
	@echo.>>"$(TEMP_INSTALL)\File Groups\src.fgl"
	@echo [General]>>"$(TEMP_INSTALL)\File Groups\src.fgl"
	@echo Type=FILELIST>>"$(TEMP_INSTALL)\File Groups\src.fgl"
	@echo Version=1.00.000>>"$(TEMP_INSTALL)\File Groups\src.fgl"


###################### copy_files ######################
#
# Copy the necessary files from the jdk-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)\setupjdk.rul" "$(TEMP_INSTALL)\Script Files\setup.rul"
	@cp "$(MAKEDIR)\..\jre\jrescript.h" "$(TEMP_INSTALL)\Script Files\jrescript.h"
	@cp "$(MAKEDIR)\..\jre\jrescript.rul" "$(TEMP_INSTALL)\Script Files\jrescript.rul"
	@cp -r $(MAKEDIR)\string_tables\* "$(TEMP_INSTALL)\String Tables"
	@mv "$(TEMP_INSTALL)\String Tables\0404-Chinese-Taiwan" "$(TEMP_INSTALL)\String Tables\0404-Chinese (Taiwan)"
	@mv "$(TEMP_INSTALL)\String Tables\0804-Chinese-PRC" "$(TEMP_INSTALL)\String Tables\0804-Chinese (PRC)"
	@cp "$(MAKEDIR)\default.fdf" "$(TEMP_INSTALL)\File Groups"
	@cp "$(MAKEDIR)\jdk.ipr" "$(TEMP_INSTALL)\Java Development Kit.ipr"

	@echo Copying license files
	@cp "$(MAKEDIR)\..\license\license.txt" "$(TEMP_INSTALL)\Setup Files\Compressed Files\0009-English\OS Independent\license.txt"
	@cp "$(MAKEDIR)\..\license\license_jre.txt" "$(TEMP_INSTALL)\Setup Files\Compressed Files\0009-English\OS Independent\license_jre.txt"
	@cp "$(MAKEDIR)\..\license\license_ja.txt" "$(TEMP_INSTALL)\Setup Files\Compressed Files\0011-Japanese\OS Independent\license.txt"
	@cp "$(MAKEDIR)\..\license\license_jre_ja.txt" "$(TEMP_INSTALL)\Setup Files\Compressed Files\0011-Japanese\OS Independent\license_jre.txt"


###################### create_install ######################
# 
# Compile and build the current installation.
#
create_install: list_files create_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 jdk.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/#TEMP_INSTALL#/$(TEMP)/g>1.tmp
	@sed s/\\/\\\\/g 1.tmp >script.tmp
	@del 1.tmp
	@sed -f script.tmp jdk.pfw >temp.pfw
	@echo Creating the installation bundle
	"$(IPFW)\pftwwiz.exe" "$(MAKEDIR)\temp.pfw" -a -s
	@del "$(MAKEDIR)\temp.pfw"
	@del script.tmp


###################### jdk_bundle #########################
#
# Create jdk bundle through its dependency. Copy the bundle to the output 
# directory.
# 
jdk_bundle: create_bundle
	@mv "$(MAKEDIR)\jdk.exe" "$(BUILDDIR)\jdk1_2_2-win.exe"


###################### all ################################
# 
# THIS IS THE ONLY VALID TARGET (with clean). Copy the installation scripts
# and jdk-image-win32 directory to the TEMP directory.
# 
all: copy_install
	@nmake jdk_bundle 
	@echo Cleaning temporary files
	@chmod -R 777 "$(TEMP_INSTALL)"
	@chmod -R 777 "$(TEMP)\jdk-image-win32"
	@rm -r "$(TEMP_INSTALL)"
	@rm -r "$(TEMP)\jdk-image-win32"
	@del "$(MAKEDIR)\list.sh
