!include "MUI2.nsh"

;--------------------------------
;Interface Configuration

  !define MUI_HEADERIMAGE
  !define MUI_HEADERIMAGE_BITMAP "@CMAKE_HOME_DIRECTORY@\doc\webcruft\simgrid_logo_win_2011.bmp" ; optional
  !define MUI_ABORTWARNING

;--------------------------------
;Pages

  !insertmacro MUI_PAGE_LICENSE "@CMAKE_HOME_DIRECTORY@\LICENSE-LGPL-2.1"
  !insertmacro MUI_PAGE_COMPONENTS
  !insertmacro MUI_PAGE_DIRECTORY
  !insertmacro MUI_PAGE_INSTFILES
  !insertmacro MUI_PAGE_FINISH
  
  !insertmacro MUI_UNPAGE_CONFIRM
  !insertmacro MUI_UNPAGE_INSTFILES
  !insertmacro MUI_UNPAGE_FINISH

;--------------------------------
;Languages
  !insertmacro MUI_LANGUAGE "English"
  !insertmacro MUI_LANGUAGE "French"
;--------------------------------

Name "Simgrid"
outFile "SimGrid-@SIMGRID_VERSION_MAJOR@.@SIMGRID_VERSION_MINOR@.@SIMGRID_VERSION_PATCH@_SGjava_@NSIS_WIN_VERSION@@BIN_EXE@"
Icon "@CMAKE_HOME_DIRECTORY@\doc\webcruft\SGicon.ico"

RequestExecutionLevel admin

# set the default installation directory
InstallDir c:\SimGrid@SIMGRID_VERSION_MAJOR@.@SIMGRID_VERSION_MINOR@.@SIMGRID_VERSION_PATCH@

Section "Libraries and Headers" LibSection

	setOutPath $INSTDIR
	file @CMAKE_HOME_DIRECTORY@\AUTHORS
	file @CMAKE_HOME_DIRECTORY@\Changelog
	file @CMAKE_HOME_DIRECTORY@\COPYING
	file @CMAKE_HOME_DIRECTORY@\LICENSE-LGPL-2.1
	file @CMAKE_HOME_DIRECTORY@\NEWS

	# install lib
	CreateDirectory $INSTDIR\lib
	setOutPath $INSTDIR\lib
	file lib\libsimgrid.dll
	file lib\libsimgrid.def
	
	#install headers
	CreateDirectory  $INSTDIR\include
	setOutPath $INSTDIR\include
	file @CMAKE_HOME_DIRECTORY@\include\xbt.h
	file include\simgrid_config.h
	
	CreateDirectory  $INSTDIR\include\xbt
	setOutPath $INSTDIR\include\xbt
	file @CMAKE_HOME_DIRECTORY@\include\xbt\misc.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\sysdep.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\virtu.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\str.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\strbuff.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\hash.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\function_types.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\asserts.h 
	file @CMAKE_HOME_DIRECTORY@\include\xbt\ex.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\log.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\module.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\mallocator.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\dynar.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\dict.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\set.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\heap.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\graph.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\fifo.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\swag.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\lib.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\matrix.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\peer.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\config.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\cunit.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\graphxml_parse.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\graphxml.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\synchro_core.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\queue.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\setset.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\mmalloc.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\parmap.h
	file @CMAKE_HOME_DIRECTORY@\include\xbt\automaton.h
    file @CMAKE_HOME_DIRECTORY@\include\xbt\xbt_os_thread.h
    file @CMAKE_HOME_DIRECTORY@\include\xbt\RngStream.h

	CreateDirectory  $INSTDIR\include\simgrid
	setOutPath $INSTDIR\include\simgrid
	file @CMAKE_HOME_DIRECTORY@\include\simgrid\platf.h
	file @CMAKE_HOME_DIRECTORY@\include\simgrid\modelchecker.h
	file @CMAKE_HOME_DIRECTORY@\include\simgrid\simix.h

	CreateDirectory  $INSTDIR\include\msg
	setOutPath $INSTDIR\include\msg
	file @CMAKE_HOME_DIRECTORY@\include\msg\msg.h
	file @CMAKE_HOME_DIRECTORY@\include\msg\datatypes.h
	
	CreateDirectory  $INSTDIR\include\simdag
	setOutPath $INSTDIR\include\simdag
	file @CMAKE_HOME_DIRECTORY@\include\simdag\simdag.h
	file @CMAKE_HOME_DIRECTORY@\include\simdag\datatypes.h

	
	CreateDirectory  $INSTDIR\include\surf
	setOutPath $INSTDIR\include\surf
	file @CMAKE_HOME_DIRECTORY@\include\surf\surfxml_parse.h
	file @CMAKE_HOME_DIRECTORY@\include\surf\simgrid_dtd.h
	file @CMAKE_HOME_DIRECTORY@\include\surf\surf_routing.h
	
	CreateDirectory  $INSTDIR\include\instr
	setOutPath $INSTDIR\include\instr
	file @CMAKE_HOME_DIRECTORY@\include\instr\instr.h
	
