def Build()

in BuildAll.py [0:0]


def Build(hostPlatform, hostArch, buildSys, compiler, arch, configuration, tblgenMode, tblgenPath):
	originalDir = os.path.abspath(os.curdir)

	if not os.path.exists("Build"):
		os.mkdir("Build")

	multiConfig = (buildSys.find("vs") == 0)

	buildDir = "Build/%s-%s-%s-%s" % (buildSys, hostPlatform, compiler, arch)
	if (not multiConfig) or (configuration == "clangformat"):
		buildDir += "-%s" % configuration;
	if not os.path.exists(buildDir):
		os.mkdir(buildDir)
	os.chdir(buildDir)
	buildDir = os.path.abspath(os.curdir)

	tblgenOptions = ""
	if (tblgenPath != None):
		tblgenOptions = " -DCLANG_TABLEGEN=\"%s\" -DLLVM_TABLEGEN=\"%s\"" % tblgenPath

	parallel = multiprocessing.cpu_count()

	batCmd = BatchCommand(hostPlatform)
	if hostPlatform == "win":
		programFilesFolder = FindProgramFilesFolder()
		if (buildSys == "vs2019") or ((buildSys == "ninja") and (compiler == "vc142")):
			vsFolder = FindVS2019Folder(programFilesFolder)
		elif (buildSys == "vs2017") or ((buildSys == "ninja") and (compiler == "vc141")):
			vsFolder = FindVS2017Folder(programFilesFolder)
		elif (buildSys == "vs2015") or ((buildSys == "ninja") and (compiler == "vc140")):
			vsFolder = FindVS2015Folder(programFilesFolder)
		if "x64" == arch:
			vcOption = "amd64"
			vcArch = "x64"
		elif "x86" == arch:
			vcOption = "x86"
			vcArch = "Win32"
		elif "arm64" == arch:
			vcOption = "amd64_arm64"
			vcArch = "ARM64"
		elif "arm" == arch:
			vcOption = "amd64_arm"
			vcArch = "ARM"
		else:
			LogError("Unsupported architecture.\n")
		vcToolset = ""
		if (buildSys == "vs2019") and (compiler == "vc141"):
			vcOption += " -vcvars_ver=14.1"
			vcToolset = "v141,"
		elif ((buildSys == "vs2019") or (buildSys == "vs2017")) and (compiler == "vc140"):
			vcOption += " -vcvars_ver=14.0"
			vcToolset = "v140,"
		batCmd.AddCommand("@call \"%sVCVARSALL.BAT\" %s" % (vsFolder, vcOption))
		batCmd.AddCommand("@cd /d \"%s\"" % buildDir)
	if (buildSys == "ninja"):
		if hostPlatform == "win":
			batCmd.AddCommand("set CC=cl.exe")
			batCmd.AddCommand("set CXX=cl.exe")
		if (configuration == "clangformat"):
			options = "-DSC_CLANGFORMAT=\"ON\""
		else:
			options = "-DCMAKE_BUILD_TYPE=\"%s\" -DSC_ARCH_NAME=\"%s\" %s" % (configuration, arch, tblgenOptions)
		batCmd.AddCommand("cmake -G Ninja %s ../../" % options)
		if tblgenMode:
			batCmd.AddCommand("ninja clang-tblgen -j%d" % parallel)
			batCmd.AddCommand("ninja llvm-tblgen -j%d" % parallel)
		else:
			batCmd.AddCommand("ninja -j%d" % parallel)
	else:
		if buildSys == "vs2019":
			generator = "\"Visual Studio 16\""
		elif buildSys == "vs2017":
			generator = "\"Visual Studio 15\""
		elif buildSys == "vs2015":
			generator = "\"Visual Studio 14\""
		if (configuration == "clangformat"):
			cmake_options = "-DSC_CLANGFORMAT=\"ON\""
			msbuild_options = ""
		else:
			cmake_options = "-T %shost=x64 -A %s %s" % (vcToolset, vcArch, tblgenOptions)
			msbuild_options = "/m:%d /v:m /p:Configuration=%s,Platform=%s" % (parallel, configuration, vcArch)
		batCmd.AddCommand("cmake -G %s %s ../../" % (generator, cmake_options))
		if tblgenMode:
			batCmd.AddCommand("MSBuild External\\DirectXShaderCompiler\\tools\\clang\\utils\\TableGen\\clang-tblgen.vcxproj /nologo %s" % msbuild_options)
			batCmd.AddCommand("MSBuild External\\DirectXShaderCompiler\\utils\\TableGen\\llvm-tblgen.vcxproj /nologo %s" % msbuild_options)
		else:
			batCmd.AddCommand("MSBuild ALL_BUILD.vcxproj /nologo %s" % msbuild_options)
	if batCmd.Execute() != 0:
		LogError("Build failed.\n")

	os.chdir(originalDir)

	tblGenPath = buildDir + "/External/DirectXShaderCompiler"
	if multiConfig:
		tblGenPath += "/" + configuration
	tblGenPath += "/bin/"
	clangTblgenPath = tblGenPath + "clang-tblgen"
	llvmTblGenPath = tblGenPath + "llvm-tblgen"
	if (hostPlatform == "win"):
		clangTblgenPath += ".exe"
		llvmTblGenPath += ".exe"
	return (clangTblgenPath, llvmTblGenPath)