// CodeXL -- Assembles the build from the upstream components

// "P4ROOT" is passed in by the build script from Jenkins
// "COPYARTIFACT_BUILD_NUMBER_*" variables referenced below are passed in to the build script from Jenkins

Define "ROOTPATH"		"[P4ROOT]"
Define "CXLPATH"		"[ROOTPATH]\CodeXL"
Define "INSPATH"		"[ROOTPATH]\Common\DK\Installer"
Define "COMMONSRCPATH"	"[ROOTPATH]\Common\Src"
Define "LIBAMDPATH"		"[ROOTPATH]\Common\Lib\AMD"
Define "KAPATH"			"[ROOTPATH]\KernelAnalyzer"
Define "COMPPATH"		"[CXLPATH]\Components"
Define "CPUPATH"		"[COMPPATH]\CpuProfiling"
Define "GPUDPATH"		"[COMPPATH]\GpuDebugging"
Define "GPUPPATH"		"[COMPPATH]\GpuProfiling"
Define "CXLRELEASEDIR"	"[CXLPATH]\Output\Release"
Define "RELEASEDIR"		"[COMPPATH]\Output\Release"
Define "DEBUGDIR"		"[COMPPATH]\Output\Debug"
Define "ALLPROJECTS"	"[CXLPATH]\AllProjectsBuild"

Define "UPDATE" "0"

Always
    Log "[P4ROOT]\CodeXL_Build.log"

   // read version number from VersionInfo.h
   Version "[COMMONSRCPATH]\VersionInfo\VersionInfo.h" "#define CODEXL_MAJOR_AND_MINOR_VERSION       [GETMAJOR],[0-9]+,[0-9]+,[0-9]+"
   Version "[COMMONSRCPATH]\VersionInfo\VersionInfo.h" "#define CODEXL_MAJOR_AND_MINOR_VERSION       [0-9]+,[GETMINOR],[0-9]+,[0-9]+"

Image


    MKDIR "[RELEASEDIR]"
    MKDIR "[DEBUGDIR]"

    // Put the CPU Profiling bits in the correct location for the VS Package build
//    XCopy "[CPUPATH]\Installer\AMDTCpuProfiling\Lib\x86\AMDTCpuProfiling.lib" "[RELEASEDIR]\arch\"
//    XCopy "[CPUPATH]\Installer\AMDTCpuProfiling\Lib\x86\AMDTCpuProfiling-d.lib" "[DEBUGDIR]\arch\"
//    XCopy "[CPUPATH]\Installer\AMDTCpuProfiling\Lib\x86\AMDTCpuProfiling.dll" "[COMPPATH]\Output\Release\bin\"
    
    // Put the GPU Profiling bits in the correct location for the VS Package build

//    XCopy "[APPPPATH]\Installer\AMDTGPUProfilingCodeXLPlugin\AMDTGpuProfiling.dll"            "[APPPPATH]\bin\Release-Win32\AMDTGpuProfiling\"
//    Xcopy "[APPPPATH]\Installer\AMDTGPUProfilingCodeXLPlugin\x86\*.*"                         "[APPPPATH]\bin\Release-Win32\sprofile\"
//    Xcopy "[APPPPATH]\Installer\AMDTGPUProfilingCodeXLPlugin\x64\*.*"                         "[APPPPATH]\bin\Release-x64\sprofile\"
//    Xcopy "[APPPPATH]\Installer\AMDTGPUProfilingCodeXLPlugin\jqPlot\*.*"                      "[APPPPATH]\Backend\Common\jqPlot\" 
//    Xcopy "[APPPPATH]\Installer\AMDTGPUProfilingCodeXLPlugin\CLPerfMarker\bin\x86\*.*"        "[APPPPATH]\bin\Release-Win32\CLPerfMarker\" 
//    Xcopy "[APPPPATH]\Installer\AMDTGPUProfilingCodeXLPlugin\CLPerfMarker\bin\x64\*.*"        "[APPPPATH]\bin\Release-x64\CLPerfMarker\"
//    Xcopy "[APPPPATH]\Installer\AMDTGPUProfilingCodeXLPlugin\CLPerfMarker\lib\x86\*.*"        "[APPPPATH]\bin\Release-Win32\CLPerfMarker\"
//    Xcopy "[APPPPATH]\Installer\AMDTGPUProfilingCodeXLPlugin\CLPerfMarker\lib\x64\*.*"        "[APPPPATH]\bin\Release-x64\CLPerfMarker\"
//    Xcopy "[APPPPATH]\Installer\AMDTGPUProfilingCodeXLPlugin\CLPerfMarker\include\*.*"        "[APPPPATH]\Backend\CLPerfMarker\"
//    Xcopy "[APPPPATH]\Installer\AMDTGPUProfilingCodeXLPlugin\CLPerfMarker\doc\*.*"            "[APPPPATH]\Doc\"

    // Put the GPU Debugging bits in the correct location for the VS Package build
