#!/usr/bin/env perl eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if 0; # not running under some shell ## # $Author: somian $ Last modified: 05 Feb 2004 18:15:52 # $Source: /usr/src/repositories/cvs/perl-proj/devtools/mk-ac-pkgopts,v $ # $Date: 2004/02/05 22:22:55 $ ## use strict; use warnings; use vars ('$VERSION'); my $script_revision = q$Revision: 1.5 $ ; use Safe; use Tie::IxHash; use Data::Dumper; use Pod::Usage; $VERSION = 0.05 ; # above must be *all one line* for MakeMaker.pm use vars qw(@Config_Entries $Descfile $cACen $PkgName $Wet_already); my $mode; my $BeDugg = 0x0; # make true if want to debug # Simplified optionflag handling. my( $argC,$argN ) = ( 0x0+@ARGV , $ARGV[$#ARGV] ); if ( $argC and grep { $_ eq lc($argN) or $_ eq substr lc($argN)=>1 } qw/ -h -u -man -help -usage / ) { pod2usage(-verbose => 2) } elsif ( $argN && $argN =~m'-version' ) { print "$VERSION\n" and exit 0 } elsif ( not $argC==0 || $argC==2 and $argN && $argN ne '-demo' ) { pod2usage(1) } sub just_add_water # implements our "demo-template" mode. { my @Demo; my $clo_Data = sub { my @array; @array = @Demo; }; if ( ref($Wet_already) && wantarray ) { return @{ [&$Wet_already] } } else { my $dfh = *DEMO::DATA::AConfHelper::DATA; local $/ = undef; @Demo = ( eval <$dfh> ); $Wet_already = $clo_Data; my %Demo = @Demo; return \%Demo; } } if (@ARGV) { unless ($ARGV[0] =~ m%^\w*[[:upper:]]\w+$%) { die "First arg must be a string containing PKGNAME!"; } else { $PkgName = shift; die "Not enough args!" if not @ARGV; $Descfile = shift; if (! -f $Descfile) { die "File not found!" } else { my $jail = Safe->new("ACoptCO"); $jail->permit_only( qw/ aassign anonhash anonlist const return enter gv leave nextstate pushmark rv2av srefgen / ); if ( $jail->rdo($Descfile) ) { print STDERR 'size of array: ' . @ACoptCO::Config_Entries if $BeDugg; @Config_Entries = @ACoptCO::Config_Entries; unless (not @Config_Entries & 1) { warn 'Input cannot be right, odd number of elements ' .'in @Config_Entries:' . scalar(@Config_Entries) ."!"; my $ddo = Data::Dumper->new([@Config_Entries]); print STDERR $ddo->Dump; die "terminating"; } $cACen = Tie::IxHash->new; for ( my $i=0; $i<=$#Config_Entries; $i++ ) { $cACen->Push(@Config_Entries[$i , 1+$i]); $i++; } } else { if ($@) { print STDERR "Compilation error in desc-file:\n", $@; } die "Description file did not open, parse or compile\n", "Please check path and data and try again."; } } } } else ### demo / skeleton-template gen mode. ### { $cACen = just_add_water; $PkgName = 'FAUX_DEMO_TEMPLATE'; # output an example of what an input file might look like, to stdout: $Data::Dumper::Purity = 1; print STDERR Data::Dumper->Dump([ $cACen ]=>[ 'Config_Entries' ]); # then send it through after tie'ing it to preserve ordering: $cACen = Tie::IxHash->new( @{ [just_add_water()] } ); } if ($BeDugg) { my $ddo = Data::Dumper->new([@Config_Entries]); print STDERR $ddo->Dump; } for my $ent ($cACen->Keys) { my $ent_v = $cACen->FETCH($ent); my $optstem = $ent; $optstem =~ s% - %_%gx ; my $optdecl = q[$]. $PkgName .q[_feat_]. $optstem; my $enORdis = $ent_v->{defstat} || 'enable'; my $opthelp = $ent_v->{helpSTR}; my $optverb = $ent_v->{msg_PTS}->[0] || 'create'; my $optsubj = $ent_v->{msg_PTS}->[1] || $ent; my $defaultstatus = $enORdis .'d'; my $optinvert = q[--]. ($enORdis eq 'enable' ? 'disable':'enable'); my $acsubst_shlvar = q[$]. $PkgName .q[_]. $optstem; my $optfeatvar_internal = substr($optdecl,1); my $acsubst_macvar = $ent_v->{ac_SUBT}->[0]; my $acsubst_usrval = $ent_v->{ac_SUBT}->[1]; my $acsubst_defval = q[]; my $optdeclinit_L = $optfeatvar_internal .q[=]. ($enORdis eq 'enable' ? 'ENABLE_Y' : 'ENABLE_N' ); my $acsubstitute_assignment_L = sub { no strict 'refs'; return q[] if ! $acsubst_macvar; $mode = shift(); my $context_val = $mode ? $acsubst_usrval : $acsubst_defval ; return substr($acsubst_shlvar,1) .qq/="/. $context_val .qq/"\n/; } ; #" my $acsubstitute_L = $acsubst_macvar ? qq/\nAC_SUBST(/. $acsubst_macvar .qq/, [$acsubst_shlvar])\n/ : q[]; my $acdefine_L = $ent_v->{ac_DEFI}->[0] ? qq/\n AC_DEFINE(/. $ent_v->{ac_DEFI}->[0] .q/, / . $ent_v->{ac_DEFI}->[1] .q/, [/. $ent_v->{ac_DEFI}->[2] .qq/])\n/ : q[]; # Lets rock and roll! print <<"MACRO!!BLOCK!!"; # Starting With User-Build-Option "$ent": make an init declaration to set default dnl $optdeclinit_L dnl AC_MSG_CHECKING([whether to $optverb $optsubj]) AC_ARG_ENABLE($ent, [AC_HELP_STRING([$optinvert-$ent], [$optverb $optsubj (default=$defaultstatus)])], [if test "unset\$enable_$optstem" != unset then enableval="\$enable_$optstem" case \$enableval in n|N|no|NO|disable ) \\ ${PkgName}_pkgopt_$optstem="disable caught (\$enableval) ENABLE_N" ;; * ) ${PkgName}_pkgopt_$optstem="enable caught (\$enableval) ENABLE_Y" ;; esac else if test \${enableval+setwithnoval} == setwithnoval then ${PkgName}_pkgopt_$optstem="enable caught (\$enableval) ENABLE_Y" fi fi], [if test "\${disable_${optstem}+defined}" == defined then ${PkgName}_pkgopt_$optstem="disable caught ENABLE_N" else ${PkgName}_pkgopt_$optstem="$optdecl" fi]) # Results post-processing for "$ent" case \$${PkgName}_pkgopt_$optstem in *ENABLE_Y ) AC_MSG_RESULT(will $optverb ${optsubj}.)$acdefine_L @{ [&$acsubstitute_assignment_L(0x1)] } ## OTHER ASSIGNMENTS, SHELL EXPRESSIONS GO HERE!! ## ;; *ENABLE_N ) AC_MSG_RESULT(will NOT $optverb ${optsubj}.) @{ [&$acsubstitute_assignment_L(0x0)] } ## OTHER ASSIGNMENTS, SHELL EXPRESSIONS GO HERE!! ## ;; * ) AC_MSG_ERROR([fatal -- bad value for internal configure variable \\\$${PkgName}_pkgopt_$optstem "\$${PkgName}_pkgopt_$optstem" -- cannot continue. Pls notify package maintainer.], 1) ;; esac$acsubstitute_L # Done With User-Build-Option "$ent". # --------------------------------------------------------------------------- MACRO!!BLOCK!! } package DEMO::DATA::AConfHelper; __DATA__ @Config_Entries = ( 'DEMO-OPT-1' =>{ defstat => q[enable], ac_SUBT => [qw/DEMO_OPT1 demoopt.cpp/], ac_DEFI => [], msg_PTS => [qw/build demo-opt/], helpSTR => q[build a demo-opt component], }, 'DEMO-OPT-2' =>{ defstat => q[disable], ac_SUBT => [], ac_DEFI => [q/DEMO_OPT2/, 1, q/include DEMO_OPT2 code/], msg_PTS => [qw/configure another-demo-opt/], helpSTR => q[build the another-demo-opt variation], }, );