#!/bin/sh

: ${fvwm_libdir=../../libs}

infile=${fvwm_libdir}/Module.h
outfile=`dirname $0`/Constants.pm

( \
	echo "# Autogenerated from the fvwm sources."; \
	echo "#"; \
	echo "# Usage in perl scripts:"; \
	echo "#   use vars qw(@EXPORT);"; \
	echo "#   require FVWM::Constants;"; \
	echo "#"; \
) \
	>$outfile

( \
	grep "#define M_" $infile; \
	grep "#define MX_" $infile | sed 's/ | /|/'; \
	grep "#define MAX_MSG_MASK " $infile; \
	grep "#define MAX_XMSG_MASK " $infile; \
	grep "#define FvwmPacketHeaderSize " $infile | sed 's/FvwmPacketHeaderSize/HEADER_SIZE/'; \
	grep "#define START_FLAG " $infile; \
) \
	| awk '{ print "use constant " $2 " => " $3 ";" }' \
	>>$outfile

( \
	echo "use constant ON_EXIT => '1e20';"; \
	echo "use constant INTSIZE => 4;" \
) \
	>>$outfile

( \
	echo '@EXPORT = qw('; \
	grep -v "^#" $outfile | cut -d" " -f3 | awk '{ print "\t" $1 }'; \
	echo ');' \
) \
	>"$outfile.tmp"
	cat "$outfile.tmp" >>$outfile; rm "$outfile.tmp"

echo '1;' >>$outfile
