-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.ps1
More file actions
74 lines (66 loc) · 3.09 KB
/
release.ps1
File metadata and controls
74 lines (66 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
###############################################################################
# Build the release executable which can be used to run script files.
###############################################################################
if (!(Test-Path "./release")) {
Write-Host "Creating release folder"
New-Item -ItemType Directory -Path "./release"
}
$releasePath = Join-Path (Split-Path -Parent $PSCommandPath) "release"
# This assumes tcc is in the path.
Push-Location "src"
$tccOutput = tcc -o (Join-Path $releasePath "arcane.exe") *.c -lws2_32 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host "EXE Build succeeded" -ForegroundColor Green
} else {
Write-Host "EXE Build failed (exit code: $LASTEXITCODE)" -ForegroundColor Red
}
if ($tccOutput) {
Write-Host $tccOutput
}
Pop-Location
###############################################################################
# Build the release DLL via "tcc -shared -rdynamic ", excluding main.c. The
# -rdynamic is required to export the functions so that interop programs can
# see and call them.
###############################################################################
Push-Location "src"
$cFiles = Get-ChildItem -Filter *.c | Where-Object { $_.Name -ne "main.c" } | ForEach-Object { $_.Name }
$tccOutputDll = tcc -shared -rdynamic -o (Join-Path $releasePath "arcane.dll") $cFiles -lws2_32 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host "DLL build succeeded" -ForegroundColor Green
} else {
Write-Host "DLL build failed (exit code: $LASTEXITCODE)" -ForegroundColor Red
}
if ($tccOutputDll) {
Write-Host $tccOutputDll
}
Pop-Location
###############################################################################
# Copy that version into the csharp folder where it's added to the csproj as
# content that gets sent to the output directory.
###############################################################################
$csharpFolder = Join-Path (Split-Path -Parent $PSCommandPath) "csharp"
if (!(Test-Path $csharpFolder)) {
Write-Host "Creating csharp folder"
New-Item -ItemType Directory -Path $csharpFolder | Out-Null
}
$sourceDll = Join-Path $releasePath "arcane.dll"
$destinationDll = Join-Path $csharpFolder "arcane.dll"
Copy-Item -Path $sourceDll -Destination $destinationDll -Force
Write-Host "arcane.dll copied to $destinationDll" -ForegroundColor Green
###############################################################################
# Build the amalgamation C file.
###############################################################################
$amalgamationFile = Join-Path $releasePath "arcane.c"
$filesToCombine = @("arcane.h", "functions.c", "arcane.c")
# Create or clear the amalgamation file.
Set-Content -Path $amalgamationFile -Value ""
foreach ($file in $filesToCombine) {
$filePath = Join-Path "src" $file
if (Test-Path $filePath) {
Get-Content $filePath | Where-Object { $_ -notmatch '#include\s+["'']arcane\.h["'']' } | Add-Content -Path $amalgamationFile
} else {
Write-Host "File $file not found in src folder." -ForegroundColor Yellow
}
}
Write-Host "Amalgamation file created at $amalgamationFile" -ForegroundColor Green