Skip to content

Instantly share code, notes, and snippets.

@jonforums
Last active December 14, 2015 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonforums/5080257 to your computer and use it in GitHub Desktop.
Save jonforums/5080257 to your computer and use it in GitHub Desktop.
Automate building TclTk on Windows with mingw/mingw-w64
#requires -version 2.0
# Author: Jon Maken
# License: 3-clause BSD
# Revision: 2013-03-04 18:48:14 -0600
#
# TODO:
# - extract generics into a downloadable utils helper module
# - add try-catch-finally error handling
# - add checkpoint support
# - support x86 and x64 builds (configure's --enable-64bit)
param(
[parameter(Mandatory=$true,
Position=0,
HelpMessage='TclTk version to build (eg - 8.6.0)')]
[alias('i')]
[string] $tcltk,
# TODO update to use DevKit's `provider-bits-version` syntax
[parameter(HelpMessage='mingw toolchain flavor to use (eg - mingw, mingw64)')]
[validateset('mingw','mingw64')]
[string] $toolchain = 'mingw',
[parameter(HelpMessage='Path to 7-Zip command line tool')]
[string] $7ZA = 'C:/tools/7za.exe',
[parameter(HelpMessage='Path to DevKit root directory')]
[string] $DEVKIT = 'C:/Devkit'
)
$msg_color = 'Yellow'
$root = split-path -parent $script:MyInvocation.MyCommand.Path
$source = @{tcl = "tcl${tcltk}-src.tar.gz"; tk = "tk${tcltk}-src.tar.gz"}
$repo_root = 'http://prdownloads.sourceforge.net/tcl/'
$archive = @{tcl = "${repo_root}$($source.tcl)"; tk = "${repo_root}$($source.tk)"}
#$archive_hash = "${repo_root}${source}.sha1"
# download and verify
# TODO implement progress bar when extracted to util helper module
if (-not ((test-path $source.tcl) -or (test-path $source.tk))) {
$client = new-object System.Net.WebClient
$client.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
#$hash = $client.DownloadString($archive_hash).Trim(" ","`r","`n").ToLower()
foreach ($src in $archive.keys) {
if (test-path $source[$src]) { continue }
write-host "[INFO] downloading $($archive[$src])" -foregroundcolor $msg_color
$client.DownloadFile($archive[$src], "$PWD/$($source[$src])")
}
<# TODO implement by embedding hash values as data into this file
$hasher = new-object System.Security.Cryptography.SHA1Managed
$fs = new-object System.IO.FileStream "$PWD/$source", 'Open', 'Read'
$test_hash = [BitConverter]::ToString($hasher.ComputeHash($fs)).Replace('-','').ToLower()
$fs.Close()
if ($test_hash -ne $hash) {
write-host "[ERROR] $source validation failed, exiting" -foregroundcolor 'Red'
break
}
#>
}
# extract
foreach ($tgz in $source.values) {
write-host "[INFO] extracting $tgz" -foregroundcolor $msg_color
$tar_file = "$($tgz.Substring(0, $tgz.LastIndexOf('-')))*.tar"
(& "$7ZA" "x" $tgz) -and (& "$7ZA" "x" $tar_file) -and (rm $tar_file) | out-null
}
# patch, configure, build, archive
foreach ($dir in "tcl${tcltk}", "tk${tcltk}") {
push-location $dir/win
# pre-configure patch - NA
# activate toolchain
# FIXME don't activate toolchain multiple times
write-host "[INFO] activating toolchain" -foregroundcolor $msg_color
. "$DEVKIT/devkitvars.ps1" | out-null
# configure
write-host "[INFO] configuring $dir" -foregroundcolor $msg_color
$clean_pwd = $(split-path $PWD -parent).Replace('\','/')
$install_dir = "$clean_pwd/my_install"
$cfg_args = "--prefix=$install_dir --enable-threads"
if ($dir -match '^tcl') { $tcl_build_dir = "$clean_pwd/win" }
if ($dir -match '^tk') { $cfg_args += " --with-tcl=$tcl_build_dir" }
sh -c "./configure $cfg_args" | out-null
# build
write-host "[INFO] building $dir" -foregroundcolor $msg_color
sh -c "make" | out-null
# install
sh -c "make install" | out-null
# archive
push-location "$install_dir"
write-host "[INFO] creating binary archive for $dir" -foregroundcolor $msg_color
$bin_archive = "${dir}-x86-windows-bin.7z"
& "7ZA" "a" "-mx=9" "-r" $bin_archive "*" | out-null
pop-location
# hoist binary archive to top level
mv "$install_dir\$bin_archive" $(split-path (split-path $PWD -parent) -parent)
pop-location
}
# cleanup
write-host "[INFO] cleaning up" -foregroundcolor $msg_color
foreach ($dir in "tcl${tcltk}", "tk${tcltk}") { rm -recurse -force $dir }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment