#! /usr/bin/env perl
# Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the Apache License 2.0 (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
use strict;
use warnings;
use File::Basename;
use File::Spec::Functions qw(abs2rel rel2abs);
use lib ".";
use configdata;
my $config = "crypto/err/openssl.ec";
my $debug = 0;
my $internal = 0;
my $nowrite = 0;
my $rebuild = 0;
my $reindex = 0;
my $static = 0;
my $unref = 0;
my %modules = ();
my $errors = 0;
my @t = localtime();
my $YEAR = $t[5] + 1900;
sub phase
{
my $text = uc(shift);
print STDERR "\n---\n$text\n" if $debug;
}
sub help
{
print STDERR <<"EOF";
mkerr.pl [options] [files...]
Options:
-conf FILE Use the named config file FILE instead of the default.
-debug Verbose output debugging on stderr.
-internal Generate code that is to be built as part of OpenSSL itself.
Also scans internal list of files.
-module M Only useful with -internal!
Only write files for library module M. Whether files are
actually written or not depends on other options, such as
-rebuild.
Note: this option is cumulative. If not given at all, all
internal modules will be considered.
-nowrite Do not write the header/source files, even if changed.
-rebuild Rebuild all header and C source files, even if there
were no changes.
-reindex Ignore previously assigned values (except for R records in
the config file) and renumber everything starting at 100.
-static Make the load/unload functions static.
-unref List all unreferenced function and reason codes on stderr;
implies -nowrite.
-help Show this help text.
... Additional arguments are added to the file list to scan,
if '-internal' was NOT specified on the command line.
EOF
}
while ( @ARGV ) {
my $arg = $ARGV[0];
last unless $arg =~ /-.*/;
$arg = $1 if $arg =~ /-(-.*)/;
if ( $arg eq "-conf" ) {
$config = $ARGV[1];
shift @ARGV;
} elsif ( $arg eq "-debug" ) {
$debug = 1;
$unref = 1;
} elsif ( $arg eq "-internal" ) {
$internal = 1;
} elsif ( $arg eq "-nowrite" ) {
$nowrite = 1;
} elsif ( $arg eq "-rebuild" ) {
$rebuild = 1;
} elsif ( $arg eq "-reindex" ) {
$reindex = 1;
} elsif ( $arg eq "-static" ) {
$static = 1;
} elsif ( $arg eq "-unref" ) {
$unref = 1;
$nowrite = 1;
} elsif ( $arg eq "-module" ) {
shift @ARGV;
$modules{uc $ARGV[0]} = 1;
} elsif ( $arg =~ /-*h(elp)?/ ) {
&help();
exit;
} elsif ( $arg =~ /-.*/ ) {
die "Unknown option $arg; use -h for help.\n";
}
shift @ARGV;
}
my @source;
if ( $internal ) {
die "Cannot mix -internal and -static\n" if $static;
die "Extra parameters given.\n" if @ARGV;
@source = ( glob('crypto/*.c'), glob('crypto/*/*.c'),
glob('ssl/*.c'), glob('ssl/*/*.c'), glob('providers/*.c'),
glob('providers/*/*.c'), glob('providers/*/*/*.c') );
} else {
die "-module isn't useful without -internal\n" if scalar keys %modules > 0;
@source = @ARGV;
}
# Data parsed out of the config and state files.
# We always map function-code values to zero, so items marked below with
# an asterisk could eventually be removed. TODO(4.0)
my %hpubinc; # lib -> public header
my %libpubinc; # public header -> lib
my %hprivinc; # lib -> private header
my %libprivinc; # private header -> lib
my %cskip; # error_file -> lib
my %errorfile; # lib -> error file name
my %fmax; # lib -> max assigned function code*
my %rmax; # lib -> max assigned reason code
my %fassigned; # lib -> colon-separated list of assigned function codes*
my %rassigned; # lib -> colon-separated list of assigned reason codes
my %fnew; # lib -> count of new function codes*
my %rnew; # lib -> count of new reason codes
my %rextra; # "extra" reason code -> lib
my %rcodes; # reason-name -> value
my %ftrans; # old name -> #define-friendly name (all caps)*
my %fcodes; # function-name -> value*
my $statefile; # state file with assigned reason and function codes
my %strings; # define -> text
# Read and parse the config file
open(IN, "$config") || die "Can't open config file $config, $!,";
while ( <IN> ) {
next if /^#/ || /^$/;
if ( /^L\s+(\S+)\s+(\S+)\s+(\S+)(?:\s+(\S+))?\s+$/ ) {
my $lib = $1;
my $pubhdr = $2;
my $err = $3;
my $privhdr = $4 // 'NONE';
$hpubinc