Last active
December 14, 2015 23:39
-
-
Save jonforums/5167198 to your computer and use it in GitHub Desktop.
Automate building minised on Windows with mingw/mingw-w64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -version 2.0 | |
# Author: Jon Maken | |
# License: 3-clause BSD | |
# Revision: 2013-03-14 23:17:01 -0600 | |
# | |
# TODO: | |
# - extract generics into a downloadable utils helper module | |
# - add proper try-catch-finally error handling | |
param( | |
[parameter(Mandatory=$true, | |
Position=0, | |
HelpMessage='minised version to build (eg - 1.14)')] | |
[validateset('1.14')] | |
[alias('v')] | |
[string] $version, | |
[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 | |
$libname = 'minised' | |
$source = "${libname}-${version}.tar.gz" | |
$source_dir = "${libname}-${version}" | |
$repo_root = "http://dl.exactcode.de/oss/${libname}/" | |
$archive = "${repo_root}${source}" | |
$hash_uri = "https://raw.github.com/jonforums/poshlab/master/hashery/${libname}.sha1" | |
# download source archive | |
if(-not (Test-Path $source)) { | |
Import-Module BitsTransfer | |
Write-Host "[INFO] downloading ${archive}" -foregroundcolor $msg_color | |
Start-BitsTransfer $archive "$PWD\$source" | |
} | |
# download hash data and validate source archive | |
Write-Host "[INFO] validating $source" -foregroundcolor $msg_color | |
$client = New-Object System.Net.WebClient | |
$hash = ConvertFrom-StringData $client.DownloadString($hash_uri) | |
try { | |
$hasher = New-Object System.Security.Cryptography.SHA1Cng | |
$fs = New-Object System.IO.FileStream "$PWD\$source", 'Open', 'Read' | |
$test_hash = [BitConverter]::ToString($hasher.ComputeHash($fs)).Replace('-','').ToLower() | |
} finally { | |
$fs.Close() | |
} | |
if ($test_hash -ne $hash[$version].ToLower()) { | |
Write-Host "[ERROR] $source validation failed, exiting" -foregroundcolor red | |
break | |
} | |
# extract | |
Write-Host "[INFO] extracting $source" -foregroundcolor $msg_color | |
$tar_file = "$($source.Substring(0, $source.LastIndexOf('-')))*.tar" | |
(& "$7ZA" "x" $source) -and (& "$7ZA" "x" $tar_file) -and (rm $tar_file) | Out-Null | |
# patch, configure, build, archive | |
Push-Location "${source_dir}" | |
# activate toolchain | |
Write-Host "[INFO] activating toolchain" -foregroundcolor $msg_color | |
. "$DEVKIT/devkitvars.ps1" | Out-Null | |
# configure | |
Write-Host "[INFO] configuring ${source_dir}" -foregroundcolor $msg_color | |
$install_dir = "$($PWD.ToString().Replace('\','/'))/my_install" | |
mkdir "$install_dir" | Out-Null | |
# build | |
Write-Host "[INFO] building ${source_dir}" -foregroundcolor $msg_color | |
sh -c "make CC=gcc" | Out-Null | |
# install | |
strip -s minised.exe | Out-Null | |
cp minised.exe, README, LICENSE -destination "$install_dir" | Out-Null | |
# archive | |
Push-Location "$install_dir" | |
Write-Host "[INFO] creating binary archive for ${source_dir}" -foregroundcolor $msg_color | |
$bin_archive = "${source_dir}-x86-windows-bin.7z" | |
& "$7ZA" "a" "-mx=9" "-r" $bin_archive "*" | Out-Null | |
Pop-Location | |
Pop-Location | |
# hoist binary archive and cleanup | |
Write-Host "[INFO] cleaning up" -foregroundcolor $msg_color | |
mv "$install_dir/$bin_archive" "$PWD" -force | |
rm "${source_dir}" -recurse -force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment