#/bin/bash

dest=..

if ! [ -e $dest/src/Makefile ] ; then echo Makefile not found ; exit 1; fi

echo Generating Visual Studio Project files in $dest

function doit {
  echo Generating $dest/$1.vcxproj

  cat vcxproj.1 > $dest/$1.vcxproj

  # this collects all the files needed
  echo "  <ItemGroup>" >> $dest/$1.vcxproj
  for dir in $dirs ; do
    sources="`(cd $dest/src/$dir; make sources)`"
    for s in $sources ; do
      echo "    <ClCompile Include=\"src\\${dir}\\${s}\"/>" >> $dest/$1.vcxproj
    done
  done
  echo "    <ClCompile Include=\"minisat-2.2.1\\minisat\\core\\Solver.cc\"/>" >> $dest/$1.vcxproj
  echo "    <ClCompile Include=\"minisat-2.2.1\\minisat\\simp\\SimpSolver.cc\"/>" >> $dest/$1.vcxproj
  echo "  </ItemGroup>" >> $dest/$1.vcxproj

  cat vcxproj.2 >> $dest/$1.vcxproj

  echo Generating $dest/$1.vcxproj.filters

  # this produces nice "filters" (folders)

  echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>" > $dest/$1.vcxproj.filters
  echo "<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">" >> $dest/$1.vcxproj.filters

  echo "  <ItemGroup>" >> $dest/$1.vcxproj.filters
  for dir in $dirs ; do
    sources="`(cd $dest/src/$dir; make sources)`"
    for s in $sources ; do
      echo "    <ClCompile Include=\"src\\${dir}\\${s}\"><Filter>${dir}</Filter></ClCompile>" >> $dest/$1.vcxproj.filters
    done
  done
  echo "    <ClCompile Include=\"minisat-2.2.1\\minisat\\core\\Solver.cc\"><Filter>minisat2</Filter></ClCompile>" >> $dest/$1.vcxproj.filters
  echo "    <ClCompile Include=\"minisat-2.2.1\\minisat\\simp\\SimpSolver.cc\"><Filter>minisat2</Filter></ClCompile>" >> $dest/$1.vcxproj.filters
  echo "  </ItemGroup>" >> $dest/$1.vcxproj.filters

  for dir in $dirs minisat2 ; do
    echo "  <ItemGroup><Filter Include=\"${dir}\"/></ItemGroup>" >> $dest/$1.vcxproj.filters
  done

  echo "</Project>" >> $dest/$1.vcxproj.filters
}

dirs="big-int langapi util ansi-c assembler cpp java_bytecode xmllang solvers goto-symex analyses pointer-analysis goto-programs linking cbmc"
doit cbmc

dirs="big-int langapi util ansi-c assembler cpp java_bytecode xmllang solvers goto-symex analyses pointer-analysis goto-programs linking jsil goto-cc"
doit goto-cc

dirs="big-int langapi util ansi-c assembler cpp java_bytecode xmllang solvers goto-symex analyses pointer-analysis goto-programs linking goto-instrument"
doit goto-instrument
