#! /bin/bash
#
# make-dist -- Copyright (c) 2001-2003 Eberhard Mattes
#
# This file is part of epocemx.
#
# epocemx is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# epocemx 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.
#
# You should have received a copy of the GNU General Public License
# along with epocemx; see the file COPYING.  If not, write to the
# the Free Software Foundation, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#

die()
{
  echo "$@"
  exit 2
}

usage()
{
  echo "Usage: make-dist SUFFIX"
  exit 1
}

test $# = 1 || usage

case $1 in
  epocemx*) usage;;
esac

name=epocemx-$1

test -e $name && die "$name: already exists"
test -e make-dist.tar && die "make-dist.tar: already exists"
test -d dist || die "dist: does not exist"
test -e dist/$name.tar.gz && die "dist/$name.tar.gz: already exists"

tar -c -f make-dist.tar --exclude "*~" \
 COPYING COPYING.EMX README INSTALL CHANGES \
 build cfg-sdk cfg-src \
 maint/{diff-sdk,make-dist,make-patch} \
 maint/exclude-{bu,bzip2,diff,find,gawk,gcc,grep,gzip,less} \
 maint/exclude-{recode,sed,su,tar,tu,unzip,zip} \
 tools/{Makefile,Makefile.epoc,*.h,*.c,*.cc,dir,vdir,emxtools.def,emxdev.def} \
 tools/{emxinstall,disasm.inp,disasm.exp,emxrsc.hrh,emxrsc.rss,emxshell.pkg} \
 tools/{remangle.explicit,install-epocsdk-libs,install-epocsdk-headers} \
 tools/emx-config-cross \
 tools/{man,zless,WELCOME} \
 console/{Makefile,*.{cc,def,hrh,rss,mbm,pkg}} \
 lib/{EM,EMPTY,Makefile,PANICS} \
 lib/{*.c,*.cc,emx*.def,*.rss,emxdll.s,emxexe.s,emxrun.s} \
 lib/{main.s,setjmp.s,emxdll.pkg,emxlink.mbm,emxdevice.mbm} \
 lib/{dll2svr.list,dll2svr.template,make-dll2svr} \
 lib/{estlib.h,estlib.rename,rename.sed,dllname.sed} \
 lib/fdlibm/{*.c,*.h} \
 lib/include/{,emxdll/,emx/,emx/sys/,sys/}*.h \
 estlib/{README,Makefile,emximp.awk,estlib.cc,helper,missing.cc} \
 host/{bu,gcc}/my* \
 epoc/{bu,diff,find,gawk,gcc,grep,gzip,less,recode,sed,su,tar,tu}/my* \
 boss_eik9/{Makefile,boss.cpp.patch} \
 hello/{Makefile,hello.c} \
 sis/{FSF,Makefile,emxbinutils.pkg,emxbzip2.pkg,emxdev.pkg,emxdiff.pkg} \
 sis/{emxfind.pkg,emxgawk.pkg,emxgcc-base.pkg,emxgcc-c.pkg,emxgcc-c++.pkg} \
 sis/{emxgrep.pkg,emxgzip.pkg,emxless.pkg,emxrecode.pkg,emxsed.pkg} \
 sis/{emxshutils.pkg,emxtar.pkg,emxtextutils.pkg,emxunzip.pkg,emxuser.pkg} \
 sis/emxzip.pkg \
 patches/{binutils-2.11,bzip2-1.0.2,diffutils-2.8,findutils-4.1}.patch \
 patches/{gawk-3.1.0,gcc-20010205,grep-2.4.2,gzip-1.2.4a,less-374}.patch \
 patches/{recode-3.6,sed-3.02,sh-utils-2.0}.patch \
 patches/{tar-1.13,textutils-2.0,unzip-5.50,zip-2.3}.patch \
 patches/{tu-config.h.patch,make-libgccsub} \
 patches/{libiberty,bfd,gzip,grep-src,tu-lib}-Makefile.patch \
  || die "make-dist.tar: tar failed"

mkdir $name || die "$name: mkdir failed"
cd $name || die "$name: cd failed"
tar xf ../make-dist.tar || die "make-dist.tar: tar failed"
mkdir tools/epoc || exit 2
mkdir dist || exit 2
chmod -R u+w .
cd ..
tar cf - $name | gzip -9 >dist/$name.tar.gz || die "$name.tar.gz: tar/gzip failed"
rm -rf $name
rm make-dist.tar
