2023-09-08 09:42:24 -07:00
|
|
|
Clear-Host
|
|
|
|
|
2023-09-23 18:03:33 -07:00
|
|
|
$target_arch = Join-Path $PSScriptRoot 'helpers/target_arch.psm1'
|
|
|
|
$devshell = Join-Path $PSScriptRoot 'helpers/devshell.ps1'
|
|
|
|
$path_root = git rev-parse --show-toplevel
|
2023-09-28 17:22:15 -07:00
|
|
|
$path_build = Join-Path $path_root 'build'
|
2023-09-23 18:03:33 -07:00
|
|
|
|
|
|
|
Import-Module $target_arch
|
2023-09-08 09:42:24 -07:00
|
|
|
|
|
|
|
Push-Location $path_root
|
|
|
|
|
|
|
|
#region Arguments
|
|
|
|
$vendor = $null
|
2023-09-28 15:38:06 -07:00
|
|
|
$optimize = $null
|
2023-09-18 17:16:40 -07:00
|
|
|
$debug = $null
|
2023-09-15 18:35:27 -07:00
|
|
|
$analysis = $false
|
2023-09-18 17:16:40 -07:00
|
|
|
$dev = $false
|
2023-09-26 14:26:35 -07:00
|
|
|
$platform = $null
|
|
|
|
$engine = $null
|
|
|
|
$game = $null
|
2023-09-08 09:42:24 -07:00
|
|
|
|
|
|
|
[array] $vendors = @( "clang", "msvc" )
|
|
|
|
|
|
|
|
# This is a really lazy way of parsing the args, could use actual params down the line...
|
|
|
|
|
|
|
|
if ( $args ) { $args | ForEach-Object {
|
|
|
|
switch ($_){
|
2023-09-15 18:35:27 -07:00
|
|
|
{ $_ -in $vendors } { $vendor = $_; break }
|
2023-09-28 15:38:06 -07:00
|
|
|
"optimize" { $optimize = $true }
|
2023-09-15 18:35:27 -07:00
|
|
|
"debug" { $debug = $true }
|
|
|
|
"analysis" { $analysis = $true }
|
2023-09-18 17:16:40 -07:00
|
|
|
"dev" { $dev = $true }
|
2023-09-26 14:26:35 -07:00
|
|
|
"platform" { $platform = $true }
|
|
|
|
"engine" { $engine = $true }
|
|
|
|
"game" { $game = $true }
|
2023-09-08 09:42:24 -07:00
|
|
|
}
|
|
|
|
}}
|
2023-09-15 18:35:27 -07:00
|
|
|
#endregion Argument
|
2023-09-08 09:42:24 -07:00
|
|
|
|
2023-09-26 14:26:35 -07:00
|
|
|
#region Toolchain Configuration
|
2023-09-08 09:42:24 -07:00
|
|
|
if ($IsWindows) {
|
2023-09-23 18:03:33 -07:00
|
|
|
# This HandmadeHero implementation is only designed for 64-bit systems
|
2023-09-08 09:42:24 -07:00
|
|
|
& $devshell -arch amd64
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $vendor -eq $null ) {
|
|
|
|
write-host "No vendor specified, assuming clang available"
|
|
|
|
$compiler = "clang"
|
|
|
|
}
|
|
|
|
|
|
|
|
write-host "Building HandmadeHero with $vendor"
|
2023-09-18 17:16:40 -07:00
|
|
|
|
|
|
|
if ( $dev ) {
|
|
|
|
if ( $debug -eq $null ) {
|
2023-09-26 22:16:41 -07:00
|
|
|
$debug = $true
|
2023-09-18 17:16:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( $optimize -eq $null ) {
|
|
|
|
$optimize = $false
|
|
|
|
}
|
|
|
|
}
|
2023-09-08 09:42:24 -07:00
|
|
|
|
|
|
|
function run-compiler
|
|
|
|
{
|
|
|
|
param( $compiler, $unit, $compiler_args )
|
|
|
|
|
2023-09-15 18:35:27 -07:00
|
|
|
if ( $analysis ) {
|
|
|
|
$compiler_args += $flag_syntax_only
|
|
|
|
}
|
2023-09-08 15:54:16 -07:00
|
|
|
|
2023-09-08 09:42:24 -07:00
|
|
|
write-host "`Compiling $unit"
|
|
|
|
write-host "Compiler config:"
|
|
|
|
$compiler_args | ForEach-Object {
|
|
|
|
write-host $_ -ForegroundColor Cyan
|
|
|
|
}
|
|
|
|
|
|
|
|
$time_taken = Measure-Command {
|
|
|
|
& $compiler $compiler_args 2>&1 | ForEach-Object {
|
|
|
|
$color = 'White'
|
|
|
|
switch ($_){
|
|
|
|
{ $_ -match "error" } { $color = 'Red' ; break }
|
|
|
|
{ $_ -match "warning" } { $color = 'Yellow'; break }
|
|
|
|
}
|
|
|
|
write-host `t $_ -ForegroundColor $color
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( Test-Path($unit) ) {
|
|
|
|
write-host "$unit compile finished in $($time_taken.TotalMilliseconds) ms"
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
write-host "Compile failed for $unit" -ForegroundColor Red
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function run-linker
|
|
|
|
{
|
|
|
|
param( $linker, $binary, $linker_args )
|
|
|
|
|
|
|
|
write-host "`Linking $binary"
|
|
|
|
write-host "Linker config:"
|
|
|
|
$linker_args | ForEach-Object {
|
|
|
|
write-host $_ -ForegroundColor Cyan
|
|
|
|
}
|
|
|
|
|
|
|
|
$time_taken = Measure-Command {
|
|
|
|
& $linker $linker_args 2>&1 | ForEach-Object {
|
|
|
|
$color = 'White'
|
|
|
|
switch ($_){
|
|
|
|
{ $_ -match "error" } { $color = 'Red' ; break }
|
|
|
|
{ $_ -match "warning" } { $color = 'Yellow'; break }
|
|
|
|
}
|
|
|
|
write-host `t $_ -ForegroundColor $color
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( Test-Path($binary) ) {
|
|
|
|
write-host "$binary linking finished in $($time_taken.TotalMilliseconds) ms"
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
write-host "Linking failed for $binary" -ForegroundColor Red
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $vendor -match "clang" )
|
|
|
|
{
|
|
|
|
# https://clang.llvm.org/docs/ClangCommandLineReference.html
|
2023-09-26 14:26:35 -07:00
|
|
|
$flag_all_c = '/TC'
|
|
|
|
$flag_all_cpp = '/TP'
|
|
|
|
$flag_compile = '-c'
|
|
|
|
$flag_color_diagnostics = '-fcolor-diagnostics'
|
|
|
|
$flag_no_color_diagnostics = '-fno-color-diagnostics'
|
|
|
|
$flag_debug = '-g'
|
|
|
|
$flag_debug_codeview = '-gcodeview'
|
|
|
|
$flag_define = '-D'
|
|
|
|
$flag_exceptions_disabled = '-fno-exceptions'
|
|
|
|
$flag_preprocess = '-E'
|
|
|
|
$flag_include = '-I'
|
|
|
|
$flag_section_data = '-fdata-sections'
|
|
|
|
$flag_section_functions = '-ffunction-sections'
|
|
|
|
$flag_library = '-l'
|
|
|
|
$flag_library_path = '-L'
|
|
|
|
$flag_linker = '-Wl,'
|
|
|
|
if ( $IsWindows ) {
|
|
|
|
$flag_link_dll = '/DLL'
|
|
|
|
$flag_link_mapfile = '/MAP:'
|
|
|
|
$flag_link_optimize_references = '/OPT:REF'
|
|
|
|
}
|
|
|
|
if ( $IsLinux ) {
|
|
|
|
$flag_link_mapfile = '--Map='
|
|
|
|
$flag_link_optimize_references = '--gc-sections'
|
|
|
|
}
|
|
|
|
$flag_link_win_subsystem_console = '/SUBSYSTEM:CONSOLE'
|
|
|
|
$flag_link_win_subsystem_windows = '/SUBSYSTEM:WINDOWS'
|
|
|
|
$flag_link_win_machine_32 = '/MACHINE:X86'
|
|
|
|
$flag_link_win_machine_64 = '/MACHINE:X64'
|
|
|
|
$flag_link_win_debug = '/DEBUG'
|
|
|
|
$flag_link_win_pdb = '/PDB:'
|
|
|
|
$flag_link_win_path_output = '/OUT:'
|
|
|
|
$flag_no_optimization = '-O0'
|
|
|
|
$flag_optimize_fast = '-O2'
|
|
|
|
$flag_optimize_size = '-O1'
|
|
|
|
$flag_optimize_intrinsics = '-Oi'
|
|
|
|
$flag_path_output = '-o'
|
|
|
|
$flag_preprocess_non_intergrated = '-no-integrated-cpp'
|
|
|
|
$flag_profiling_debug = '-fdebug-info-for-profiling'
|
|
|
|
$flag_set_stack_size = '-stack='
|
|
|
|
$flag_syntax_only = '-fsyntax-only'
|
|
|
|
$flag_target_arch = '-target'
|
|
|
|
$flag_wall = '-Wall'
|
|
|
|
$flag_warning = '-W'
|
|
|
|
$flag_warnings_as_errors = '-Werror'
|
|
|
|
$flag_win_nologo = '/nologo'
|
2023-09-08 09:42:24 -07:00
|
|
|
|
2023-09-23 18:03:33 -07:00
|
|
|
$ignore_warning_ms_include = 'no-microsoft-include'
|
|
|
|
$ignore_warning_return_type_c_linkage = 'no-return-type-c-linkage'
|
2023-09-08 09:42:24 -07:00
|
|
|
|
|
|
|
$target_arch = Get-TargetArchClang
|
|
|
|
|
|
|
|
$warning_ignores = @(
|
2023-09-23 18:03:33 -07:00
|
|
|
$ignore_warning_ms_include,
|
|
|
|
$ignore_warning_return_type_c_linkage
|
2023-09-08 09:42:24 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
# https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-170
|
|
|
|
$libraries = @(
|
|
|
|
'Kernel32' # For Windows API
|
|
|
|
# 'msvcrt', # For the C Runtime (Dynamically Linked)
|
|
|
|
# 'libucrt',
|
|
|
|
'libcmt' # For the C Runtime (Static Linkage)
|
|
|
|
)
|
|
|
|
|
|
|
|
function build-simple
|
|
|
|
{
|
2023-09-26 14:26:35 -07:00
|
|
|
param( [array]$includes, [array]$compiler_args, [array]$linker_args, [string]$unit, [string]$binary )
|
2023-09-08 09:42:24 -07:00
|
|
|
Write-Host "build-simple: clang"
|
|
|
|
|
2023-09-26 22:16:41 -07:00
|
|
|
$object = $unit -replace '\.cpp', '.obj'
|
|
|
|
$map = $unit -replace '\.cpp', '.map'
|
2023-09-28 17:22:15 -07:00
|
|
|
$object = join-path $path_build (split-path $object -Leaf)
|
|
|
|
$map = join-path $path_build (split-path $map -Leaf)
|
2023-09-26 22:16:41 -07:00
|
|
|
|
|
|
|
# The PDB file has to also be time-stamped so that we can reload the DLL at runtime
|
|
|
|
$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
|
|
|
|
$pdb = $binary -replace '\.(exe|dll)$', "_$timestamp.pdb"
|
2023-09-08 09:42:24 -07:00
|
|
|
|
2023-09-08 14:50:22 -07:00
|
|
|
$compiler_args += @(
|
2023-09-08 09:42:24 -07:00
|
|
|
$flag_no_color_diagnostics,
|
2023-09-13 21:43:35 -07:00
|
|
|
$flag_exceptions_disabled,
|
2023-09-08 09:42:24 -07:00
|
|
|
$flag_target_arch, $target_arch,
|
|
|
|
$flag_wall,
|
2023-09-28 18:57:52 -07:00
|
|
|
$flag_preprocess_on_intergrated,
|
|
|
|
# $flag_section_data,
|
|
|
|
# $flag_section_functions,
|
2023-09-09 09:47:06 -07:00
|
|
|
( $flag_path_output + $object )
|
2023-09-08 09:42:24 -07:00
|
|
|
)
|
2023-09-28 15:38:06 -07:00
|
|
|
if ( $optimize ) {
|
2023-09-15 18:35:27 -07:00
|
|
|
$compiler_args += $flag_optimize_fast
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$compiler_args += $flag_no_optimization
|
|
|
|
}
|
|
|
|
if ( $debug ) {
|
2023-09-18 17:16:40 -07:00
|
|
|
$compiler_args += ( $flag_define + 'Build_Debug=1' )
|
2023-09-08 09:42:24 -07:00
|
|
|
$compiler_args += $flag_debug, $flag_debug_codeview, $flag_profiling_debug
|
|
|
|
}
|
2023-09-18 17:16:40 -07:00
|
|
|
else {
|
|
|
|
$compiler_args += ( $flag_define + 'Build_Debug=0' )
|
|
|
|
}
|
2023-09-08 09:42:24 -07:00
|
|
|
|
|
|
|
$warning_ignores | ForEach-Object {
|
|
|
|
$compiler_args += $flag_warning + $_
|
|
|
|
}
|
2023-09-09 09:47:06 -07:00
|
|
|
$compiler_args += $includes | ForEach-Object { $flag_include + $_ }
|
2023-09-08 09:42:24 -07:00
|
|
|
|
|
|
|
$compiler_args += $flag_compile, $unit
|
|
|
|
run-compiler $compiler $unit $compiler_args
|
|
|
|
|
2023-09-08 14:50:22 -07:00
|
|
|
$linker_args += @(
|
2023-09-08 09:42:24 -07:00
|
|
|
$flag_link_win_machine_64,
|
2023-09-26 14:26:35 -07:00
|
|
|
$( $flag_link_win_path_output + $binary )
|
2023-09-08 09:42:24 -07:00
|
|
|
)
|
2023-09-15 18:35:27 -07:00
|
|
|
if ( $debug ) {
|
2023-09-08 09:42:24 -07:00
|
|
|
$linker_args += $flag_link_win_debug
|
|
|
|
$linker_args += $flag_link_win_pdb + $pdb
|
2023-09-26 14:26:35 -07:00
|
|
|
$linker_args += $flag_link_mapfile + $map
|
2023-09-08 09:42:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$libraries | ForEach-Object {
|
|
|
|
$linker_args += $_ + '.lib'
|
|
|
|
}
|
|
|
|
|
|
|
|
$linker_args += $object
|
2023-09-26 14:26:35 -07:00
|
|
|
run-linker $linker $binary $linker_args
|
2023-09-16 15:41:07 -07:00
|
|
|
|
|
|
|
# $compiler_args += $unit
|
|
|
|
# $linker_args | ForEach-Object {
|
|
|
|
# $compiler_args += $flag_linker + $_
|
|
|
|
# }
|
|
|
|
# run-compiler $compiler $unit $compiler_args
|
2023-09-08 09:42:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$compiler = 'clang++'
|
|
|
|
$linker = 'lld-link'
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $vendor -match "msvc" )
|
|
|
|
{
|
|
|
|
# https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170
|
2023-09-15 18:35:27 -07:00
|
|
|
$flag_all_c = '/TC'
|
|
|
|
$flag_all_cpp = '/TP'
|
2023-09-08 14:50:22 -07:00
|
|
|
$flag_compile = '/c'
|
|
|
|
$flag_debug = '/Zi'
|
|
|
|
$flag_define = '/D'
|
2023-09-20 21:26:23 -07:00
|
|
|
$flag_exceptions_disabled = '/EHsc-'
|
2023-09-15 18:35:27 -07:00
|
|
|
$flag_RTTI_disabled = '/GR-'
|
2023-09-08 14:50:22 -07:00
|
|
|
$flag_include = '/I'
|
|
|
|
$flag_full_src_path = '/FC'
|
|
|
|
$flag_nologo = '/nologo'
|
|
|
|
$flag_dll = '/LD'
|
|
|
|
$flag_dll_debug = '/LDd'
|
|
|
|
$flag_linker = '/link'
|
2023-09-26 14:26:35 -07:00
|
|
|
$flag_link_dll = '/DLL'
|
2023-09-26 22:16:41 -07:00
|
|
|
$flag_link_no_incremental = '/INCREMENTAL:NO'
|
2023-09-20 21:26:23 -07:00
|
|
|
$flag_link_mapfile = '/MAP:'
|
|
|
|
$flag_link_optimize_references = '/OPT:REF'
|
2023-09-08 14:50:22 -07:00
|
|
|
$flag_link_win_debug = '/DEBUG'
|
|
|
|
$flag_link_win_pdb = '/PDB:'
|
|
|
|
$flag_link_win_machine_32 = '/MACHINE:X86'
|
|
|
|
$flag_link_win_machine_64 = '/MACHINE:X64'
|
|
|
|
$flag_link_win_path_output = '/OUT:'
|
|
|
|
$flag_link_win_rt_dll = '/MD'
|
|
|
|
$flag_link_win_rt_dll_debug = '/MDd'
|
|
|
|
$flag_link_win_rt_static = '/MT'
|
|
|
|
$flag_link_win_rt_static_debug = '/MTd'
|
|
|
|
$flag_link_win_subsystem_console = '/SUBSYSTEM:CONSOLE'
|
|
|
|
$flag_link_win_subsystem_windows = '/SUBSYSTEM:WINDOWS'
|
|
|
|
$flag_no_optimization = '/Od'
|
2023-09-15 18:35:27 -07:00
|
|
|
$flag_optimize_fast = '/O2'
|
|
|
|
$flag_optimize_size = '/O1'
|
2023-09-20 21:26:23 -07:00
|
|
|
$flag_optimize_intrinsics = '/Oi'
|
2023-09-15 18:35:27 -07:00
|
|
|
$flag_optimized_debug = '/Zo'
|
2023-09-08 14:50:22 -07:00
|
|
|
$flag_out_name = '/OUT:'
|
|
|
|
$flag_path_interm = '/Fo'
|
|
|
|
$flag_path_debug = '/Fd'
|
|
|
|
$flag_path_output = '/Fe'
|
|
|
|
$flag_preprocess_conform = '/Zc:preprocessor'
|
2023-09-16 15:41:07 -07:00
|
|
|
$flag_set_stack_size = '/F'
|
2023-09-15 18:35:27 -07:00
|
|
|
$flag_syntax_only = '/Zs'
|
2023-09-20 21:26:23 -07:00
|
|
|
$flag_wall = '/Wall'
|
|
|
|
$flag_warnings_as_errors = '/WX'
|
2023-09-08 09:42:24 -07:00
|
|
|
|
|
|
|
# This works because this project uses a single unit to build
|
|
|
|
function build-simple
|
|
|
|
{
|
2023-09-26 14:26:35 -07:00
|
|
|
param( [array]$includes, [array]$compiler_args, [array]$linker_args, [string]$unit, [string]$binary )
|
2023-09-08 09:42:24 -07:00
|
|
|
Write-Host "build-simple: msvc"
|
|
|
|
|
2023-09-26 22:16:41 -07:00
|
|
|
$object = $unit -replace '\.(cpp)$', '.obj'
|
|
|
|
$map = $unit -replace '\.(cpp)$', '.map'
|
2023-09-28 17:22:15 -07:00
|
|
|
$object = join-path $path_build (split-path $object -Leaf)
|
|
|
|
$map = join-path $path_build (split-path $map -Leaf)
|
2023-09-26 22:16:41 -07:00
|
|
|
|
|
|
|
# The PDB file has to also be time-stamped so that we can reload the DLL at runtime
|
|
|
|
$timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
|
|
|
|
$pdb = $binary -replace '\.(exe|dll)$', "_$timestamp.pdb"
|
2023-09-08 09:42:24 -07:00
|
|
|
|
|
|
|
$compiler_args += @(
|
|
|
|
$flag_nologo,
|
2023-09-16 15:41:07 -07:00
|
|
|
# $flag_all_cpp,
|
2023-09-20 21:26:23 -07:00
|
|
|
$flag_exceptions_disabled,
|
|
|
|
( $flag_define + '_HAS_EXCEPTIONS=0' ),
|
|
|
|
$flag_RTTI_disabled,
|
2023-09-08 09:42:24 -07:00
|
|
|
$flag_preprocess_conform,
|
|
|
|
$flag_full_src_path,
|
|
|
|
( $flag_path_interm + $path_build + '\' ),
|
|
|
|
( $flag_path_output + $path_build + '\' )
|
|
|
|
)
|
2023-09-15 18:35:27 -07:00
|
|
|
|
|
|
|
if ( $optimize ) {
|
|
|
|
$compiler_args += $flag_optimize_fast
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$compiler_args += $flag_no_optimization
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $debug )
|
|
|
|
{
|
2023-09-08 14:50:22 -07:00
|
|
|
$compiler_args += $flag_debug
|
2023-09-18 17:16:40 -07:00
|
|
|
$compiler_args += ( $flag_define + 'Build_Debug=1' )
|
2023-09-08 09:42:24 -07:00
|
|
|
$compiler_args += ( $flag_path_debug + $path_build + '\' )
|
2023-09-08 14:50:22 -07:00
|
|
|
$compiler_args += $flag_link_win_rt_static_debug
|
2023-09-15 18:35:27 -07:00
|
|
|
|
2023-09-28 15:38:06 -07:00
|
|
|
if ( $optimize ) {
|
2023-09-15 18:35:27 -07:00
|
|
|
$compiler_args += $flag_optimized_debug
|
|
|
|
}
|
2023-09-08 09:42:24 -07:00
|
|
|
}
|
|
|
|
else {
|
2023-09-18 17:16:40 -07:00
|
|
|
$compiler_args += ( $flag_define + 'Build_Debug=0' )
|
2023-09-08 14:50:22 -07:00
|
|
|
$compiler_args += $flag_link_win_rt_static
|
2023-09-08 09:42:24 -07:00
|
|
|
}
|
|
|
|
$compiler_args += $includes | ForEach-Object { $flag_include + $_ }
|
2023-09-16 15:41:07 -07:00
|
|
|
|
|
|
|
$compiler_args += $flag_compile, $unit
|
|
|
|
run-compiler $compiler $unit $compiler_args
|
2023-09-08 09:42:24 -07:00
|
|
|
|
2023-09-08 14:50:22 -07:00
|
|
|
$linker_args += @(
|
2023-09-08 09:42:24 -07:00
|
|
|
$flag_nologo,
|
2023-09-08 14:50:22 -07:00
|
|
|
$flag_link_win_machine_64,
|
2023-09-26 22:16:41 -07:00
|
|
|
$flag_link_no_incremental,
|
2023-09-26 14:26:35 -07:00
|
|
|
( $flag_link_win_path_output + $binary )
|
2023-09-08 09:42:24 -07:00
|
|
|
)
|
2023-09-16 15:41:07 -07:00
|
|
|
if ( $debug ) {
|
2023-09-08 14:50:22 -07:00
|
|
|
$linker_args += $flag_link_win_debug
|
|
|
|
$linker_args += $flag_link_win_pdb + $pdb
|
2023-09-26 14:26:35 -07:00
|
|
|
$linker_args += $flag_link_mapfile + $map
|
2023-09-08 09:42:24 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
}
|
|
|
|
|
|
|
|
$linker_args += $object
|
2023-09-26 14:26:35 -07:00
|
|
|
run-linker $linker $binary $linker_args
|
2023-09-15 18:35:27 -07:00
|
|
|
|
2023-09-16 15:41:07 -07:00
|
|
|
# $compiler_args += $unit
|
|
|
|
# $compiler_args += $flag_linker
|
|
|
|
# $compiler_args += $linker_args
|
|
|
|
# run-compiler $compiler $unit $compiler_args
|
2023-09-08 09:42:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$compiler = 'cl'
|
|
|
|
$linker = 'link'
|
|
|
|
}
|
|
|
|
#endregion Configuration
|
|
|
|
|
2023-09-26 14:26:35 -07:00
|
|
|
#region Building
|
2023-09-08 14:50:22 -07:00
|
|
|
$path_project = Join-Path $path_root 'project'
|
2023-09-26 14:26:35 -07:00
|
|
|
$path_data = Join-Path $path_root 'data'
|
2023-09-26 22:16:41 -07:00
|
|
|
$path_binaries = Join-Path $path_data 'binaries'
|
2023-09-08 14:50:22 -07:00
|
|
|
$path_deps = Join-Path $path_project 'dependencies'
|
2023-09-28 17:22:15 -07:00
|
|
|
$path_codegen = Join-Path $path_project 'codegen'
|
2023-09-08 14:50:22 -07:00
|
|
|
$path_gen = Join-Path $path_project 'gen'
|
|
|
|
$path_platform = Join-Path $path_project 'platform'
|
2023-09-26 14:26:35 -07:00
|
|
|
$path_engine = Join-Path $path_project 'engine'
|
2023-09-08 09:42:24 -07:00
|
|
|
|
|
|
|
$update_deps = Join-Path $PSScriptRoot 'update_deps.ps1'
|
|
|
|
|
2023-09-28 18:21:05 -07:00
|
|
|
$handmade_process_active = Get-Process | Where-Object {$_.Name -like 'handmade_win32*'}
|
|
|
|
|
2023-09-08 09:42:24 -07:00
|
|
|
if ( (Test-Path $path_build) -eq $false ) {
|
|
|
|
New-Item $path_build -ItemType Directory
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (Test-Path $path_deps) -eq $false ) {
|
|
|
|
& $update_deps
|
|
|
|
}
|
|
|
|
|
2023-09-26 22:16:41 -07:00
|
|
|
if ( (Test-Path $path_binaries) -eq $false ) {
|
|
|
|
New-Item $path_binaries -ItemType Directory
|
|
|
|
}
|
|
|
|
|
2023-09-08 12:14:09 -07:00
|
|
|
#region Handmade Runtime
|
2023-09-09 14:06:47 -07:00
|
|
|
$includes = @(
|
2023-09-26 14:26:35 -07:00
|
|
|
$path_project
|
2023-09-09 14:06:47 -07:00
|
|
|
)
|
2023-09-09 17:14:40 -07:00
|
|
|
|
|
|
|
# Microsoft
|
2023-09-08 18:08:57 -07:00
|
|
|
$lib_gdi32 = 'Gdi32.lib'
|
2023-09-09 14:06:47 -07:00
|
|
|
$lib_xinput = 'Xinput.lib'
|
|
|
|
$lib_user32 = 'User32.lib'
|
2023-09-22 12:13:18 -07:00
|
|
|
$lib_winmm = 'Winmm.lib'
|
2023-09-08 15:54:16 -07:00
|
|
|
|
2023-09-09 17:14:40 -07:00
|
|
|
# Github
|
|
|
|
$lib_jsl = Join-Path $path_deps 'JoyShockLibrary/x64/JoyShockLibrary.lib'
|
|
|
|
|
2023-09-16 15:41:07 -07:00
|
|
|
$stack_size = 1024 * 1024 * 4
|
|
|
|
|
2023-09-15 18:35:27 -07:00
|
|
|
$compiler_args = @(
|
|
|
|
($flag_define + 'UNICODE'),
|
|
|
|
($flag_define + '_UNICODE')
|
2023-09-16 15:41:07 -07:00
|
|
|
# ($flag_set_stack_size + $stack_size)
|
2023-09-20 21:26:23 -07:00
|
|
|
$flag_wall
|
|
|
|
$flag_warnings_as_errors
|
|
|
|
$flag_optimize_intrinsics
|
|
|
|
|
2023-09-23 18:03:33 -07:00
|
|
|
($flag_define + 'Build_Unity=1' )
|
2023-09-15 18:35:27 -07:00
|
|
|
)
|
2023-09-08 14:50:22 -07:00
|
|
|
|
2023-09-18 17:16:40 -07:00
|
|
|
if ( $dev ) {
|
|
|
|
$compiler_args += ( $flag_define + 'Build_Development=1' )
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$compiler_args += ( $flag_define + 'Build_Development=0' )
|
|
|
|
}
|
|
|
|
|
2023-09-26 14:26:35 -07:00
|
|
|
if ( $engine )
|
|
|
|
{
|
2023-09-28 10:44:43 -07:00
|
|
|
$path_pdb_lock = Join-Path $path_binaries 'handmade_engine.pdb.lock'
|
|
|
|
New-Item $path_pdb_lock -ItemType File -Force -Verbose
|
|
|
|
|
|
|
|
# Delete old PDBs
|
|
|
|
[Array]$pdb_files = Get-ChildItem -Path $path_binaries -Filter "handmade_engine_*.pdb"
|
2023-09-26 22:16:41 -07:00
|
|
|
foreach ($file in $pdb_files) {
|
|
|
|
Remove-Item -Path $file.FullName -Force
|
|
|
|
Write-Host "Deleted $file" -ForegroundColor Green
|
|
|
|
}
|
|
|
|
|
2023-09-26 14:26:35 -07:00
|
|
|
$engine_compiler_args = $compiler_args
|
|
|
|
$engine_compiler_args += ($flag_define + 'Build_DLL=1' )
|
2023-09-09 17:14:40 -07:00
|
|
|
|
2023-09-26 14:26:35 -07:00
|
|
|
if ( $vendor -eq 'msvc' )
|
|
|
|
{
|
|
|
|
$engine_compiler_args += ($flag_define + 'Engine_API=__declspec(dllexport)')
|
|
|
|
}
|
|
|
|
if ( $vendor -eq 'clang' )
|
|
|
|
{
|
|
|
|
$engine_compiler_args += ($flag_define + 'Engine_API=__attribute__((visibility("default")))')
|
|
|
|
}
|
2023-09-09 17:14:40 -07:00
|
|
|
|
2023-09-26 14:26:35 -07:00
|
|
|
$linker_args = @(
|
2023-09-28 18:57:52 -07:00
|
|
|
$flag_link_dll
|
|
|
|
# $flag_link_optimize_references
|
2023-09-26 14:26:35 -07:00
|
|
|
)
|
2023-09-08 09:42:24 -07:00
|
|
|
|
2023-09-26 22:16:41 -07:00
|
|
|
$unit = Join-Path $path_project 'handmade_engine.cpp'
|
|
|
|
$dynamic_library = Join-Path $path_binaries 'handmade_engine.dll'
|
2023-09-26 14:26:35 -07:00
|
|
|
|
|
|
|
build-simple $includes $engine_compiler_args $linker_args $unit $dynamic_library
|
|
|
|
|
|
|
|
if ( Test-Path $dynamic_library )
|
|
|
|
{
|
2023-09-26 22:16:41 -07:00
|
|
|
# $data_path = Join-Path $path_data 'handmade_engine.dll'
|
|
|
|
# move-item $dynamic_library $data_path -Force
|
|
|
|
$path_lib = $dynamic_library -replace '\.dll', '.lib'
|
|
|
|
$path_exp = $dynamic_library -replace '\.dll', '.exp'
|
|
|
|
Remove-Item $path_lib -Force
|
2023-09-28 18:57:52 -07:00
|
|
|
if ( Test-Path $path_exp ) { Remove-Item $path_exp -Force }
|
2023-09-26 14:26:35 -07:00
|
|
|
|
|
|
|
# We need to generate the symbol table so that we can lookup the symbols we need when loading/reloading the library at runtime.
|
|
|
|
# This is done by sifting through the emitter.map file from the linker for the base symbol names
|
|
|
|
# and mapping them to their found decorated name
|
|
|
|
|
2023-09-28 15:38:06 -07:00
|
|
|
# Initialize the hashtable with the desired order of symbols
|
|
|
|
$engine_symbols = [ordered]@{
|
|
|
|
'on_module_reload' = $null
|
|
|
|
'startup' = $null
|
|
|
|
'shutdown' = $null
|
|
|
|
'update_and_render' = $null
|
|
|
|
'update_audio' = $null
|
|
|
|
}
|
2023-09-26 14:26:35 -07:00
|
|
|
|
2023-09-28 15:38:06 -07:00
|
|
|
$path_engine_obj = Join-Path $path_build 'handmade_engine.obj'
|
2023-09-26 14:26:35 -07:00
|
|
|
$path_engine_map = Join-Path $path_build 'handmade_engine.map'
|
2023-09-28 15:38:06 -07:00
|
|
|
$maxNameLength = ($engine_symbols.Keys | Measure-Object -Property Length -Maximum).Maximum
|
2023-09-26 14:26:35 -07:00
|
|
|
|
|
|
|
Get-Content -Path $path_engine_map | ForEach-Object {
|
2023-09-28 15:38:06 -07:00
|
|
|
# If all symbols are found, exit the loop
|
|
|
|
if ($engine_symbols.Values -notcontains $null) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
# Split the line into tokens
|
|
|
|
$tokens = $_ -split '\s+', 4
|
2023-09-26 14:26:35 -07:00
|
|
|
# Extract only the decorated name using regex for both MSVC and Clang conventions
|
2023-09-28 15:38:06 -07:00
|
|
|
$decoratedName = ($tokens[2] -match '(\?[\w@]+|_Z[\w@]+)') ? $matches[1] : $null
|
|
|
|
|
|
|
|
# Check the origin of the symbol
|
|
|
|
# If the origin matches 'handmade_engine.obj', then process the symbol
|
|
|
|
$originParts = $tokens[3] -split '\s+'
|
|
|
|
$origin = if ($originParts.Count -eq 3) { $originParts[2] } else { $originParts[1] }
|
|
|
|
|
|
|
|
# Diagnostic output
|
|
|
|
if ( $false -and $decoratedName) {
|
|
|
|
write-host "Found decorated name: $decoratedName" -ForegroundColor Yellow
|
|
|
|
write-host "Origin : $origin" -ForegroundColor Yellow
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($origin -like 'handmade_engine.obj') {
|
|
|
|
# Check each regular name against the current line
|
|
|
|
$engine_symbols.Keys | Where-Object { $engine_symbols[$_] -eq $null } | ForEach-Object {
|
|
|
|
if ($decoratedName -like "*$_*") {
|
|
|
|
$engine_symbols[$_] = $decoratedName
|
|
|
|
}
|
2023-09-26 14:26:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
write-host "Engine Symbol Table:" -ForegroundColor Green
|
2023-09-28 15:38:06 -07:00
|
|
|
$engine_symbols.GetEnumerator() | ForEach-Object {
|
|
|
|
$paddedName = $_.Key.PadRight($maxNameLength)
|
|
|
|
$decoratedName = $_.Value
|
2023-09-26 22:16:41 -07:00
|
|
|
write-host "`t$paddedName, $decoratedName" -ForegroundColor Green
|
2023-09-26 14:26:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
# Write the symbol table to a file
|
2023-09-28 17:22:15 -07:00
|
|
|
$path_engine_symbols = Join-Path $path_build 'handmade_engine.symbols'
|
2023-09-28 15:38:06 -07:00
|
|
|
$engine_symbols.Values | Out-File -Path $path_engine_symbols
|
2023-09-26 14:26:35 -07:00
|
|
|
}
|
2023-09-28 10:44:43 -07:00
|
|
|
|
|
|
|
Remove-Item $path_pdb_lock -Force -Verbose
|
2023-09-28 17:22:15 -07:00
|
|
|
|
|
|
|
#region CodeGen
|
2023-09-28 18:21:05 -07:00
|
|
|
if ( $handmade_process_active -eq $null ) {
|
2023-09-28 18:57:52 -07:00
|
|
|
# Delete old PDBs
|
|
|
|
$pdb_files = Get-ChildItem -Path $path_build -Filter "engine_postbuild_gen_*.pdb"
|
|
|
|
foreach ($file in $pdb_files) {
|
|
|
|
Remove-Item -Path $file.FullName -Force
|
|
|
|
Write-Host "Deleted $file" -ForegroundColor Green
|
|
|
|
}
|
|
|
|
|
2023-09-28 17:22:15 -07:00
|
|
|
$engine_codegen_compiler_args = @()
|
|
|
|
$engine_codegen_compiler_args += ( $flag_define + 'GEN_TIME' )
|
|
|
|
|
|
|
|
$engine_codegen_linker_args = @(
|
|
|
|
$flag_link_win_subsystem_console
|
|
|
|
)
|
|
|
|
|
2023-09-28 18:21:05 -07:00
|
|
|
$unit = Join-Path $path_codegen 'engine_postbuild_gen.cpp'
|
|
|
|
$executable = Join-Path $path_build 'engine_postbuild_gen.exe'
|
2023-09-28 17:22:15 -07:00
|
|
|
|
|
|
|
build-simple $includes $engine_codegen_compiler_args $engine_codegen_linker_args $unit $executable
|
|
|
|
write-host
|
|
|
|
|
|
|
|
Push-Location $path_build
|
|
|
|
& $executable
|
|
|
|
Pop-Location
|
|
|
|
|
|
|
|
$path_generated_file = Join-Path $path_build 'engine_symbol_table.hpp'
|
|
|
|
move-item $path_generated_file (join-path $path_gen (split-path $path_generated_file -leaf)) -Force
|
|
|
|
}
|
|
|
|
#endregion CodeGen
|
2023-09-28 18:21:05 -07:00
|
|
|
}
|
2023-09-28 17:22:15 -07:00
|
|
|
|
2023-09-28 18:21:05 -07:00
|
|
|
if ( $platform )
|
|
|
|
{
|
|
|
|
# Delete old PDBs
|
2023-09-26 22:16:41 -07:00
|
|
|
$pdb_files = Get-ChildItem -Path $path_binaries -Filter "handmade_win32_*.pdb"
|
|
|
|
foreach ($file in $pdb_files) {
|
|
|
|
Remove-Item -Path $file.FullName -Force
|
|
|
|
Write-Host "Deleted $file" -ForegroundColor Green
|
|
|
|
}
|
|
|
|
|
2023-09-26 14:26:35 -07:00
|
|
|
$platform_compiler_args = $compiler_args
|
|
|
|
$platform_compiler_args += ($flag_define + 'Build_DLL=0' )
|
|
|
|
|
|
|
|
$linker_args = @(
|
|
|
|
$lib_gdi32,
|
|
|
|
# $lib_xinput,
|
|
|
|
$lib_user32,
|
|
|
|
$lib_winmm,
|
|
|
|
|
|
|
|
$lib_jsl,
|
|
|
|
|
|
|
|
$flag_link_win_subsystem_windows
|
2023-09-28 17:22:15 -07:00
|
|
|
$flag_link_optimize_references
|
2023-09-26 14:26:35 -07:00
|
|
|
)
|
|
|
|
|
2023-09-26 22:16:41 -07:00
|
|
|
$unit = Join-Path $path_project 'handmade_win32.cpp'
|
|
|
|
$executable = Join-Path $path_binaries 'handmade_win32.exe'
|
2023-09-26 14:26:35 -07:00
|
|
|
|
|
|
|
build-simple $includes $platform_compiler_args $linker_args $unit $executable
|
|
|
|
|
2023-09-26 22:16:41 -07:00
|
|
|
# if ( Test-Path $executable )
|
|
|
|
# {
|
|
|
|
# $data_path = Join-Path $path_data 'handmade_win32.exe'
|
|
|
|
# move-item $executable $data_path -Force
|
|
|
|
# }
|
|
|
|
}
|
|
|
|
|
|
|
|
$path_jsl_dll = Join-Path $path_binaries 'JoyShockLibrary.dll'
|
|
|
|
if ( (Test-Path $path_jsl_dll) -eq $false )
|
|
|
|
{
|
|
|
|
$path_jsl_dep_dll = Join-Path $path_deps 'JoyShockLibrary/x64/JoyShockLibrary.dll'
|
|
|
|
Copy-Item $path_jsl_dep_dll $path_jsl_dll
|
2023-09-26 14:26:35 -07:00
|
|
|
}
|
2023-09-08 12:14:09 -07:00
|
|
|
#endregion Handmade Runtime
|
|
|
|
|
|
|
|
Pop-Location
|
2023-09-26 14:26:35 -07:00
|
|
|
#endregion Building
|