#!/bin/sh
# build-info -- Generate header file containing build details
# $Id: build-info,v 1.5 2000/11/16 21:58:27 jsh Exp $

version="$1"
sawfishdir="$2"
lispdir="$3"
sawfishexecdir="$4"
localedir="$5"

[ -n "$HOSTNAME" ] \
    || HOSTNAME=`hostname` \
    || HOSTNAME=unknown

[ -n "$LOCALDOMAIN" ] \
    || LOCALDOMAIN=`dnsdomainname` \
    || LOCALDOMAIN=`domainname` \
    || LOCALDOMAIN=unknown

sys_name="$HOSTNAME.$LOCALDOMAIN"
user_name="$LOGNAME"

dateopts=""
if [ -n "$SOURCE_DATE_EPOCH" ] ; then
    if date --version|grep -q GNU ; then
        dateopts="-u -d @$SOURCE_DATE_EPOCH"
    else
        dateopts="-u -r $SOURCE_DATE_EPOCH"
    fi
    sys_name=reproducible
    user_name=reproducible
fi
build_date="`date $dateopts +'%a %b %e %Y'`"
build_time="`date $dateopts +'%T %Z'`"

cat >src/build.h <<EOF
/* build.h -- Definitions relating to the current build
   Automatically generated by build-info; DO NOT EDIT! */

#ifndef BUILD_H
#define BUILD_H

#define SAWFISH_VERSION "$version"
#define SAWFISH_DIR "$sawfishdir"
#define SAWFISH_LISPDIR "$lispdir"
#define SAWFISH_EXECDIR "$sawfishexecdir"
#define SAWFISH_LOCALEDIR "$localedir"

#define BUILD_HOST "$sys_name"
#define BUILD_USER "$user_name"

#define BUILD_DATE "$build_date"
#define BUILD_TIME "$build_time"

#endif /* BUILD_H */
EOF
