diff --git a/package/win/compile_wrapper.ps1 b/package/win/compile_wrapper.ps1 index c5d603ef3..44fdfe90b 100644 --- a/package/win/compile_wrapper.ps1 +++ b/package/win/compile_wrapper.ps1 @@ -1,30 +1,38 @@ # Short Powershell script to build a wrapper exec -if ($args[0]) -{ - $perlver = $args[0] -} else -{ - $perlver = 524 -} +Param +( + [string]$perlVersion = "524", + [string]$STRAWBERRY_PATH = "C:\Strawberry", + # Path to C++ compiler, or just name if it is in path + [string]$cxx = "g++" +) -$perllib = "-lperl$perlver" -$shell_loc = "..\common\shell.cpp" +function Get-ScriptDirectory +{ + $Invocation = (Get-Variable MyInvocation -Scope 1).Value + Split-Path $Invocation.MyCommand.Path +} +$scriptDir = Get-ScriptDirectory + +$perllib = "-lperl$perlVersion" +$shell_loc = "${scriptDir}\..\common\shell.cpp" # Build the resource file (used to load icon, etc) -windres slic3r.rc -O coff -o slic3r.res +windres ${scriptDir}\slic3r.rc -O coff -o ${scriptDir}\slic3r.res # Compile an object file that does not have gui forced. -g++ -c -I'C:\strawberry\perl\lib\CORE\' $shell_loc -o slic3r.o +Invoke-Expression "$cxx -c -I'${STRAWBERRY_PATH}\perl\lib\CORE\' $shell_loc -o ${scriptDir}/slic3r.o" + # Compile an object file with --gui automatically passed as an argument -g++ -c -I'C:\strawberry\perl\lib\CORE\' -DFORCE_GUI $shell_loc -o slic3r-gui.o +Invoke-Expression "$cxx -c -I'${STRAWBERRY_PATH}\perl\lib\CORE\' -DFORCE_GUI $shell_loc -o ${scriptDir}/slic3r-gui.o" # Build the EXE for the unforced version as slic3r-console -g++ -static-libgcc -static-libstdc++ -L'C:\strawberry\c\lib' -L'C:\strawberry\perl\bin' -L'C:\strawberry\perl\lib\CORE\' $perllib slic3r.o slic3r.res -o slic3r-console.exe | Write-Host +Invoke-Expression "$cxx -static-libgcc -static-libstdc++ -L'${STRAWBERRY_PATH}\c\lib' -L'${STRAWBERRY_PATH}\perl\bin' -L'${STRAWBERRY_PATH}\perl\lib\CORE\' $perllib ${scriptDir}/slic3r.o ${scriptDir}/slic3r.res -o ${scriptDir}/slic3r-console.exe | Write-Host" # Build the EXE for the forced GUI -g++ -static-libgcc -static-libstdc++ -L'C:\strawberry\c\lib' -mwindows -L'C:\strawberry\perl\bin' -L'C:\strawberry\perl\lib\CORE\' $perllib slic3r-gui.o slic3r.res -o slic3r.exe | Write-Host +Invoke-Expression "$cxx -static-libgcc -static-libstdc++ -L'${STRAWBERRY_PATH}\c\lib' -mwindows -L'${STRAWBERRY_PATH}\perl\bin' -L'${STRAWBERRY_PATH}\perl\lib\CORE\' $perllib ${scriptDir}/slic3r-gui.o ${scriptDir}/slic3r.res -o ${scriptDir}/slic3r.exe | Write-Host" # Build an extra copy of the GUI version that creates a console window -g++ -static-libgcc -static-libstdc++ -L'C:\strawberry\c\lib' -L'C:\strawberry\perl\bin' -L'C:\strawberry\perl\lib\CORE\' $perllib slic3r-gui.o slic3r.res -o slic3r-debug-console.exe | Write-Host +Invoke-Expression "$cxx -static-libgcc -static-libstdc++ -L'${STRAWBERRY_PATH}\c\lib' -L'${STRAWBERRY_PATH}\perl\bin' -L'${STRAWBERRY_PATH}\perl\lib\CORE\' $perllib ${scriptDir}/slic3r-gui.o ${scriptDir}/slic3r.res -o ${scriptDir}/slic3r-debug-console.exe | Write-Host" diff --git a/package/win/package_win32.ps1 b/package/win/package_win32.ps1 index 3ebf49ae6..c9ea3d419 100644 --- a/package/win/package_win32.ps1 +++ b/package/win/package_win32.ps1 @@ -2,44 +2,78 @@ # Licensed under the same license as the rest of Slic3r. # ------------------------ # You need to have Strawberry Perl 5.24.0.1 (or slic3r-perl) installed for this to work, +Param +( + # Perl version major/minor number. Slic3r perl uses 524 + [string]$perlVersion = "524", + # Override the output file name. + [string]$outputFile = "", + [string]$currentDate = "$(Get-Date -UFormat '%Y.%m.%d')", + # Override the branch name used in the output. Otherwise autodetect based on git. + [string]$branch = "", + #This is "32bit" or "64bit". It will detect based on presence of libglut. + [string]$arch = $env:ARCH, + # Change this to where you have Strawberry Perl installed. + [string]$STRAWBERRY_PATH = "C:\Strawberry", + [switch]$skipInstallPAR +) + +function Get-ScriptDirectory +{ + $Invocation = (Get-Variable MyInvocation -Scope 1).Value + Split-Path $Invocation.MyCommand.Path +} +$scriptDir = Get-ScriptDirectory + echo "Make this is run from the perl command window." echo "Requires PAR." -New-Variable -Name "current_branch" -Value "" -New-Variable -Name "current_date" -Value "$(Get-Date -UFormat '%Y.%m.%d')" -New-Variable -Name "output_file" -Value "" +$perldll = "perl$perlVersion" -if ($args[0]) { - $perlversion = $args[0] -} else { - $perlversion = "524" +if ($branch -eq "") { + git branch | foreach { + if ($env:APPVEYOR) { + if ($_ -match "` (.*)") { + $branch += $matches[1] + } + } else { + if ($_ -match "\*` (.*)"){ + $branch += $matches[1] + } + } + } } -$perldll = "perl$perlversion" +if ($outputFile -eq "") { + $outputFile = $output_zip +} -git branch | foreach { - if ($env:APPVEYOR) { - if ($_ -match "` (.*)") { - $current_branch += $matches[1] - } - } else { - if ($_ -match "\*` (.*)"){ - $current_branch += $matches[1] - } - } +if (!($arch -eq "64bit" -Or $arch -eq "32bit")) { + # detect current version through libglut + if (Test-Path "${STRAWBERRY_PATH}\c\bin\libglut-0__.dll") { + $arch = "64bit" + } else { + $arch = "32bit" + } + echo "Arch: $arch" } if ($env:APPVEYOR) { - $output_dir = "${pwd}\..\..\Slic3r-${current_branch}.${current_date}.${env:APPVEYOR_BUILD_NUMBER}.$(git rev-parse --short HEAD).${env:ARCH}.zip" + $output_zip = "${scriptDir}\..\..\Slic3r-${branch}.${currentDate}.${env:APPVEYOR_BUILD_NUMBER}.$(git rev-parse --short HEAD).${arch}.zip" } else { - $output_dir = "${pwd}\..\..\Slic3r-${current_branch}.${current_date}.$(git rev-parse --short HEAD).zip" + $output_zip = "${scriptDir}\..\..\Slic3r-${branch}.${currentDate}.$(git rev-parse --short HEAD).${arch}.zip" } -# Change this to where you have Strawberry Perl installed. -New-Variable -Name "STRAWBERRY_PATH" -Value "C:\Strawberry" +if ($outputFile -eq "") { + $outputFile = $output_zip +} -cpanm "PAR::Packer" -if ($env:ARCH -eq "32bit") { +if (-Not $skipInstallPAR) { + cpanm "PAR::Packer" +} + +# Some file names change based on 64bit/32bit. Set them here. +if ($arch -eq "32bit") { $perlarch = "sjlj" $glut = "libglut-0_.dll" $pthread= "pthreadGC2-w32.dll" @@ -49,17 +83,21 @@ if ($env:ARCH -eq "32bit") { $pthread= "pthreadGC2-w64.dll" } +if (!( (Test-Path -Path "${scriptDir}\slic3r.exe") -And (Test-Path -Path "${scriptDir}\slic3r-console.exe") -And (Test-Path -Path "${scriptDir}\slic3r-debug-console.exe") ) ) { + echo "Compiling Slic3r binaries" + & ${scriptDir}\compile_wrapper.ps1 -perlVersion=$perlVersion -STRAWBERRY_PATH=$STRAWBERRY_PATH +} pp ` --a "slic3r.exe;Slic3r.exe" ` --a "slic3r-console.exe;Slic3r-console.exe" ` --a "slic3r-debug-console.exe;Slic3r-debug-console.exe" ` --a "../../lib;lib" ` --a "../../local-lib;local-lib" ` --a "../../slic3r.pl;slic3r.pl" ` --a "../../var;var" ` --a "../../FreeGLUT/freeglut.dll;freeglut.dll" ` --a "${STRAWBERRY_PATH}\perl\bin\perl${perlversion}.dll;perl${perlversion}.dll" ` +-a "${scriptDir}/slic3r.exe;Slic3r.exe" ` +-a "${scriptDir}/slic3r-console.exe;Slic3r-console.exe" ` +-a "${scriptDir}/slic3r-debug-console.exe;Slic3r-debug-console.exe" ` +-a "${scriptDir}/../../lib;lib" ` +-a "${scriptDir}/../../local-lib;local-lib" ` +-a "${scriptDir}/../../slic3r.pl;slic3r.pl" ` +-a "${scriptDir}/../../var;var" ` +-a "${scriptDir}/../../FreeGLUT/freeglut.dll;freeglut.dll" ` +-a "${STRAWBERRY_PATH}\perl\bin\perl${perlVersion}.dll;perl${perlVersion}.dll" ` -a "${STRAWBERRY_PATH}\perl\bin\libstdc++-6.dll;libstdc++-6.dll" ` -a "${STRAWBERRY_PATH}\perl\bin\libgcc_s_${perlarch}-1.dll;libgcc_s_${perlarch}-1.dll" ` -a "${STRAWBERRY_PATH}\perl\bin\libwinpthread-1.dll;libwinpthread-1.dll" ` @@ -145,14 +183,11 @@ pp ` -M XSLoader ` -B ` -M lib ` --p ..\..\slic3r.pl -o ..\..\slic3r.par +-p ${scriptDir}\..\..\slic3r.pl -o ${scriptDir}\..\..\slic3r.par # switch renaming based on whether or not using packaged exe or zip # make this more useful for not being on the appveyor server -if ($env:APPVEYOR) { - copy ..\..\slic3r.par ${output_file} -} else { - copy ..\..\slic3r.par ${output_file} -} -del ..\..\slic3r.par +copy ${scriptDir}\..\..\slic3r.par ${outputFile} +echo "Package saved as ${outputFile}" +del ${scriptDir}\..\..\slic3r.par