//    XCopy /S "[GPUDPATH]\Installer\AMDTGpuDebugging\Release\*.*" "[RELEASEDIR]\"
//    XCopy /S "[GPUDPATH]\Installer\AMDTGpuDebugging_Debug\Debug\*.*" "[DEBUGDIR]\"

    // need to copy the symbol files to make a zip for easier debugging
    Define "SYMZIPDIR" "[CXLPATH]\Output\Symbols"
    MKDIR "[CXLPATH]\Output"
    MKDIR "[SYMZIPDIR]"

    Define "ZIPDIR" "[CXLPATH]\Installer\CodeXL_KA_ZIP"
    Define "ZIPDIRX86" "[CXLPATH]\Installer\CodeXL_KA_ZIP\x86"
    Define "ZIPDIRX64" "[CXLPATH]\Installer\CodeXL_KA_ZIP\x64"
    MKDIR "[ZIPDIR]"
    MKDIR "[ZIPDIRX86]"
    MKDIR "[ZIPDIRX64]"

Version
    // Handle the Package Framework info
    // ========================
    // update version number
    MakeWriteable "[COMMONSRCPATH]\VersionInfo\VersionInfo.h"
    Replace "[COMMONSRCPATH]\VersionInfo\VersionInfo.h" "(.*define FILEVER\s+)[0-9]+\,[0-9]+\,[0-9]+\,[0-9]+" "$1[MAJOR],[MINOR],[BUILD],[UPDATE]"
    Replace "[COMMONSRCPATH]\VersionInfo\VersionInfo.h" "(.*define PRODUCTVER\s+)[0-9]+\,[0-9]+\,[0-9]+\,[0-9]+" "$1[MAJOR],[MINOR],[BUILD],[UPDATE]"
    Replace "[COMMONSRCPATH]\VersionInfo\VersionInfo.h" "(.*define VS_PACKAGE_FILEVER\s+)[0-9]+\,[0-9]+\,[0-9]+\,[0-9]+" "$1[MAJOR],[MINOR],[BUILD],[UPDATE]"
    Replace "[COMMONSRCPATH]\VersionInfo\VersionInfo.h" "(.*define VS_PACKAGE_PRODUCTVER\s+)[0-9]+\,[0-9]+\,[0-9]+\,[0-9]+" "$1[MAJOR],[MINOR],[BUILD],[UPDATE]"

    Replace "[COMMONSRCPATH]\VersionInfo\VersionInfo.h" "(.*define STRFILEVER\s+L\")[0-9]+\,[0-9]+\,[0-9]+\,[0-9]+" "$1[MAJOR],[MINOR],[BUILD],[UPDATE]"
    Replace "[COMMONSRCPATH]\VersionInfo\VersionInfo.h" "(.*define STRPRODUCTVER\s+L\")[0-9]+\,[0-9]+\,[0-9]+\,[0-9]+" "$1[MAJOR],[MINOR],[BUILD],[UPDATE]"
    Replace "[COMMONSRCPATH]\VersionInfo\VersionInfo.h" "(.*define VS_PACKAGE_STRFILEVER\s+L\")[0-9]+\,[0-9]+\,[0-9]+\,[0-9]+" "$1[MAJOR],[MINOR],[BUILD],[UPDATE]"
    Replace "[COMMONSRCPATH]\VersionInfo\VersionInfo.h" "(.*define VS_PACKAGE_STRPRODUCTVER\s+L\")[0-9]+\,[0-9]+\,[0-9]+\,[0-9]+" "$1[MAJOR],[MINOR],[BUILD],[UPDATE]"

    // Handle the Package Installer info
    // ========================
    // Update version number for the CodeXLUpdate_win64.xml
    MakeWriteable "[CXLPATH]\Installer\CodeXLUpdate_win64.xml"
    Replace "[CXLPATH]\Installer\CodeXLUpdate_win64.xml" "<Program_Version_Major>[0-9]+</Program_Version_Major>" "<Program_Version_Major>[MAJOR]</Program_Version_Major>"
    Replace "[CXLPATH]\Installer\CodeXLUpdate_win64.xml" "<Program_Version_Minor>[0-9]+</Program_Version_Minor>" "<Program_Version_Minor>[MINOR]</Program_Version_Minor>"
    Replace "[CXLPATH]\Installer\CodeXLUpdate_win64.xml" "<Program_Version_Build>[0-9]+</Program_Version_Build>" "<Program_Version_Build>[BUILD]</Program_Version_Build>"
    Replace "[CXLPATH]\Installer\CodeXLUpdate_win64.xml" "<Program_Release_Year>[0-9]+</Program_Release_Year>" "<Program_Release_Year>[YEAR]</Program_Release_Year>"
    Replace "[CXLPATH]\Installer\CodeXLUpdate_win64.xml" "<Program_Release_Month>[0-9]+</Program_Release_Month>" "<Program_Release_Month>[MONTHNUMBER]</Program_Release_Month>"
    Replace "[CXLPATH]\Installer\CodeXLUpdate_win64.xml" "<Program_Release_Day>[0-9]+</Program_Release_Day>" "<Program_Release_Day>[DAY]</Program_Release_Day>"
    Replace "[CXLPATH]\Installer\CodeXLUpdate_win64.xml" "<Program_File>.*</Program_File>" "<Program_File>http://developer.amd.com/Downloads/AMD_CodeXL_[MAJOR].[MINOR].[BUILD].exe</Program_File>"

    // Update version number for the CodeXLUpdate_win32.xml
    MakeWriteable "[CXLPATH]\Installer\CodeXLUpdate_win32.xml"
    Replace "[CXLPATH]\Installer\CodeXLUpdate_win32.xml" "<Program_Version_Major>[0-9]+</Program_Version_Major>" "<Program_Version_Major>[MAJOR]</Program_Version_Major>"
    Replace "[CXLPATH]\Installer\CodeXLUpdate_win32.xml" "<Program_Version_Minor>[0-9]+</Program_Version_Minor>" "<Program_Version_Minor>[MINOR]</Program_Version_Minor>"
    Replace "[CXLPATH]\Installer\CodeXLUpdate_win32.xml" "<Program_Version_Build>[0-9]+</Program_Version_Build>" "<Program_Version_Build>[BUILD]</Program_Version_Build>"
    Replace "[CXLPATH]\Installer\CodeXLUpdate_win32.xml" "<Program_Release_Year>[0-9]+</Program_Release_Year>" "<Program_Release_Year>[YEAR]</Program_Release_Year>"
    Replace "[CXLPATH]\Installer\CodeXLUpdate_win32.xml" "<Program_Release_Month>[0-9]+</Program_Release_Month>" "<Program_Release_Month>[MONTHNUMBER]</Program_Release_Month>"
    Replace "[CXLPATH]\Installer\CodeXLUpdate_win32.xml" "<Program_Release_Day>[0-9]+</Program_Release_Day>" "<Program_Release_Day>[DAY]</Program_Release_Day>"
    Replace "[CXLPATH]\Installer\CodeXLUpdate_win32.xml" "<Program_File>.*</Program_File>" "<Program_File>http://developer.amd.com/Downloads/AMD_CodeXL_[MAJOR].[MINOR].[BUILD].exe</Program_File>"

