Enctype list configuration enhancements
[krb5.git] / src / windows / build / commandandcontrol.pl
1 #!perl -w
2
3 #use strict;
4
5 sub commandandcontrol {
6     local ($configdefault, $bIgnoreCmdlineConfig)   = @_;
7     local $OPT = {foo => 'bar'};
8
9     Getopt::Long::Configure('no_bundling', 'no_auto_abbrev',
10            'no_getopt_compat', 'require_order',
11            'ignore_case', 'pass_through',
12            'prefix_pattern=(--|-|\+|\/)'
13            );
14     GetOptions($OPT,
15            'help|h|?',
16            'cvstag|c:s',
17            'svntag|s:s',
18            'svnbranch|b:s',
19            'src|r:s',
20            'out|o:s',
21            'debug|d',
22            'nodebug',
23            'config|f=s',
24            'logfile|l:s',
25            'nolog',
26            'repository:s',
27            'username|u:s',
28            'verbose|v',
29            'vverbose',
30            'make!',
31            'clean',
32            'package!',
33            'sign!',
34            );
35
36     if ( $OPT->{help} ) {
37         usage();
38         exit(0);
39         }
40         
41     delete $OPT->{foo};
42
43     local $argvsize = @ARGV;
44     if ($argvsize > 0) {
45         print "Error -- invalid argument:  $ARGV[0]\n";
46         usage();
47         die;
48         }
49     # The first time C&C is called, it is OK to override the default (./bkwconfig.xml)
50     #   with a value from the command line.
51     # The second time C&C is called, the repository has been updated and C&C will be passed
52     #   <src>/pismere/athena/auth/krb5/windows/build/bkwconfig.xml.  That value MUST be used.
53     if ($bIgnoreCmdlineConfig)      {$OPT->{config} = $configdefault;}
54     elsif (! exists $OPT->{config}) {$OPT->{config} = $configdefault;}
55
56     my $configfile      = $OPT->{config};
57     my $bOutputCleaned  = 0;
58
59     print "Info -- Reading configuration from $configfile.\n";
60
61     # Get configuration file:
62     local $xml = new XML::Simple();
63     my $config = $xml->XMLin($configfile);
64     # Set up convenience variables:
65     local $odr  = $config->{Config};    ## Options, directories, repository, environment.
66
67 #while ($v = each %$OPT) {print "$v: $OPT->{$v}\n";}
68
69     # Scan the configuration for switch definitions:
70     while (($sw, $val) = each %$odr) {
71         next if (! exists $val->{def}); ## ?? Should always exist.
72
73         # Set/clear environment variables:
74         if ($val->{env}) {
75             if ($val->{def})    {$ENV{$sw}   = (exists $val->{value}) ? $val->{value} : 1; }
76             else                {delete $ENV{$sw};  }
77             }
78
79         # If the switch is in the command line, override the stored value:
80         if (exists $OPT->{$sw}) {
81             if (exists $val->{value}) {
82                 $val->{value}   = $OPT->{$sw};  
83                 $val->{def}     = 1;
84                 }
85             else {
86                 $val->{def}   = $OPT->{$sw};    ## If no<switch>, value will be zero.
87                 }
88             }
89         # If the switch can be negated, test that, too:
90         if ( ! ($val->{def} =~ /A/)) {
91             local $nosw = "no".$sw;
92             if (exists $OPT->{$nosw}) {
93                 $val->{def} = 0;
94                 }
95             }
96     
97         # For any switch definition with fixed values ("options"), validate:
98         if (exists $val->{options}) {
99             local $bValid   = 0;
100             # options can be like value1|syn1 value2|syn2|syn3
101             foreach $option (split(/ /, $val->{options})) {
102                 local $bFirst   = 1;
103                 local $sFirst;
104                 foreach $opt (split(/\|/, $option)) {
105                     # opt will be like value2, syn2, syn3
106                     if ($bFirst) {
107                         $sFirst = $opt; ## Remember the full name of the option.
108                         $bFirst = 0;
109                         }
110                     if ($val->{value} =~ /$opt/i) {
111                         $val->{value} = $sFirst;    ## Save the full name.
112                         $bValid = 1;
113                         }
114                     }
115                 }
116             if (! $bValid) {
117                 print "Fatal -- invalid $sw value $val->{value}.  Possible values are $val->{options}.\n";
118                 usage();
119                 die;
120                 }
121             }
122         }
123
124     # Don't allow /svntag and /svnbranch simultaneously:
125     if ( (length $odr->{svntag}->{value} > 0)   && 
126          (length $odr->{svnbranch}->{value} > 0) ) {
127         die "Fatal -- Can't specify both /SVNTAG and /SVNBRANCH.";
128         }
129
130     return $config;
131     }
132     
133
134 sub usage {
135     print <<USAGE;
136 Usage: $0 [options] NMAKE-options
137
138   Options are case insensitive.
139
140   Options:
141     /help /?           usage information (what you now see).
142     /config /f path    Path to config file.  Default is bkwconfig.xml.
143     /srcdir /r dir     Source directory to use.  Should contain 
144                        pismere/athena.  If cvstag or svntag is null, 
145                        the directory should be prepopulated.
146     /outdir /o dir     Directory to be created where build results will go
147     /repository checkout | co \\  What repository action to take.
148                 update   | up  ) Options are to checkout, update or 
149                 skip          /  take no action [skip].
150     /username /u name  username used to access svn if checking out.
151     /cvstag /c tag     use -r <tag> in cvs command
152     /svnbranch /b tag  use /branches/<tag> instead of /trunk.
153     /svntag /s tag     use /tags/<tag> instead of /trunk.
154     /debug /d          Do debug make instead of release make.
155     /[no]make          Control the make step.
156     /clean             Build clean target.
157     /[no]package       Control the packaging step.
158     /[no]sign          Control signing of executable files.
159     /verbose /v        Debug mode - verbose output.
160     /logfile /l path   Where to write output.  Default is bkw.pl.log.
161     /nolog             Don't save output.
162   Other:
163     NMAKE-options      any options you want to pass to NMAKE, which can be:
164                        (note: /nologo is always used)
165
166 USAGE
167     system("$MAKE /?");
168     }
169
170 return 1;