SectionEnd
Section "Binaries" BinSection	
	
	# insatll bin
	CreateDirectory $INSTDIR\bin
	setOutPath $INSTDIR\bin
	file bin\colorize
	file bin\graphicator@BIN_EXE@
	file bin\simgrid_update_xml

	
SectionEnd
Section "Documentation" DocSection	
	
	# install doc
	CreateDirectory $INSTDIR\doc
	setOutPath $INSTDIR\doc
	file /nonfatal /r @CMAKE_HOME_DIRECTORY@\doc\html
	# create a shortcut in the start menu programs directory
	CreateDirectory "$SMPROGRAMS\SimGrid @SIMGRID_VERSION_MAJOR@.@SIMGRID_VERSION_MINOR@.@SIMGRID_VERSION_PATCH@"
	createShortCut  "$SMPROGRAMS\SimGrid @SIMGRID_VERSION_MAJOR@.@SIMGRID_VERSION_MINOR@.@SIMGRID_VERSION_PATCH@\Documentation.lnk"	"$INSTDIR\doc\html\index.html"
	createShortCut  "$SMPROGRAMS\SimGrid @SIMGRID_VERSION_MAJOR@.@SIMGRID_VERSION_MINOR@.@SIMGRID_VERSION_PATCH@\Website.lnk"	"http://simgrid.gforge.inria.fr/"
	
SectionEnd
Section "Examples" ExamplesSection	

	CreateDirectory $INSTDIR\examples
	setOutPath $INSTDIR\examples
	
	#install examples for platforms
	file /r @CMAKE_HOME_DIRECTORY@\examples\platforms
	
	# install example HelloWorld
	file /r @CMAKE_HOME_DIRECTORY@\doc\HelloWorld
		
	# install example MasterSlave
	CreateDirectory $INSTDIR\examples\MasterSlave
	setOutPath $INSTDIR\examples\MasterSlave
	file @CMAKE_HOME_DIRECTORY@\examples\msg\masterslave\masterslave_forwarder.c
	file @CMAKE_HOME_DIRECTORY@\examples\msg\masterslave\deployment_masterslave_forwarder.xml
	file @CMAKE_HOME_DIRECTORY@\examples\msg\msg_platform.xml
	file @CMAKE_HOME_DIRECTORY@\doc\HelloWorld\CMakeLists.txt

	# create shortcuts in the start menu programs directory
	CreateDirectory "$SMPROGRAMS\SimGrid @SIMGRID_VERSION_MAJOR@.@SIMGRID_VERSION_MINOR@.@SIMGRID_VERSION_PATCH@\Examples\"
	createShortCut  "$SMPROGRAMS\SimGrid @SIMGRID_VERSION_MAJOR@.@SIMGRID_VERSION_MINOR@.@SIMGRID_VERSION_PATCH@\Examples\HelloWorld project.lnk"	"$INSTDIR\examples\HelloWorld"
	createShortCut  "$SMPROGRAMS\SimGrid @SIMGRID_VERSION_MAJOR@.@SIMGRID_VERSION_MINOR@.@SIMGRID_VERSION_PATCH@\Examples\MasterSlave project.lnk"	"$INSTDIR\examples\MasterSlave"
	
