#!/bin/sh

#	Copyright (C) 2003-2005 Daniel Muller, dan at verliba dot cz
#	Copyright (C) 2006-2021 Verlihub Team, info at verlihub dot net
#
#	Verlihub is free software; You can redistribute it
#	and modify it under the terms of the GNU General
#	Public License as published by the Free Software
#	Foundation, either version 3 of the license, or at
#	your option any later version.
#
#	Verlihub is distributed in the hope that it will be
#	useful, but without any warranty, without even the
#	implied warranty of merchantability or fitness for
#	a particular purpose. See the GNU General Public
#	License for more details.
#
#	Please see http://www.gnu.org/licenses/ for a copy
#	of the GNU General Public License.

src="$1"
dst="$2"

consts=""

gen() {
  flt=$1
  file=$2
  {
    echo "# $flt* constants from $file"
    echo 'use constant {'
    grep $flt "$src"/src/$file |sed 's/=/=>/'|perl -pne 's/\t/\ /g; s@//+@#@g'
    echo '};'
    echo
  } >> "$dst"
  c=$(grep $flt "$src"/src/$file|awk '{ print $1 }'|perl -pne tr/\\n/\ /)
  consts="$consts
   $c"
}

mkdir -p $(dirname "$dst")

cat > "$dst" <<EOF1
package vh;

use 5.008;
use strict;
use warnings;
use Carp;

require Exporter;

our @ISA = qw(Exporter);

our %EXPORT_TAGS = qw();

our @EXPORT = qw();

our \$VERSION = '0.01';

EOF1

gen eSF_ cconndc.h
gen eBF_ cban.h
gen eUC_ cuser.h
gen eUR_ cuser.h

echo "our @EXPORT_OK = qw($consts
);" >> "$dst"

cat >> "$dst" <<EOF2

1;

__END__

=head1 NAME

vh::const - autogenerated Perl module with Verlihub constants

=head1 SYNOPSIS

Don't use this module because vh module imports all constant

  use vh;

  print "eBF_SHARE=".vh::eBF_SHARE."\n";

=cut=
EOF2
