Compile perl in Windows
Q. How do I compile my perl script under Windows?
A. The simplest thing is to download and install Strawberry Perl (it is free).
Once installed, get run the following:
perl -MCPAN -e "install PAR::Packer"
and install Packer. Once installed, you can compile a simple script into one big exe file:
pp -o ProgramName.exe MyPerlScript.pl
If you want to compile a GUI (without the command screen in the background), you can run this command:
pp --gui -o sample.exe sample.pl
You can do all kinds of fancy things, such as versioning and custom icon. Use this template as a sample (I have not tested the script below, but the code above worked for simple compilation):
:: file:compile-morphus.1.2.3.dev.ysg.cmd v1.0.0 :: disable the echo @echo off :: this is part of the name of the file - not used set _Action=run :: the name of the Product next_line_is_templatized set _ProductName=morphus :: the version of the current Product next_line_is_templatized set _ProductVersion=1.2.3 :: could be dev , test , dev , prod next_line_is_templatized set _ProductType=dev :: who owns this Product / environment next_line_is_templatized set _ProductOwner=ysg :: identifies an instance of the tool ( new instance for this version could be created by simply changing the owner ) set _EnvironmentName=%_ProductName%.%_ProductVersion%.%_ProductType%.%_ProductOwner% :: go the run dir cd %~dp0 :: do 4 times going up for /L %%i in (1,1,5) do pushd .. :: The BaseDir is 4 dirs up than the run dir set _ProductBaseDir=%CD% :: debug echo BEFORE _ProductBaseDir is %_ProductBaseDir% :: remove the trailing \ IF %_ProductBaseDir:~-1%==\ SET _ProductBaseDir=%_ProductBaseDir:~0,-1% :: debug echo AFTER _ProductBaseDir is %_ProductBaseDir% :: debug pause :: The version directory of the Product set _ProductVersionDir=%_ProductBaseDir%\%_ProductName%\%_EnvironmentName% :: the dir under which all the perl scripts are placed set _ProductVersionPerlDir=%_ProductVersionDir%\sfw\perl :: The Perl script performing all the tasks set _PerlScript=%_ProductVersionPerlDir%\%_Action%_%_ProductName%.pl :: where the log events are stored set _RunLog=%_ProductVersionDir%\data\log\compile-%_ProductName%.cmd.log :: define a favorite editor set _MyEditor=textpad ECHO Check the variables set _ :: debug PAUSE :: truncate the run log echo date is %date% time is %time% > %_RunLog% :: uncomment this to debug all the vars :: debug set>> %_RunLog% :: for each perl pm and or pl file to check syntax and with output to logs for /f %%i in ('dir %_ProductVersionPerlDir%\*.pl /s /b /a-d' ) do echo %%i >> %_RunLog%&perl -wc %%i | tee -a%_RunLog% 2>&1 :: for each perl pm and or pl file to check syntax and with output to logs for /f %%i in ('dir %_ProductVersionPerlDir%\*.pm /s /b /a-d' ) do echo %%i >> %_RunLog%&perl -wc %%i | tee -a%_RunLog% 2>&1 :: now open the run log cmd /c start /max %_MyEditor% %_RunLog% :: this is the call without debugging :: old echo CFPoint1OK The run cmd script %0 is executed >> %_RunLog% echo CFPoint2OKcompile the exe fileSTDOUT and STDERRto a single _RunLog file >> %_RunLog% cd %_ProductVersionPerlDir% pp -o %_Action%_%_ProductName%.exe %_PerlScript% | tee -a %_RunLog% 2>&1 :: open the run log cmd /c start /max %_MyEditor% %_RunLog% :: uncomment this line to wait for 5 seconds :: ping localhost -n 5 :: uncomment this line to see what is happening :: PAUSE :: ::::::: :: Purpose: :: To compile every *.pl file into *.exe file under a folder ::::::: :: Requirements : :: perl , pp , win gnu utils tee :: perl -MCPAN -e "install PAR::Packer" :: text editor supporting <> < > cmd call syntax
:::::::
:: VersionHistory
:: 1.0.0 --- 2012-06-23 12:05:45 --- ysg --- Initial creation from run_morphus.cmd
:::::::
:: eof file:compile-morphus.1.2.3.dev.ysg.cmd v1.0.0
Last Updated on Tuesday, 27 June 2017 14:14
Comments (1)
Add your comment
yvComment v.1.24.0
thank you!