SectionEnd

Section "Java Bindings" JavaSection	
	# install java library and examples
	CreateDirectory $INSTDIR\examples\simgrid-java
	setOutPath $INSTDIR\lib
	file /nonfatal "lib\simgrid-java.dll"
	file /nonfatal "lib\simgrid-java.def"
	file /nonfatal "simgrid.jar"
	setOutPath $INSTDIR\examples\simgrid-java
	file /nonfatal /r ".\examples\"
	# create shortcuts in the start menu programs directory
	createShortCut  "$SMPROGRAMS\SimGrid @SIMGRID_VERSION_MAJOR@.@SIMGRID_VERSION_MINOR@.@SIMGRID_VERSION_PATCH@\Examples\Java project.lnk"	"$INSTDIR\examples\simgrid-java"
	# create a popup box, with an OK button"
	messageBox MB_OK "WARNING! Please add to your environment variable CLASSPATH value '$INSTDIR\lib\simgrid.jar;.' before executing Simgrid classes."
SectionEnd

Section "SMPI Library" SMPISection
	setOutPath $INSTDIR\bin
	file bin\smpicc
	file bin\smpif2c
	file bin\smpiff
	file bin\smpirun
	file bin\smpif90
	
    setOutPath $INSTDIR\lib
	
	CreateDirectory  $INSTDIR\include\smpi
	setOutPath $INSTDIR\include\smpi
	file @CMAKE_HOME_DIRECTORY@\include\smpi\smpi.h
	file @CMAKE_HOME_DIRECTORY@\include\smpi\mpi.h
	file @CMAKE_HOME_DIRECTORY@\include\smpi\smpi_cocci.h
	file @CMAKE_HOME_DIRECTORY@\include\smpi\smpi_main.h
	file include\smpi\mpif.h
	file include\smpi\smpif.h
	
	CreateDirectory $INSTDIR\examples\smpi
	file /r @CMAKE_HOME_DIRECTORY@\examples\smpi\tracing
	file /r @CMAKE_HOME_DIRECTORY@\examples\smpi\replay
	setOutPath $INSTDIR\examples\smpi
	file @CMAKE_HOME_DIRECTORY@\examples\smpi\bcbench.c
	file @CMAKE_HOME_DIRECTORY@\examples\smpi\mvmul.c
	file /r @CMAKE_HOME_DIRECTORY@\examples\smpi\mc
	file @CMAKE_HOME_DIRECTORY@\examples\smpi\hostfile
	file @CMAKE_HOME_DIRECTORY@\examples\msg\small_platform_with_routers.xml
	file @CMAKE_HOME_DIRECTORY@\examples\smpi\CMakeLists.txt
SectionEnd

# default section start
section	
	# define uninstaller name
	writeUninstaller $INSTDIR\uninstaller@BIN_EXE@

	# create a shortcut in the start menu programs directory
	CreateDirectory "$SMPROGRAMS\SimGrid @SIMGRID_VERSION_MAJOR@.@SIMGRID_VERSION_MINOR@.@SIMGRID_VERSION_PATCH@"
	createShortCut  "$SMPROGRAMS\SimGrid @SIMGRID_VERSION_MAJOR@.@SIMGRID_VERSION_MINOR@.@SIMGRID_VERSION_PATCH@\Uninstall simgrid.lnk" "$INSTDIR\uninstaller@BIN_EXE@"

	# Include for some of the windows message defines
	!include "winmessages.nsh"
	# HKLM (all users) vs HKCU (current user) defines
	!define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
	!define env_hkcu 'HKCU "Environment"'
	# Set Variables
	WriteRegExpandStr ${env_hkcu} SIMGRID_ROOT $INSTDIR
	WriteRegExpandStr ${env_hkcu} SIMGRID_VERSION @SIMGRID_VERSION_MAJOR@.@SIMGRID_VERSION_MINOR@.@SIMGRID_VERSION_PATCH@
	
	WriteRegStr HKCU "SOFTWARE\SimGrid" "Version" "@SIMGRID_VERSION_MAJOR@.@SIMGRID_VERSION_MINOR@.@SIMGRID_VERSION_PATCH@"
	WriteRegStr HKCU "SOFTWARE\SimGrid" "InstallPath" "$INSTDIR"
	
	# create a popup box, with an OK button"
	messageBox MB_OK "WARNING! Please add to your environment variable PATH value '$INSTDIR\lib;$INSTDIR\GnuWin32\bin' before executing Simgrid binaries."
	
	SetRebootFlag false

