to_debian.pl (3731B)
1 #!/usr/bin/perl 2 3 use warnings; 4 use strict; 5 6 # standard imports 7 use Getopt::Long qw/:config auto_help/; 8 use File::Spec qw/ catfile /; 9 use Cwd qw/ getcwd abs_path /; 10 11 # external imports 12 use Config::Simple; 13 14 my $deb_standards_version = '3.9.5'; 15 my $deb_priority = 'optional'; 16 my $deb_arch = 'any'; 17 my $deb_section = 'development'; 18 19 my $ini_dir = File::Spec->catfile(getcwd, '.bluto'); 20 my $out_dir = File::Spec->catfile(getcwd, 'debian'); 21 GetOptions( 22 'd:s', \$ini_dir, 23 'o:s', \$out_dir, 24 'standards-version:s' => \$deb_standards_version, 25 'priority:s' => \$deb_priority, 26 'arch:s' => \$deb_arch, 27 'section=s' => \$deb_section, 28 ); 29 $ini_dir = abs_path($ini_dir); 30 31 print STDERR "using ini dir " . $ini_dir . "\n"; 32 33 my $fn = File::Spec->catfile($ini_dir, 'bluto.ini'); 34 Config::Simple->import_from($fn, \my %config); 35 36 $fn = File::Spec->catfile($ini_dir, 'bluto.deb.ini'); 37 Config::Simple->import_from($fn, \my %config_deb); 38 39 40 our $deb_first_author; 41 our $deb_first_url; 42 our $deb_first_license; 43 for my $k (keys %config) { 44 my @p = split(/:/, $k); 45 print STDERR "processing key " . $k . " " . $p[0] . "\n"; 46 if ($p[0] eq 'author' && ! defined $deb_first_author) { 47 my @n = split(/\./, $p[1]); 48 my $name = $config{'author:' . $n[0] . '.name'}; 49 $deb_first_author = $name; 50 my $email = $config{'author:' . $n[0] . '.email'}; 51 if (defined $email) { 52 $deb_first_author .= ' <' . $email . '>'; 53 } 54 } elsif ($p[0] eq 'locate' && ! defined $deb_first_url) { 55 $deb_first_url = $config{$k}; 56 } 57 58 @p = split(/\./, $p[0], 2); 59 if ($p[0] eq 'license' && ! defined $deb_first_license) { 60 $deb_first_license = $p[1] . '-' . $config{$k}; 61 } 62 } 63 64 my %deb_depends = ( 65 'exec' => [], 66 'build' => [], 67 'install' => [], 68 ); 69 for my $k (keys %config_deb) { 70 my @p = split(/\./, $k, 2); 71 if (substr($p[0], 0, 7) eq 'dep:deb') { 72 my @m = split(/-/, $p[0]); 73 my $dep = $p[1]; 74 if ($config_deb{$k} ne '0') { 75 $dep .= ' (' . $config_deb{$k}. ')'; 76 } 77 push(@{$deb_depends{$m[1]}}, $dep); 78 } 79 } 80 81 my $fh; 82 $fn = File::Spec->catfile($out_dir, 'control'); 83 open($fh, '>', $fn); 84 85 print $fh "Source: " . $config{'main.name'} . "\n"; 86 print $fh "Section: " . $deb_section . "\n"; 87 print $fh "Priority: " . $deb_priority . "\n"; 88 print $fh "Maintainer: " . $deb_first_author . "\n"; 89 print $fh "Standards-Version: " . $deb_standards_version . "\n"; 90 print $fh "Package: " . $config{'main.name'} . "\n"; 91 print $fh "Architecture: " . $deb_arch . "\n"; 92 my $v = join(', ', @{$deb_depends{'build'}}); 93 if ($v ne '') { 94 print $fh "Build-Depends: " . $v . "\n"; 95 } 96 print $fh "\n"; 97 98 $v = join(', ', @{$deb_depends{'install'}}); 99 if ($v ne '') { 100 print $fh "Pre-Depends: " . $v. "\n"; 101 } 102 $v = join(', ', @{$deb_depends{'exec'}}); 103 if ($v ne '') { 104 print $fh "Depends: " . $v. "\n"; 105 } 106 print $fh "Description: " . $config{'main.summary'} . "\n"; 107 close($fh); 108 109 110 $fn = File::Spec->catfile($out_dir, 'compat'); 111 open($fh, '>', $fn); 112 print $fh $config_deb{'main:deb.engine'}; 113 close($fh); 114 115 $fn = File::Spec->catfile($out_dir, 'copyright'); 116 open($fh, '>', $fn); 117 print $fh "Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/\n"; 118 print $fh "Upstream-Name: " . $config{'main.name'}. "\n"; 119 print $fh "Source: " . $deb_first_url . "\n"; 120 print $fh "\n"; 121 print $fh "Files: *\n"; 122 123 my @time = localtime(); 124 my $year = $time[5] + 1900; 125 print $fh "Copyright: Copyright " . $year . " " . $deb_first_author . "\n"; 126 print $fh "License: " . $deb_first_license . "\n"; 127 close($fh); 128 129 $fn = File::Spec->catfile($out_dir, 'changelog'); 130 if (! -f $fn) { 131 open($fh, '>', $fn); 132 print $fh $config{'main.name'} . " (" . $config{'main.version'} . ") UNRELEASED; urgency: low\n\n"; 133 print $fh " * Automatic commit message from bluto\n\n"; 134 print $fh " -- " . $first_author . " " . 135 close($fh);