install_strawberry_p4perl.ps1 #1

  • //
  • p4perl/
  • r16.1/
  • install_strawberry_p4perl.ps1
  • View
  • Commits
  • Open Download .zip Download (4 KB)
<#
    .Synopsis
        This script installs P4Perl for Strawberry Perl
        Copyright (c) 2017, Perforce Software, Inc.	All rights reserved.
        
    .Description
        It assumes Strawberry Perl is already installed (32 bit or 64 bit)
        and is the Perl available in the path. It also requires MinGW
        to be in the path (for dmake, gcc etc).

        You can set this manually:
        
        $env:path = "C:\Strawberry\perl\bin;C:\Strawberry\c\bin;" + $env:path

        Run this script in a temp directory where it can download .zip files
		and create sub-directories as appropriate, e.g. in c:\temp

        You may need to execute "set-ExecutionPolicy remotesigned" to allow
        Powershell to run this script (as Administrator)
                
#>

$p4perlDownload = 'https://swarm.workshop.perforce.com/projects/p4perl/archives/main.zip' 
$p4apiDownload = 'https://swarm.workshop.perforce.com/projects/perforce_software-p4/archives/2016-1.zip'
$jamDownload = 'https://swarm.workshop.perforce.com/downloads/guest/perforce_software/jam/jam-2.6.zip'
$p4apiver = "2016.1.1429894";

Function Get-Date-Time () {
    Get-Date -format "yyyy\/MM\/dd HH\:mm\:ss"
}

Function Log([string]$message) {
    # Logs output to file and to console
    $datetime = get-date-time
    write-host "$datetime $message"
   #Append-To-File "$datetime $message" $global:Logfile
}

Function DownloadAndUnzip([string]$download, [string]$zipfile, [string]$targetdir) {
	Log "Downloading: $download"
    if (!(Test-Path -path $targetdir)) {
        md $targetdir
    }
    (New-Object Net.WebClient).DownloadFile($download, $zipfile)
    (new-object -com shell.application).namespace($targetdir).CopyHere((new-object -com shell.application).namespace($zipfile).Items(), 16)
	# if ($lastexitcode -ne 0) {
		# throw "Error unzipping"
	# }
}

$rootdir = get-location
# Check for required commands in our path - exceptions thrown if not found
$cmd = get-command "perl.exe"
$cmd = get-command "gcc.exe"

$jamTargetdir = Join-Path $rootdir 'jam'
$jamZipfile = Join-Path $rootdir 'jam.zip'
DownloadAndUnzip $jamDownload $jamZipfile $jamTargetdir

$p4perlTargetdir = Join-Path $rootdir 'p4perl'
$p4perlZipfile = Join-Path $rootdir 'p4perl.zip'
DownloadAndUnzip $p4perlDownload $p4perlZipfile $p4perlTargetdir

$p4apiTargetdir = Join-Path $rootdir 'p4api'
$p4apiZipfile = Join-Path $rootdir 'p4src.zip'	
DownloadAndUnzip $p4apiDownload $p4apiZipfile $p4apiTargetdir

Log "Decide on 32 vs 64 bit depending on Perl version installed"
$ver = & perl -V
$archname = [regex]::match($ver, 'archname=(\S+)').Groups[1].Value
$arch = '86'
if ($archname -match 'x64') { $arch = '64' }
Log "`nPerl architecture is: $arch"

# Build Jam
Log "`n======================`nBuilding Jam`n"
$jamdir = Join-Path $jamTargetdir 'jam-2.6'
cd $jamdir
$makefile = 'Makefile'
# Configure for MinGW
(Get-Content $makefile).replace('#CC = gcc', 'CC = gcc').replace('#CFLAGS = -DMINGW', 'CFLAGS = -DMINGW') | Set-Content $makefile
dmake
if ($lastexitcode -ne 0) {
	throw "Error compiling P4API"
}

$env:path = "$jamdir\bin.mingwx$arch;" + $env:path

Log "======================`nUsing Jam to build P4API`n"

cd "$p4apiTargetdir\2016-1"

$fixfile = 'sys\fileiont.cc'
(Get-Content $fixfile).replace('# if defined( OS_MINGW64 ) == defined( OS_MINGW )', 
        '# if defined( OS_MINGW )') | Set-Content $fixfile

jam -sPRODUCTION=1 p4api.tar
if (!Test-Path "$p4apiTargetdir\p4-bin\bin.mingwx$arch\p4api-$p4apiver.main\sample\Version") {
	throw "Failed to find results of p4api build"
}

Log "======================`nBuilding P4Perl`n"

cd "$p4perlTargetdir\main"
copy "$p4apiTargetdir\p4-bin\bin.mingwx$arch\p4api-$p4apiver.main\sample\Version" .
perl .\Makefile.PL -make=dmake --apidir C:\temp\p4api\p4-bin\bin.mingwx$arch\p4api-$p4apiver.main

dmake 
if ($lastexitcode -ne 0) {
	throw "Error Building P4Perl"
}
Log "Installing P4Perl`n"
dmake install 
if ($lastexitcode -ne 0) {
	throw "Error installing P4Perl"
}
Log "Testing that P4Perl has been installed`n"
$ver = & perl -MP4 -e "print P4::Identify()"
if ($ver -match "Rev\. P4PERL/NTX$arch/2016.1") {
	Log "`nP4Perl has been installed successfully!`n$ver"
} else {
	Log "`nP4Perl NOT installed successfully!`n$ver"
}
# Change User Description Committed
#1 21613 C. Thomas Tyler Populate -r -o -S //p4perl/r16.1.
//p4perl/main/install_strawberry_p4perl.ps1
#1 21593 C. Thomas Tyler Populate -o //guest/perforce_software/p4perl/main/...
//p4perl/main/....
//guest/perforce_software/p4perl/main/install_strawberry_p4perl.ps1
#1 21585 Robert Cowham Add a Powershell script to do the installation for P4Perl
Tested with Strawberry Perl 5.22 and 5.24 (both 32 and 64 bit versions).