pwn-compile/compile.ps1

39 lines
977 B
PowerShell

Param(
[Int]$Cores = 0
)
if ($Cores-ne 0) {
Write-Host "Overriding core count with $Cores."
$MaxThreads = $Cores
}
else {
$MaxThreads = (Get-WmiObject -Class Win32_Processor).NumberOfLogicalProcessors
Write-Host "Running with $MaxThreads" Cores by default.
}
$files = (ls *.pwn).Name
$workdir = (pwd)
$Block = {
Param([string] $file, [string] $workdir)
& cd $workdir; .\pawncc.exe $file
}
#Remove all jobs
Get-Job | Remove-Job
#Start the jobs. Max 4 jobs running simultaneously.
foreach($file in $files){
While ($(Get-Job -state running).count -ge $MaxThreads){
Start-Sleep -Milliseconds 3
}
Start-Job -Scriptblock $Block -ArgumentList $file, $workdir
}
#Wait for all jobs to finish.
While ($(Get-Job -State Running).count -gt 0){
start-sleep 1
}
#Get information from each job.
foreach($job in Get-Job){
$info= Receive-Job -Id ($job.Id)
}
#Remove all jobs created.
Get-Job | Remove-Job