#!/usr/bin/perl -w use strict; my $git = "C:\\Program Files\\Git\\bin\\git.exe"; my $repo = "C:\\Users\\am\\Documents\\ShemovCleaner"; my $builddir = 'C:\Users\am\Documents\ShemovCleaner-Release'; my $sevenzip = 'C:\Program Files\7-Zip\7z.exe'; my $finaldest = 'C:\Users\am\bin\ShemovCleaner\ShemovCleaner.exe'; chdir $repo; my $branchcmd = "\"$git\" branch"; my $branch; open (my $bfh, '-|', $branchcmd); while(<$bfh>){ if(m#\*\s*(.*)#){ $branch = $1; } } close($bfh); my $commitcmd = "\"$git\" log -n 1 --format=" . '"%h - %aD" --abbrev-commit --abbrev=12'; open (my $cfh, '-|', $commitcmd); my $commit = <$cfh>; close ($cfh); chomp($commit); chdir $builddir; unlink glob "*.*"; chdir "$builddir\\release" or die "horribly"; unlink glob "*.*"; chdir $repo; my $archivecmd = "\"$git\" archive --format zip -o $builddir\\smc.zip HEAD"; system($archivecmd); chdir $builddir; my $unzipcmd = "\"$sevenzip\" x $builddir\\smc.zip"; system($unzipcmd); open (my $main, '<', "main.cpp"); open (my $main2, '>', "main2.cpp"); while(<$main>){ if(m#__build_info__#){ my $new = $_; $new =~ s#__build_info__#$branch branch#; print $main2 $new; }else{ print $main2 $_; } } close ($main); close ($main2); unlink ("main.cpp"); rename ("main2.cpp", "main.cpp"); open (my $cleaner, '<', "shemovcleaner.cpp"); open (my $cleaner2, '>', "shemovcleaner2.cpp"); while(<$cleaner>){ if(m#/\* __debug build__ \*/#){ my $new = $_; $new =~ s#/\* __debug build__ \*/#$commit#; print $cleaner2 $new; }else{ print $cleaner2 $_; } } close ($cleaner); close ($cleaner2); unlink ("shemovclenaner.cpp"); rename ("shemovcleaner2.cpp", "shemovcleaner.cpp"); open (my $batch, '>', "make.cmd"); print $batch 'PATH="c:\psql\10.1\bin;C:\Qt\Tools\mingw530_32\bin;C:\Qt\5.10.0\mingw53_32\bin;C:\Qt\Tools\mingw530_32\bin;C:\Program Files (x86)\Google\Chrome\Application;C:\Perl64\site\bin;C:\Perl64\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\GNU\GnuPG\pub;C:\Program Files\Git\cmd;C:\Program Files\OpenVPN\bin;C:\Users\am\AppData\Local\Microsoft\WindowsApps;"', "\n"; print $batch 'C:\Qt\5.10.0\mingw53_32\bin\qmake.exe C:\Users\am\Documents\ShemovCleaner-Release\ShemovCleaner.pro -spec win32-g++', "\n"; print $batch 'C:\Qt\5.10.0\mingw53_32\bin\qmake.exe C:\Users\am\Documents\ShemovCleaner-Release\ShemovCleaner.pro -o Makefile', "\n"; print $batch 'C:\Qt\Tools\mingw530_32\bin\mingw32-make.exe -j 5', "\n"; print $batch 'copy /Y release\ShemovCleaner.exe ', $finaldest; close($batch); system("make.cmd");