# =====
# Makefile for auto packing Firefox Portable CE
#   written by hobbyscripter<hobbyscripter@gmail.com>
# =====

# =====
# Usage
# =====
# 1. Copy a copy of makefile to the parent directory of
#    Firefox Portable Directory.
# 2. Make these command in your %path%: "make.exe", 
#    "makensis.exe", "7z.exe". (Note: You may set absolute
#    path at Variables Section, too)
# 3. Type this command in the command prompt: make.

# =====
# Variables
# =====
# Version Control
Version=0.0.0.0
SourceCodeStatus=unstable
PackTime=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%
ReleaseStatus=release
Edition=CE

# Source/Target
CurrentDir=%CD%
SourceDir=$(CurrentDir)\SID_PFx
TempDir=FirefoxPortableCE
TargetFile=$(CurrentDir)\$(Version)-$(SourceCodeStatus)-$(PackTime)@$(ReleaseStatus).zip

# Required Software
NSISMAKE=makensis.exe
SEVENZIP=7z.exe

# =====
# Rules
# =====
all: launcher copy compress launcher

# -----
# Compress File
compress: copy
	$(SEVENZIP) a -tzip "$(TargetFile)" "$(TempDir)"
	rmdir /S /Q "$(TempDir)"

# -----
# Copy File
# -----
copy: createdir
	$(SEVENZIP) a -t7z -mx0 "$(TempDir)\temp.7z" "$(SourceDir)\Other\*"
	$(SEVENZIP) x "$(TempDir)\temp.7z" * -r -o"$(TempDir)\Other"
	del "$(TempDir)\temp.7z"
	copy "$(SourceDir)\App\DefaultData\defaultdata_readme.txt" "$(TempDir)\App\DefaultData"
	copy "$(SourceDir)\App\firefox\firefox_readme.txt" "$(TempDir)\App\firefox"
	copy "$(SourceDir)\App\readme.txt" "$(TempDir)\App"
	copy "$(SourceDir)\Data\codetab\cp950.dat" "$(TempDir)\Data\codetab"
	copy "$(SourceDir)\Data\plugins\plugins_readme.txt" "$(TempDir)\Data\plugins"
	copy "$(SourceDir)\Data\profile\profile_readme.txt" "$(TempDir)\Data\profile"
	copy "$(SourceDir)\FirefoxPortableCE.exe" "$(TempDir)"
	copy "$(SourceDir)\HelpCHT.html" "$(TempDir)"

# -----
# Create Temporary Directory
# -----
createdir:
	if exist "$(TempDir)" rmdir /S /Q "$(TempDir)"
	mkdir "$(TempDir)"
	mkdir "$(TempDir)\App"
	mkdir "$(TempDir)\App\DefaultData"
	mkdir "$(TempDir)\App\firefox"
	mkdir "$(TempDir)\Data"
	mkdir "$(TempDir)\Data\codetab"
	mkdir "$(TempDir)\Data\plugins"
	mkdir "$(TempDir)\Data\profile"
	mkdir "$(TempDir)\Other"

# -----
# Compile Launcher
# -----
launcher: createdir
	$(NSISMAKE) "/XSetCompressor LZMA" "$(SourceDir)\Other\FirefoxPortableSource\FirefoxPortable$(Edition).nsi"
	move "$(SourceDir)\Other\FirefoxPortableSource\FirefoxPortable$(Edition).exe" "$(TempDir)\FirefoxPortable$(Edition).exe"