$ENV{'PATH'} = $ENV{'PATH'}.':/usr/lib64/qt4/bin/:/opt/casa/02/bin/';
$scriptdir=dirname(abs_path($0));
print("Script location: $scriptdir\n");
print("Branch: $branch\n");
print("Installing casatools\n");
system "pip3 install casatools";
print("Cloning CASAplotms\n");
system"git clone -q --recursive https://open-bitbucket.nrao.edu/scm/casa/CASAplotms.git";
print("Checking out branch $branch");
system("cd CASAplotms && git checkout $branch && git submodule update");
print("Getting the latest tag\n");
$version=`python $scriptdir/tagger/lasttag.py -s $scriptdir/CASAplotms -b $branch --revisiononly`;
print("Version: $version\n");
print("Checking for casatools\n");
$hasCasatools = `python3 -m casatools --grpc-protopy`;
print("Casatools status: $hasCasatools\n");
print("Executing adjust script\n");
system("cd CASAplotms && scripts/adjust");
print("Running qmake\n");
system("cd CASAplotms && qmake");
system("cd CASAplotms && make -j 2");
print("Creating wheel\n");
system("cd CASAplotms && make py BUILD=$version");
print("Copying wheel to /wheeldirectory");
system("cp `find . -name *.whl` /wheeldirectory/");