Clean
    BuildSln "[ALLPROJECTS]\CodeXL-AllProjects.sln" "" "Clean" "Release|Win32"
    BuildSln "[ALLPROJECTS]\CodeXL-AllProjects.sln" "" "Clean" "Debug|Win32"
    BuildSln "[ALLPROJECTS]\CodeXL-AllProjects.sln" "" "Clean" "Release|x64"
    BuildSln "[ALLPROJECTS]\CodeXL-AllProjects.sln" "" "Clean" "Debug|x64"

Debug

    BuildSln "[ALLPROJECTS]\CodeXL-AllProjects.sln" "" "BuildandTest" "Debug|x64"
    BuildSln "[ALLPROJECTS]\CodeXL-AllProjects.sln" "" "BuildandTest" "Debug|Win32"
    //BuildSln "[CXLPATH]\Examples\AMDTTeaPot\AMDTTeaPotVS2015.sln" "" "BuildandTest" "Debug|Win32"
    SendBuildErrors "[EMAIL]" "CodeXL All Projects Debug Win32 Build Failed"

Release

    BuildSln "[ALLPROJECTS]\CodeXL-AllProjects.sln" "" "BuildandTest" "Release|x64"
    BuildSln "[ALLPROJECTS]\CodeXL-AllProjects.sln" "" "BuildandTest" "Release|Win32"
    SendBuildErrors "[EMAIL]" "CodeXL All Projects Release Win32 Build Failed"

    SYSTEM "[CXLPATH]\Installer\VersionPatch.bat [CXLPATH]\Installer\VersionPatch.ps1 [ROOTPATH] [MAJOR].[MINOR].[BUILD].[UPDATE] Public"