# default section end
sectionEnd

LangString DESC_LibSection 		${LANG_ENGLISH} "Install Simgrid libraries with associated headers."
LangString DESC_BinSection 		${LANG_ENGLISH} "Install some useful tools for Simgrid."
LangString DESC_DocSection 		${LANG_ENGLISH} "Generated (doxygen) documentation."
LangString DESC_ExamplesSection ${LANG_ENGLISH} "Simgrid's HelloWorld example and some classical platforms."
LangString DESC_JAVASection 	${LANG_ENGLISH} "Install the Java binding and examples."
LangString DESC_SMPISection 	${LANG_ENGLISH} "Install the SMPI library, headers, and examples."


LangString DESC_LibSection 		${LANG_FRENCH} 	"Installer les librairies Simgrid et leurs Ent�tes."
LangString DESC_BinSection 		${LANG_FRENCH} 	"Installer les outils optionnels."
LangString DESC_DocSection 		${LANG_FRENCH} 	"Installer la documentation."
LangString DESC_ExamplesSection ${LANG_FRENCH} 	"Installer un exemple 'HelloWorld' et des fichiers de plate-formes types."
LangString DESC_JAVASection 	${LANG_FRENCH}  "Installer la librairie Simgrid-java et les exemples."
LangString DESC_SMPISection 	${LANG_FRENCH}  "Installer la librairie SMPI, ses en-t�tes, et ses exemples."

!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
  !insertmacro MUI_DESCRIPTION_TEXT ${LibSection} 		$(DESC_LibSection)
  !insertmacro MUI_DESCRIPTION_TEXT ${BinSection} 		$(DESC_BinSection)
  !insertmacro MUI_DESCRIPTION_TEXT ${DocSection} 		$(DESC_DocSection)
  !insertmacro MUI_DESCRIPTION_TEXT ${ExamplesSection} 	$(DESC_ExamplesSection)
  !insertmacro MUI_DESCRIPTION_TEXT ${JAVASection} 		$(DESC_JAVASection)
  !insertmacro MUI_DESCRIPTION_TEXT ${SMPISection} 		$(DESC_SMPISection)
!insertmacro MUI_FUNCTION_DESCRIPTION_END

