1#! 2#------------------------------------------------------------------------------- 3# pack_zip.pl 4# 5# Copyright (C) 2010,2017 Oliver Hamann. 6# 7# Homepage: http://eaglemode.sourceforge.net/ 8# 9# This program is free software: you can redistribute it and/or modify it under 10# the terms of the GNU General Public License version 3 as published by the 11# Free Software Foundation. 12# 13# This program is distributed in the hope that it will be useful, but WITHOUT 14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15# FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for 16# more details. 17# 18# You should have received a copy of the GNU General Public License version 3 19# along with this program. If not, see <http://www.gnu.org/licenses/>. 20#------------------------------------------------------------------------------- 21 22use strict; 23use warnings; 24use Cwd 'abs_path'; 25use File::Basename; 26BEGIN { require (abs_path(dirname($0).'/common.pm')); } 27 28# Dependencies 29my $tbzFile=catfile(Var('PKG_DIR'),Var('NAME').'-'.Var('VERSION').'.tar.bz2'); 30if (!-e $tbzFile) { system('perl','pack_tar-bz2.pl')==0 || exit(1); } 31 32# Have an empty temporary directory. 33my $tmpDir=catfile(Var('TMP_DIR'),Var('NAME').'-zip-packing-'.$>); 34if (-e $tmpDir) { RemoveTree($tmpDir); } 35CreateDirPath($tmpDir); 36 37# Unpack source package into the temporary directory. 38my $packageDir=catfile($tmpDir,Var('NAME').'-'.Var('VERSION')); 39print("Unpacking the source package to $packageDir\n"); 40my $oldDir=getcwd(); 41chdir($tmpDir) or die; 42system( 43 'tar', 44 'xfj', 45 $tbzFile 46)==0 || exit 1; 47chdir($oldDir) or die; 48 49# Create zip archive from source tree. 50my $zipFile=catfile(Var('PKG_DIR'),Var('NAME').'-'.Var('VERSION').'.zip'); 51if (-e $zipFile) { RemoveTree($zipFile); } 52print("Creating $zipFile\n"); 53my $oldDir2=getcwd(); 54chdir(dirname($packageDir)) or die; 55system( 56 "zip", 57 "-r9", 58 $zipFile, 59 basename($packageDir) 60)==0 or die("zip failed, stopped"); 61chdir($oldDir2) or die; 62 63# Remove temporary directory. 64RemoveTree($tmpDir); 65