@echo on
@setlocal

@set NO_SYS_SIGNING=
rem *** parse arguments
:loop1
@if /I "%1"=="no_sys_signing"     set NO_SYS_SIGNING=on
@shift
@if not "%1"=="" goto loop1


@rem *** NOTE: We should always use the full list of OS.

@rem *** OS list for x86, see inf2cat.txt
set OSLIST_x86=2000,XP_X86,Server2003_X86,Vista_X86,7_X86,Server2008_X86,8_X86,6_3_X86
@rem *** OS list for x64, see inf2cat.txt
set OSLIST_x64=XP_X64,Server2003_X64,Vista_X64,7_X64,Server2008_X64,Server2008R2_X64,8_X64,Server8_X64,6_3_X64,Server6_3_X64

@rem
@rem OS list contains a combination of the following values:
@rem    2000  XP_X86   Server2003_X86   Vista_X86  7_X86  Server2008_X86                      8_X86        6_3_X86
@rem          XP_X64   Server2003_X64   Vista_X64  7_X64  Server2008_X64   Server2008R2_X64   8_X64        6_3_X64
@rem                   Server2003_IA64                    Server2008_IA64  Server2008R2_IA64  Server8_X64  Server6_3_X64
@rem                                                                                          8_ARM
@rem
@rem

@rem load the certificate settings
@call ..\signing\set_vendor_certificate.cmd 
@call ..\signing\set_sign_tools.cmd 
@call .\setvars.cmd

@rem check if SignTools package is available

@if "%SIGNTOOLS%"=="" (
	@echo.
	@echo ***************************************************************************
	@echo The environment variable SIGNTOOLS has not been set.
	@echo Please install the SignTools package from Thesycon. Ask Thesycon for a free
	@echo copy of the SignTools installer at the e-mail address 
	@echo info^(at^)thesycon^(dot^)de. 
	@echo Press enter to exit.
	@echo ***************************************************************************
	pause
	@goto end
)

@if "%VENDOR_CERTIFICATE%"=="" (
	@echo.
	@echo ***************************************************************************
	@echo The environment variable VENDOR_CERTIFICATE has not been set.
	@echo If you own a code signing certificate from VeriSign or another provider
	@echo then edit set_vendor_certificate.cmd or set VENDOR_CERTIFICATE in your 
	@echo machine's environment.
	@echo This script requires a valid code signing certificate.
	@echo Press enter to exit.
	@echo ***************************************************************************
	@echo.
	pause
	@goto end
)
@if not exist driver_package\release (
	@echo.
	@echo ***************************************************************************
	@echo The driver package was not yet created. Please use the script 
	@echo create_drvpackage.cmd first.
	@echo Press enter to exit.
	@echo ***************************************************************************
	@echo.
	pause
	@goto end
)

@echo on
@rem sign .sys files
@if "%NO_SYS_SIGNING%"=="on" goto cont1

@if exist driver_package\debug (	
	cmd /c ..\signing\vendor_sign_files.cmd driver_package\debug\*.sys
)
cmd /c ..\signing\vendor_sign_files.cmd driver_package\release\*.sys
:cont1

@rem create .cat files
@if exist driver_package\debug (
	%SIGNTOOLS%\bin\inf2cat.exe /driver:driver_package\debug  /os:%OSLIST_x86%,%OSLIST_x64%
	@if %errorlevel% NEQ 0 pause
)
%SIGNTOOLS%\bin\inf2cat.exe /driver:driver_package\release  /os:%OSLIST_x86%,%OSLIST_x64%
@if %errorlevel% NEQ 0 pause

@rem sign .cat files
@set FILES_TO_SIGN=
@if exist driver_package\debug (
	@set FILES_TO_SIGN=driver_package\debug\*.cat
)
@set FILES_TO_SIGN=%FILES_TO_SIGN% driver_package\release\*.cat
cmd /c ..\signing\vendor_sign_files.cmd %FILES_TO_SIGN%

@echo off
@goto end
rem *************** end of 'main'

:end
endlocal
