-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompile.ps1
More file actions
81 lines (67 loc) · 1.9 KB
/
compile.ps1
File metadata and controls
81 lines (67 loc) · 1.9 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
75
76
77
78
79
80
81
param(
[switch]$clean
)
# Compiler/interpreters
$CC = "gcc"
$CXX = "g++"
$PYTHON = "python"
# Directories
$BUILD_DIR = "build"
$SRC_DIR = "src"
# Check if programs file exists
if (-not (Test-Path "programs")) {
Write-Host "Error: 'programs' file not found."
exit 1
}
# Read programs from 'programs' file, ignore empty lines
$PROGRAMS = Get-Content "programs" | Where-Object { $_.Trim() -ne "" }
# Functions
function Ensure-BuildDir {
if (-not (Test-Path $BUILD_DIR)) {
New-Item -ItemType Directory -Path $BUILD_DIR | Out-Null
}
}
function Clean-BuildDir {
if (Test-Path $BUILD_DIR) {
Remove-Item -Path $BUILD_DIR -Recurse -Force
Write-Host "Cleaned $BUILD_DIR"
}
}
if ($clean) {
Clean-BuildDir
exit
}
Ensure-BuildDir
foreach ($prog in $PROGRAMS) {
$src = Join-Path $SRC_DIR $prog
if (-not (Test-Path $src)) {
Write-Host "Skipping $src — file not found"
continue
}
$ext = [System.IO.Path]::GetExtension($prog).ToLower()
switch ($ext) {
".c" {
$out = Join-Path $BUILD_DIR ([System.IO.Path]::GetFileNameWithoutExtension($prog))
Write-Host "Compiling C: $src -> $out"
& $CC "-Wall" "-Wextra" $src "-o" $out
}
".cpp" {
$out = Join-Path $BUILD_DIR ([System.IO.Path]::GetFileNameWithoutExtension($prog))
Write-Host "Compiling C++: $src -> $out"
& $CXX "-Wall" "-Wextra" $src "-o" $out
}
".py" {
$out = Join-Path $BUILD_DIR $prog
Write-Host "Copying Python script: $src -> $out"
Copy-Item $src $out -Force
}
".ps1" {
$out = Join-Path $BUILD_DIR $prog
Write-Host "Copying PowerShell script: $src -> $out"
Copy-Item $src $out -Force
}
default {
Write-Host "Skipping $src — unsupported extension"
}
}
}