ReleaseInternal
    SetEnv "AMDT_BUILD"        "AMDT_INTERNAL"
    SetEnv "AMDT_BUILD_SUFFIX" "-internal"
    SetEnv "AMDT_BUILD_SUFFIX" "-internal"

    BuildSln "[ALLPROJECTS]\CodeXL-AllProjects.sln" "" "BuildandTest" "Release|x64"
    BuildSln "[ALLPROJECTS]\CodeXL-AllProjects.sln" "" "BuildandTest" "Release|Win32"
    SendBuildErrors "[EMAIL]" "CodeXL All Projects Internal Release Win32 Build Failed"

    SYSTEM "[CXLPATH]\Installer\VersionPatch.bat [CXLPATH]\Installer\VersionPatch.ps1 [ROOTPATH] [MAJOR].[MINOR].[BUILD].[UPDATE] internal"

ReleaseNda
    SetEnv "AMDT_BUILD"        "AMDT_NDA"
    SetEnv "AMDT_BUILD_SUFFIX" "-nda"
    SetEnv "AMDT_BUILD_SUFFIX" "-nda"

    BuildSln "[ALLPROJECTS]\CodeXL-AllProjects.sln" "" "BuildandTest" "Release|x64"
    BuildSln "[ALLPROJECTS]\CodeXL-AllProjects.sln" "" "BuildandTest" "Release|Win32"
    SendBuildErrors "[EMAIL]" "CodeXL All Projects NDA Release Win32 Build Failed"

    SYSTEM "[CXLPATH]\Installer\VersionPatch.bat [CXLPATH]\Installer\VersionPatch.ps1 [ROOTPATH] [MAJOR].[MINOR].[BUILD].[UPDATE] nda"

	
Image Release
    XCopy "[CXLPATH]\Output\Release\bin\*.pdb" "[SYMZIPDIR]\"
	
Image ReleaseNda
    XCopy "[CXLPATH]\Output\Release\bin\*.pdb" "[SYMZIPDIR]\"

Image ReleaseInternal
    XCopy "[CXLPATH]\Output\Release\bin\*.pdb" "[SYMZIPDIR]\"

Image Debug
    XCopy "[CXLPATH]\Output\Debug\bin\*.pdb" "[SYMZIPDIR]\"
    XCopy "[CXLPATH]\Output\Debug\bin\*.dll" "[SYMZIPDIR]\"
    XCopy "[CXLPATH]\Output\Debug\bin\*.exe" "[SYMZIPDIR]\"

Image
    // generate the symbols zip
    Zip "[CXLPATH]\Installer\CodeXL-symbols-[MAJOR].[MINOR].[BUILD].[UPDATE].zip" "[SYMZIPDIR]"

Version Install
    // Update version number for the Advanced Installer project
    MakeWriteable "[CXLPATH]\Installer\CodeXL\setup.aip"
    XCopy "[LIBAMDPATH]\RCP\RadeonComputeProfiler\bin\*.*" "[CXLPATH]\Output\Release\bin\"
    XCopy /s /i /y "[LIBAMDPATH]\RCP\RadeonComputeProfiler\jqPlot\*.*" "[CXLPATH]\Output\Release\bin\jqPlot\"
    XCopy "[LIBAMDPATH]\RCP\RCPProfileDataParser\bin\*.*" "[CXLPATH]\Output\Release\bin\"

