#! /bin/csh
#
#	make cosmos installer
#
# 
#	Copyright (C) 2003 Hirohisa MORI joshua@nichibun.ac.jp
# 
#	This program is free software; you can redistribute it and/or
#	modify it under the terms of the GLOBALBASE General Public 
#	License as published by http://www.globalbase.org/
# 
#	This program 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.
#
#	Usage::
#
#	make.cosmos.installer MACHINE
#
#	for installer of MACHINE
#	MACHINE is corresponding the following dir. names
#
#	solaris
#	linux.redhat
#	linux.debian
#	MacOSX
#	FreeBSD
#	....
#
#	and the result execution file is MACHINE/cosmos.t
#

echo
echo First Try
echo

mkdir $1/work
mkdir $1/work/arch
mkdir $1/work/arch/unix
mkdir $1/work/arch/unix/installer

gcc -c -Wreturn-type -o $1/work/arch/unix/installer/main.o ../../src/arch/unix/installer/main.c
gcc -c -Wreturn-type -o $1/work/arch/unix/installer/grue.o ../../src/arch/unix/installer/grue.c
gcc -c -Wreturn-type -o $1/work/arch/unix/installer/offset.o ../../src/arch/unix/installer/offset.c
gcc -o $1/cosmos.t $1/work/arch/unix/installer/main.o $1/work/arch/unix/installer/grue.o $1/work/arch/unix/installer/offset.o

echo installer FILESIZE
ls -l $1/cosmos.t

echo
echo tar and gzip
echo

cp -r ../../peripheral $1
pushd $1

rm peripheral/*~
rm -r peripheral/CVS
tar cvf tmp.tar bin/cosmos peripheral
gzip -c tmp.tar > tmp.tar.gz

popd

echo
echo Second Try
echo

echo -n 'int offset = ' > $1/offset.c
ls -l $1/cosmos.t | awk '{print $5}' >> $1/offset.c
echo ';' >> $1/offset.c

gcc -c -Wreturn-type -o $1/offset.o $1/offset.c

gcc -o $1/cosmos.t $1/work/arch/unix/installer/main.o $1/work/arch/unix/installer/grue.o $1/offset.o

echo installer FILESIZE before linking
ls -l $1/cosmos.t

echo
echo Finish
echo

cat $1/tmp.tar.gz >> $1/cosmos.t

rm $1/tmp.tar
rm $1/tmp.tar.gz
rm $1/offset.*
rm -r $1/peripheral




