# Copyright (C) 2017-2025 Alexander Schoepe, Bochum, DE, <schoepe@users.sourceforge.net>
# Distributed under BSD license.

# BuildType: MSys / gcc

proc Init_tbcload { libName libVersion } {
    SetScriptAuthor    $libName "Alexander Schoepe" "schoepe@users.sourceforge.net"
    SetLibHomepage     $libName "https://github.com/tcltk-depot/tbcload"
    SetLibDependencies $libName "Tcl"
    SetPlatforms       $libName "All"
    SetWinCompilers    $libName "gcc"
}

proc Build_tbcload { libName libVersion buildDir instDir devDir distDir } {
    if { [UseStage "Extract" $libName] } {
        ExtractLibrary $libName $buildDir
    }

    if { [UseStage "Configure" $libName] } {
        set flags  ""
        set cflags ""
        append cflags [GetPermissiveCFlags] " "
        append cflags [GetDarwinCFlags]     " "
        if { [string trim $cflags] ne "" } {
            append flags "CFLAGS='$cflags' "
        }
        TeaConfigTcl $libName $buildDir $instDir $flags
    }

    if { [UseStage "Compile" $libName] } {
        MSysBuild $libName $buildDir "install-binaries"
    }

    if { [UseStage "Distribute" $libName] } {
        StripLibraries "$instDir"
        LibFileCopy "$instDir"  "$devDir/[GetTclDir]"   "*"  true
        LibFileCopy "$instDir"  "$distDir/[GetTclDir]"  "*"  true

        if { ! [UseTclPkgVersion] } {
            FileRename "$devDir/[GetTclLibDir]/$libName$libVersion"   "$devDir/[GetTclLibDir]/$libName"
            FileRename "$distDir/[GetTclLibDir]/$libName$libVersion"  "$distDir/[GetTclLibDir]/$libName"
        }
    }
    return true
}
