| 1 | #! /usr/bin/env perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: create pkg-config metadata files | ||||||||||||||||||||||||||||
| 4 | # PODNAME: mkpkgconfig | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use v5.14; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Getopt::Long::Descriptive; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use File::Spec::Functions; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | our $VERSION = 'v2.0.2'; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use constant { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ALL_VARS => 1, | |||||||||||||||||||||||||||
| 19 | REQUESTED_VARS => 2, | ||||||||||||||||||||||||||||
| 20 | NEEDED_VARS => 3, | ||||||||||||||||||||||||||||
| 21 | 1 | }; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | our %VarsAuto = ( ## no critic (PackageVars) | |||||||||||||||||||||||||||
| 24 | exec_prefix => '${prefix}', | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | bindir => '${exec_prefix}/bin', | ||||||||||||||||||||||||||||
| 27 | sbindir => '${exec_prefix}/sbin', | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | libdir => '${exec_prefix}/lib', | ||||||||||||||||||||||||||||
| 30 | pkg_libdir => '${libdir}/${package}', | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | libexecdir => '${exec_prefix}/libexec', | ||||||||||||||||||||||||||||
| 33 | pkg_libexecdir => '${libexecdir}/${package}', | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | datarootdir => '${prefix}/share', | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | datadir => '${datarootdir}', | ||||||||||||||||||||||||||||
| 38 | pkg_datadir => '${datadir}/${package}', | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sysconfdir => '${prefix}/etc', | ||||||||||||||||||||||||||||
| 41 | pkg_sysconfdir => '${sysconfdir}/${package}', | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | localstatedir => '${prefix}/var', | ||||||||||||||||||||||||||||
| 44 | pkg_localstatedir => '${localstatedir}/${package}', | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | includedir => '${prefix}/include', | ||||||||||||||||||||||||||||
| 47 | pkg_includedir => '${includedir}/${package}', | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | docdir => '${datarootdir}/doc/${package}', | ||||||||||||||||||||||||||||
| 50 | infodir => '${datarootdir}/info', | ||||||||||||||||||||||||||||
| 51 | mandir => '${datarootdir}/man', | ||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | my %KeywordOptions = ( | |||||||||||||||||||||||||||
| 55 | Name => { required => 1 }, | ||||||||||||||||||||||||||||
| 56 | Description => { required => 1 }, | ||||||||||||||||||||||||||||
| 57 | Requires => { required => 0 }, | ||||||||||||||||||||||||||||
| 58 | Libs => { required => 0 }, | ||||||||||||||||||||||||||||
| 59 | Conflicts => { required => 0 }, | ||||||||||||||||||||||||||||
| 60 | Cflags => { required => 0 }, | ||||||||||||||||||||||||||||
| 61 | URL => { required => 0 }, | ||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 1 | ▶ | main( @ARGV ) unless caller; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 6 | ▶ | sub main { | ||||||||||||||||||||||||||
|
Subroutine
main: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 6 | local @ARGV = @_; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # save original options for output; | ||||||||||||||||||||||||||||
| 71 | 6 | my @sARGV = @ARGV; | |||||||||||||||||||||||||||
| 72 | 6 | my $opt = parse_opts(); | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 6 | require App::mkpkgconfig::PkgConfig; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 6 | my $conf = App::mkpkgconfig::PkgConfig->new; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # add standard variables | ||||||||||||||||||||||||||||
| 79 | 6 | ▶ | $conf->add_variable( prefix => $opt->prefix ) if defined $opt->prefix; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 6 | ▶ | $conf->add_variable( package => $opt->package ) if defined $opt->package; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 6 | $conf->add_variable( version => $opt->modversion ); | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # add auto generated variables | ||||||||||||||||||||||||||||
| 84 | 6 | ▶ | $conf->add_variables( \%VarsAuto ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | if defined $opt->auto; | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | # override from user | ||||||||||||||||||||||||||||
| 88 | 6 | $conf->add_variables( $opt->var ); | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # add standard keywords | ||||||||||||||||||||||||||||
| 91 | 6 | $conf->add_keyword( Name => $opt->name ); | |||||||||||||||||||||||||||
| 92 | 6 | $conf->add_keyword( Description => $opt->description ); | |||||||||||||||||||||||||||
| 93 | 6 | $conf->add_keyword( Version => '${version}' ); | |||||||||||||||||||||||||||
| 94 | 6 | for my $kwd ( qw( Requires Libs Conflicts Cflags ) ) { | |||||||||||||||||||||||||||
| 95 | 24 | my $mth = lc $kwd; | |||||||||||||||||||||||||||
| 96 | 24 | ▶ | $conf->add_keyword( $kwd => $opt->$mth ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | if defined $opt->$mth; | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # override from user | ||||||||||||||||||||||||||||
| 101 | 6 | $conf->add_keywords( $opt->kwd ); | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | #<<< no tidy | ||||||||||||||||||||||||||||
| 104 | my @vars_needed = | ||||||||||||||||||||||||||||
| 105 | # output all variables, used or not | ||||||||||||||||||||||||||||
| 106 | $opt->usevars == ALL_VARS ? $conf->variables | ||||||||||||||||||||||||||||
| 107 | # output only requested + keyword dependencies | ||||||||||||||||||||||||||||
| 108 | 6 | ▶ | : $opt->usevars == REQUESTED_VARS ? ( keys %{ $opt->var } , @{ $opt->auto // [] } ) | ||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%2/2
$opt->auto // []
MC/DC100%1/1
$opt->auto // []
$opt->auto
Truth table100%2/2
A
A= $opt->auto
| |||||||||||||||||||||||||||||
| 109 | # only variables actually used by keywords | ||||||||||||||||||||||||||||
| 110 | : $opt->usevars == NEEDED_VARS ? () | ||||||||||||||||||||||||||||
| 111 | : die( 'unknown filter for variables: ', $opt->usevars, "\n" ); | ||||||||||||||||||||||||||||
| 112 | #>>> | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 6 | ▶ | $conf->write( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | $opt->output, | ||||||||||||||||||||||||||||
| 116 | write => ( $opt->usevars == ALL_VARS ? 'all' : 'req' ), | ||||||||||||||||||||||||||||
| 117 | vars => \@vars_needed, | ||||||||||||||||||||||||||||
| 118 | comments => [ "This file was created by $0 ($VERSION) via", join( q{ }, $0, @sARGV ) ] ); | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 6 | ▶ | sub parse_opts { | ||||||||||||||||||||||||||
|
Subroutine
parse_opts: called CC=9 SCAR=27.0
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 6 | my %Map_usevars = ( | |||||||||||||||||||||||||||
| 125 | 'all' => ALL_VARS, | ||||||||||||||||||||||||||||
| 126 | 'requested' => REQUESTED_VARS, | ||||||||||||||||||||||||||||
| 127 | 'req' => REQUESTED_VARS, | ||||||||||||||||||||||||||||
| 128 | 'needed' => NEEDED_VARS, | ||||||||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | my ( $opt, $usage ) = Getopt::Long::Descriptive::describe_options( | ||||||||||||||||||||||||||||
| 132 | '%o <options>', | ||||||||||||||||||||||||||||
| 133 | [ 'output|o=s', 'output [stdout]' ], | ||||||||||||||||||||||||||||
| 134 | [ | ||||||||||||||||||||||||||||
| 135 | 'usevars|u:s', | ||||||||||||||||||||||||||||
| 136 | 'which variables to output', | ||||||||||||||||||||||||||||
| 137 | { | ||||||||||||||||||||||||||||
| 138 | default => { reverse %Map_usevars }->{ +NEEDED_VARS }, | ||||||||||||||||||||||||||||
| 139 | callbacks => { | ||||||||||||||||||||||||||||
| 140 | 5 | ▶ | 'valid output variables' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||
| 141 | 5 | ▶ | return 1 if defined $Map_usevars{ $_[0] }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 0 | die( "$_[0] isn't one of 'all', 'req', 'requested', or 'used'\n" ); | |||||||||||||||||||||||||||
| 143 | }, | ||||||||||||||||||||||||||||
| 144 | }, | ||||||||||||||||||||||||||||
| 145 | }, | ||||||||||||||||||||||||||||
| 146 | ], | ||||||||||||||||||||||||||||
| 147 | [ 'auto:s@', 'generate a default set of variables' ], | ||||||||||||||||||||||||||||
| 148 | [ | ||||||||||||||||||||||||||||
| 149 | 'list-auto', | ||||||||||||||||||||||||||||
| 150 | 'output a list of variables generated by the --auto option', | ||||||||||||||||||||||||||||
| 151 | { shortcircuit => 1 }, | ||||||||||||||||||||||||||||
| 152 | ], | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | [], | ||||||||||||||||||||||||||||
| 155 | ['Variables:'], | ||||||||||||||||||||||||||||
| 156 | [ 'var|variable=s%', 'define variables', { default => {} } ], | ||||||||||||||||||||||||||||
| 157 | [ 'prefix=s', q{'prefix' variable}, ], | ||||||||||||||||||||||||||||
| 158 | [ 'package=s', q{'package' variable}, ], | ||||||||||||||||||||||||||||
| 159 | [ 'modversion=s', '"version" variable and Version keyword)', { required => 1 } ], | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | [], | ||||||||||||||||||||||||||||
| 162 | ['Keywords:'], | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | [ 'kwd|keyword=s%', 'define keywords', { default => {} } ], | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | ( | ||||||||||||||||||||||||||||
| 167 | map { | ||||||||||||||||||||||||||||
| 168 | 6 | [ | |||||||||||||||||||||||||||
| 169 | qq(\u$_|\l$_=s), | ||||||||||||||||||||||||||||
| 170 | qq("\u$_" keyword), | ||||||||||||||||||||||||||||
| 171 | 42 | ▶ | { ( $KeywordOptions{$_}{required} // 0 ? ( required => 1 ) : () ), }, | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$KeywordOptions{$_}{"required"} // 0
MC/DC0%0/1
$KeywordOptions{$_}{"required"} // 0
$KeywordOptions{$_}{"required"}
Truth table50%1/2
A
A= $KeywordOptions{$_}{"required"}
| |||||||||||||||||||||||||||||
| 172 | ] | ||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | keys %KeywordOptions | ||||||||||||||||||||||||||||
| 175 | ), | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | [], | ||||||||||||||||||||||||||||
| 178 | ['Miscellaneous::'], | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | [ 'version|v', 'output version and exit', { shortcircuit => 1 } ], | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | [ 'help|h', 'output short help message and exit', { shortcircuit => 1 } ], | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | [ 'manual|m', 'output full manual page and exit', { shortcircuit => 1 } ], | ||||||||||||||||||||||||||||
| 185 | ); | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 6 | ▶ | if ( $opt->help ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 0 | print( $usage->text ); | |||||||||||||||||||||||||||
| 189 | 0 | exit; | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | 6 | ▶ | if ( $opt->version ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | 0 | print( $VERSION, "\n" ); | |||||||||||||||||||||||||||
| 193 | 0 | exit; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | 6 | ▶ | if ( $opt->manual ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 0 | require Pod::Usage; | |||||||||||||||||||||||||||
| 197 | 0 | Pod::Usage::pod2usage( { -exitval => 0, -verbose => 2, -output => \*STDOUT } ); | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 6 | ▶ | if ( $opt->list_auto ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | 0 | require List::Util; | |||||||||||||||||||||||||||
| 202 | 0 | my $length = List::Util::max( map { length } keys %VarsAuto ); | |||||||||||||||||||||||||||
| 203 | printf( "%-*s = %s\n", $length, $_, $VarsAuto{$_} ) | ||||||||||||||||||||||||||||
| 204 | 0 | for sort keys %VarsAuto; | |||||||||||||||||||||||||||
| 205 | 0 | exit; | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 6 | ▶ | if ( defined $opt->auto ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | 3 | my @auto = map { split /,/ } @{ $opt->auto }; | |||||||||||||||||||||||||||
| 210 | 3 | $opt->{auto} = \@auto; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 6 | $opt->{usevars} = $Map_usevars{ $opt->usevars }; | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 6 | return $opt; | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 1 | 1; | |||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | # | ||||||||||||||||||||||||||||
| 221 | # This file is part of App-mkpkgconfig | ||||||||||||||||||||||||||||
| 222 | # | ||||||||||||||||||||||||||||
| 223 | # This software is Copyright (c) 2020 by Smithsonian Astrophysical Observatory. | ||||||||||||||||||||||||||||
| 224 | # | ||||||||||||||||||||||||||||
| 225 | # This is free software, licensed under: | ||||||||||||||||||||||||||||
| 226 | # | ||||||||||||||||||||||||||||
| 227 | # The GNU General Public License, Version 3, June 2007 | ||||||||||||||||||||||||||||
| 228 | # | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | __END__ | ||||||||||||||||||||||||||||