# create a section to define what the uninstaller does.
# the section will always be named "Uninstall"
section "Uninstall"

	# always delete uninstaller first
	delete $INSTDIR\uninstaller@BIN_EXE@

	# delete installed libs
	delete $INSTDIR\lib\libsimgrid.dll
	delete $INSTDIR\lib\libsimgrid.def

	# delete installed bin
	delete $INSTDIR\bin\colorize
	delete $INSTDIR\bin\graphicator@BIN_EXE@
	delete $INSTDIR\bin\simgrid_update_xml
	delete $INSTDIR\bin\smpicc
	delete $INSTDIR\bin\smpif2c
	delete $INSTDIR\bin\smpiff
	delete $INSTDIR\bin\smpirun
	delete $INSTDIR\bin\tesh
	
	# delete installed headers
	delete $INSTDIR\include\xbt.h
	delete $INSTDIR\include\simgrid_config.h
	delete $INSTDIR\include\xbt\misc.h
	delete $INSTDIR\include\xbt\sysdep.h
	delete $INSTDIR\include\xbt\virtu.h
	delete $INSTDIR\include\xbt\str.h
	delete $INSTDIR\include\xbt\strbuff.h
	delete $INSTDIR\include\xbt\hash.h
	delete $INSTDIR\include\xbt\function_types.h
	delete $INSTDIR\include\xbt\asserts.h 
	delete $INSTDIR\include\xbt\ex.h
	delete $INSTDIR\include\xbt\log.h
	delete $INSTDIR\include\xbt\module.h
	delete $INSTDIR\include\xbt\mallocator.h
	delete $INSTDIR\include\xbt\dynar.h
	delete $INSTDIR\include\xbt\dict.h
	delete $INSTDIR\include\xbt\set.h
	delete $INSTDIR\include\xbt\heap.h
	delete $INSTDIR\include\xbt\graph.h
	delete $INSTDIR\include\xbt\fifo.h
	delete $INSTDIR\include\xbt\swag.h
	delete $INSTDIR\include\xbt\lib.h
	delete $INSTDIR\include\xbt\matrix.h
	delete $INSTDIR\include\xbt\peer.h
	delete $INSTDIR\include\xbt\config.h
	delete $INSTDIR\include\xbt\cunit.h
	delete $INSTDIR\include\xbt\graphxml_parse.h
	delete $INSTDIR\include\xbt\graphxml.h
	delete $INSTDIR\include\xbt\time.h
	delete $INSTDIR\include\xbt\synchro.h
	delete $INSTDIR\include\xbt\synchro_core.h
	delete $INSTDIR\include\xbt\queue.h
	delete $INSTDIR\include\xbt\setset.h
	delete $INSTDIR\include\xbt\mmalloc.h
	delete $INSTDIR\include\xbt\replay_trace_reader.h
	delete $INSTDIR\include\xbt\parmap.h
	delete $INSTDIR\include\xbt\socket.h
	delete $INSTDIR\include\xbt\file_stat.h

	delete $INSTDIR\include\simgrid\platf.h
	delete $INSTDIR\include\simgrid\modelchecker.h
	delete $INSTDIR\include\simgrid\simix.h

	delete $INSTDIR\include\msg\msg.h
	delete $INSTDIR\include\msg\datatypes.h	
	delete $INSTDIR\include\simdag\simdag.h
	delete $INSTDIR\include\simdag\datatypes.h
	delete $INSTDIR\include\smpi\smpi.h
	delete $INSTDIR\include\smpi\mpi.h
	delete $INSTDIR\include\smpi\mpif.h
	delete $INSTDIR\include\smpi\smpi_cocci.h
	delete $INSTDIR\include\smpi\smpi_main.h
	delete $INSTDIR\include\smpi\smpif.h
	delete $INSTDIR\include\surf\surfxml_parse.h
	delete $INSTDIR\include\surf\simgrid_dtd.h
	delete $INSTDIR\include\surf\surf_routing.h
	delete $INSTDIR\include\instr\instr.h
		
	# delete EXTRA FILES
	delete $INSTDIR\AUTHORS
	delete $INSTDIR\Changelog
	delete $INSTDIR\COPYING
	delete $INSTDIR\LICENSE-LGPL-2.1
	delete $INSTDIR\NEWS
	
	# now delete directories
	RMDir  "$INSTDIR\bin"
	RMDir  "$INSTDIR\lib"
	RMDir  "$INSTDIR\include\simix"
	RMDir  "$INSTDIR\include\instr"
	RMDir  "$INSTDIR\include\surf"
	RMDir  "$INSTDIR\include\smpi"
	RMDir  "$INSTDIR\include\simdag"
	RMDir  "$INSTDIR\include\msg"
	RMDir  "$INSTDIR\include\mc"
	RMDir  "$INSTDIR\include\xbt"
	RMDir  "$INSTDIR\include"
	RMDir  /r "$INSTDIR\doc"
	RMDir  /r "$INSTDIR\examples"
	RMDir  /r "$SMPROGRAMS\SimGrid @SIMGRID_VERSION_MAJOR@.@SIMGRID_VERSION_MINOR@.@SIMGRID_VERSION_PATCH@"
	
	# Delete variable
	DeleteRegValue ${env_hkcu} SIMGRID_ROOT
	DeleteRegValue ${env_hkcu} SIMGRID_VERSION
    DeleteRegKey HKCU "SOFTWARE\SimGrid"
    
    # delete JAVA-bindings
    RMDir /r "$INSTDIR\simgrid-java"
    
    # delete INSTDIR
    RMDir  /r "$INSTDIR"
    
# uninstall section end
sectionEnd