Image Release
    Define "ATZIPDIR" "[CXLPATH]\CAIT"
    MKDIR "[ATZIPDIR]"
    Define "ATx86DIR" "[ATZIPDIR]\x86"
    Define "ATx64DIR" "[ATZIPDIR]\x86_64"
    
    // SET x86 files
    XCopy "[GPUDPATH]\AMDTAutomaticTester\x86\*.*" "[ATZIPDIR]\x86\"
    XCopy "[ROOTPATH]\Common\Lib\AMD\OpenCLDebugAPI\1.3\lib\x86\AMDOpenCLDebug.dll" "[ATx86DIR]\"
    XCopy "[CXLPATH]\Output\Release\bin\CXLApiClasses.dll" "[ATx86DIR]\"
    XCopy "[CXLPATH]\Output\Release\bin\CXLApiFunctions.dll" "[ATx86DIR]\"
    XCopy "[CXLPATH]\Output\Release\bin\CXLBaseTools.dll" "[ATx86DIR]\"
    XCopy "[CXLPATH]\Output\Release\bin\CXLOSWrappers.dll" "[ATx86DIR]\"
    XCopy "[CXLPATH]\Output\Release\bin\CXLOSAPIWrappers.dll" "[ATx86DIR]\"
    XCopy "[CXLPATH]\Output\Release\bin\CXLProcessDebugger.dll" "[ATx86DIR]\"
    XCopy "[CXLPATH]\Output\Release\bin\CXLRemoteClient.dll" "[ATx86DIR]\"	
    XCopy "[CXLPATH]\Output\Release\bin\CXLServerUtilities.dll" "[ATx86DIR]\"
    XCopy "[CXLPATH]\Output\Release\bin\CodeXLGpuDebuggingTest.exe" "[ATx86DIR]\"
    XCopy "C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\dbghelp.dll" "[ATx86DIR]\"
    XCopy "[CXLPATH]\Output\Release\bin\spies\*.*" "[ATx86DIR]\spies\"
    XCopy "[GPUDPATH]\AMDTAutomaticTester\GoldMasters_APPSDK_3_0\BitonicSort_StepTest.log" "[ATx86DIR]\GoldMasters_APPSDK_3_0\"
    XCopy "[GPUDPATH]\AMDTAutomaticTester\GoldMasters_APPSDK_3_0\MatrixMulDouble_StepTest.log" "[ATx86DIR]\GoldMasters_APPSDK_3_0\"
    XCopy "[GPUDPATH]\AMDTAutomaticTester\GoldMasters_APPSDK_3_0\SobelFilter_StepTest.log" "[ATx86DIR]\GoldMasters_APPSDK_3_0\"
    XCopy "[GPUDPATH]\AMDTAutomaticTester\GoldMasters_APPSDK_3_0\URNG_StepIntoTest.log" "[ATx86DIR]\GoldMasters_APPSDK_3_0\"


    // Set x64 files
    XCopy "[GPUDPATH]\AMDTAutomaticTester\x86_64\*.*" "[ATZIPDIR]\x86_64\"
    XCopy "[ROOTPATH]\Common\Lib\AMD\OpenCLDebugAPI\1.3\lib\x64\AMDOpenCLDebug*.dll" "[ATx64DIR]\"
    XCopy "[CXLPATH]\Output\Release\bin\CXLApiClasses*.dll" "[ATx64DIR]\"
    XCopy "[CXLPATH]\Output\Release\bin\CXLApiFunctions*.dll" "[ATx64DIR]\"
    XCopy "[CXLPATH]\Output\Release\bin\CXLBaseTools*.dll" "[ATx64DIR]\"
    XCopy "[CXLPATH]\Output\Release\bin\CXLOSWrappers*.dll" "[ATx64DIR]\"
    XCopy "[CXLPATH]\Output\Release\bin\CXLOSAPIWrappers*.dll" "[ATx64DIR]\"
    XCopy "[CXLPATH]\Output\Release\bin\CXLProcessDebugger*.dll" "[ATx64DIR]\"
    XCopy "[CXLPATH]\Output\Release\bin\CXLRemoteClient*.dll" "[ATx64DIR]\"	
    XCopy "[CXLPATH]\Output\Release\bin\CXLRemoteDebuggingServer*.exe" "[ATx64DIR]\"  
    XCopy "[CXLPATH]\Output\Release\bin\CXLServerUtilities*.dll" "[ATx64DIR]\"
    XCopy "[CXLPATH]\Output\Release\bin\CodeXLGpuDebuggingTest*.exe" "[ATx64DIR]\"
    XCopy "[CXLPATH]\Output\Release\bin\spies64\*.*" "[ATx64DIR]\spies64\"
    XCopy "[GPUDPATH]\AMDTAutomaticTester\GoldMasters_APPSDK_3_0\BitonicSort_StepTest.log" "[ATx64DIR]\GoldMasters_APPSDK_3_0\"
    XCopy "[GPUDPATH]\AMDTAutomaticTester\GoldMasters_APPSDK_3_0\MatrixMulDouble_StepTest.log" "[ATx64DIR]\GoldMasters_APPSDK_3_0\"
    XCopy "[GPUDPATH]\AMDTAutomaticTester\GoldMasters_APPSDK_3_0\SobelFilter_StepTest.log" "[ATx64DIR]\GoldMasters_APPSDK_3_0\"
    XCopy "[GPUDPATH]\AMDTAutomaticTester\GoldMasters_APPSDK_3_0\URNG_StepIntoTest.log" "[ATx64DIR]\GoldMasters_APPSDK_3_0\"

XCopy "[GPUDPATH]\AMDTAutomaticTester\ReadMe.*" "[ATZIPDIR]"

Zip "[CXLPATH]\Installer\CAIT-[MAJOR].[MINOR].[BUILD].zip" "[ATZIPDIR]"
