#!/bin/tcsh
## build_all.csh
## Aaron Sloman
## Revised 5 Jan 2020

## Modified version of build_all.sh script provided by Waldek Hebisch
## Extended 23 Dec 2019, by AS
## Run this in the poplog_base directory created from the tar file
##  ../latest_poplog_base.tar.bz2
## Adds two tar commands to Waldek's build_pop.sh script
## For some reason the bash version works only if 'sourced'.
## This tcsh version can be run as ./build_all.csh
## with or without output redirected.

## Make it easy to find the pathname, for $usepop
echo 'Create file whose content is the path name of this directory'
echo `pwd` > USEPOP

echo "directory name stored in file USEPOP"
echo "cat USEPOP"
cat USEPOP
##export usepop=`pwd`
##just in case not yet set
setenv usepop `pwd`

echo ""

echo "run first build"
echo "./build_pop0 >& buildout1"
./build_pop0 >& buildout1

echo ""

echo "mv pop/pop/newpop11 pop/pop/corepop"
echo "type 'y' if permission requested"
echo ""
mv pop/pop/newpop11 pop/pop/corepop

echo ""

echo "run second build, to complete construction of basic new poplog"
echo "./build_pop2 >& buildout2"
./build_pop2 >& buildout2

echo ""

echo "Basic saved images created in pop/lib/psv:"
echo ""
echo "ls -l pop/lib/psv"
ls -l pop/lib/psv

echo ""

cd pop
echo "Basic pop directory"

echo ""
ls -l
echo "Installing doc files"
tar xfj ../../docs.tar.bz2

echo ""

echo "Installing packages directory"
echo "tar xfj ../../packages-V16.tar.bz2"
tar xfj ../../packages-V16.tar.bz2
echo ""
echo "ls -l"
ls -l

echo ""
echo "using .../pop/com/poplog.csh to set up environment variables needed to run poplog"

echo ""
echo 'source $usepop/pop/com/poplog.csh'
source $usepop/pop/com/poplog.csh
echo ""

echo "CREATING DOCUMENTATION INDEXES NEEDED BY USERS"

echo ""

## get rid of any previous output file
rm -f /tmp/makeindexes-out.txt

echo '$usepop/pop/com/makeindexes > /tmp/makeindexes-out.txt'

$usepop/pop/com/makeindexes > /tmp/makeindexes-out.txt

echo "DONE"

echo "Output of makeindexes should be in /tmp/makeindexes-out.txt"

echo 'Try setting up $usepop using poplog_base/USEPOP'
echo ''
echo 'Then if using bash or sh, do'
echo ''
echo 'source $usepop/pop/com/poplog.sh'
echo ''
echo 'If using tcsh or csh, do'
echo ''
echo 'source $usepop/pop/com/poplog.csh'
echo ''
## TRANSFERRED TO getpoplog.sh
## echo 'NB IF YOU INTEND TO USE MOTIF,'
## echo 'MAKE SURE THE LINUX MOTIF LIBRARY HAS BEEN INSTALLED'
## echo 'motif-devel in Fedora,etc, libmotif-dev in Ubuntu and openmotif in Arch'
## echo ''
## echo ''
## echo 'To link poplog with motif first make sure that $usepop is set to'
## cat USEPOP
## echo ''
## echo 'Then do'
## echo ''
## echo '$usepop/pop/src/newpop -link -x=-xm -norsv'
## echo ''
