#!/bin/sh

set -e

if [ -z "$1" ]; then
    echo "build_gpl_release <version>"
    exit 1
fi

TMP=tmp.build_gpl_release
RELDIR=`pwd`/Release
VER=$1
NOW=`date +%Y-%m-%d`
DIR=hostap-$VER

REMOVE="build_gpl_release todo.lst Prism2-HW.txt"
REMOVE_DIRS="testing www"

if [ -r $TMP ]; then
    echo "Temporary directory '$TMP' exists. Remove it before running this."
    exit 1
fi

mkdir $TMP
cd $TMP

cvs export -D now -d "$DIR" hostap

cd "$DIR"
if [ -n "$REMOVE" ]; then
    rm $REMOVE
fi
if [ -n "$REMOVE_DIRS" ]; then
    rm -r $REMOVE_DIRS
fi

CONF=driver/modules/hostap_config.h
sed "s/\(^#define PRISM2_VERSION \"\)CVS/\1$VER - $NOW/" < $CONF > $CONF.tmp &&
    mv $CONF.tmp $CONF

echo "Version: $VER - $NOW"

DATE=`head -3 ChangeLog | tail -1 | sed "s/ .*//"`

if [ "$DATE" != "$NOW" ]; then
    echo "NOTE! Date mismatch in ChangeLog: $DATE != $NOW"
fi

cd ..
mkdir -p $RELDIR

# Old style tarball with everything (to be removed?)
tar czf $RELDIR/$DIR.tar.gz $DIR

# New style tarballs
mv $DIR/wpa_supplicant wpa_supplicant-$VER
cp $DIR/COPYING wpa_supplicant-$VER
cp $DIR/hostapd/{eloop.[ch],common.[ch],md5.[ch],rc4.[ch]} wpa_supplicant-$VER
cp $DIR/utils/wireless_copy.h wpa_supplicant-$VER
cp $DIR/driver/modules/hostap_common.h wpa_supplicant-$VER
cd wpa_supplicant-$VER
cat Makefile | sed "s%../hostapd/%%g" > Makefile.tmp
mv -f Makefile.tmp Makefile
cd ..
tar czf $RELDIR/wpa_supplicant-$VER.tar.gz wpa_supplicant-$VER

mv $DIR/hostapd hostapd-$VER
cp $DIR/COPYING hostapd-$VER
cp $DIR/driver/modules/hostap_common.h hostapd-$VER
cp $DIR/utils/wireless_copy.h hostapd-$VER
tar czf $RELDIR/hostapd-$VER.tar.gz hostapd-$VER

mv $DIR/utils hostap-utils-$VER
cp $DIR/COPYING hostap-utils-$VER
cp $DIR/driver/modules/hostap_common.h hostap-utils-$VER
tar czf $RELDIR/hostap-utils-$VER.tar.gz hostap-utils-$VER

PDIR=hostap-driver-$VER
mkdir $PDIR
mv $DIR/{README,COPYING,ChangeLog,Makefile,driver,kernel-patches,pcmcia-cs-patches} $PDIR
tar czf $RELDIR/$PDIR.tar.gz $PDIR

cd ..
rm -r $TMP
ls -l $RELDIR/*$VER*


exit 0

Issues:

hostap-utils:

prism2_srec:
	include ../hostapd/common.h
	include ../driver/modules/hostap_wlan.h
