import os;
import subprocess;
import platform;

# GLFW class
class GLFW :

    @classmethod
    def Exists(cls) : return os.path.isdir("Thirdparty/glfw");

    @classmethod
    def Add(cls) :

        dir = os.getcwd();
        os.chdir("Thirdparty");
        subprocess.call("git clone https://github.com/glfw/glfw glfw");
        os.chdir("glfw");
        subprocess.call("git checkout 3.3-stable");
        os.chdir(dir);

# GLM class
class GLM :

    @classmethod
    def Exists(cls) : return os.path.isdir("Thirdparty/glm");

    @classmethod
    def Add(cls) :

        dir = os.getcwd();
        os.chdir("Thirdparty");
        subprocess.call("git clone https://github.com/g-truc/glm glm");
        os.chdir("glm");
        subprocess.call("git checkout 0.9.8");
        os.chdir(dir);

# ImGui class
class ImGui :

    @classmethod
    def Exists(cls) : return os.path.isdir("Thirdparty/imgui");

    @classmethod
    def Add(cls) :

        dir = os.getcwd();
        os.chdir("Thirdparty");
        subprocess.call("git clone https://github.com/ocornut/imgui imgui");
        os.chdir("imgui");
        subprocess.call("git checkout docking");
        os.chdir(dir);

# Premake class
class Premake5 :

    @classmethod
    def Exists(cls) : return os.path.isdir("Thirdparty/premake5");

    @classmethod
    def Add(cls) : subprocess.call("git clone https://github.com/premake/premake-core Thirdparty/premake5");

    @classmethod
    def Built(cls) : return os.path.isdir("Thirdparty/premake5/bin/release");

    @classmethod
    def Build(cls) : 

        dir = os.getcwd();
        os.chdir("Thirdparty/premake5");

        if(platform.system() == "Windows") : subprocess.call([os.path.abspath("Bootstrap.bat")]);
        if(platform.system() == "Linux") : subprocess.call([os.path.abspath("make -f Bootstrap.mak linux")]);
        if(platform.system() == "Darwin") : subprocess.call([os.path.abspath("make -f Bootstrap.mak osx")]);
        
        os.chdir(dir);

    @classmethod
    def Generate(cls) :

        if(platform.system() == "Windows") : subprocess.call("Thirdparty/premake5/bin/release/premake5 vs2022");
        if(platform.system() == "Linux") : subprocess.call("Thirdparty/premake5/bin/release/premake5 gmake2");
        if(platform.system() == "Darwin") : subprocess.call("Thirdparty/premake5/bin/release/premake5 xcode");


# Global logic
if(GLFW.Exists() is False) : GLFW.Add();
if(GLM.Exists() is False) : GLM.Add();
if(ImGui.Exists() is False) : ImGui.Add();
if(Premake5.Exists() is False) : Premake5.Add();
if(Premake5.Built() is False) : Premake5.Build();
Premake5.Generate();
import os;
import subprocess;
import platform;

# GLFW class
class GLFW :

    @classmethod
    def Exists(cls) : return os.path.isdir("Thirdparty/glfw");

    @classmethod
    def Add(cls) :

        dir = os.getcwd();
        os.chdir("Thirdparty");
        subprocess.call("git clone https://github.com/glfw/glfw glfw");
        os.chdir("glfw");
        subprocess.call("git checkout 3.3-stable");
        os.chdir(dir);

# GLM class
class GLM :

    @classmethod
    def Exists(cls) : return os.path.isdir("Thirdparty/glm");

    @classmethod
    def Add(cls) :

        dir = os.getcwd();
        os.chdir("Thirdparty");
        subprocess.call("git clone https://github.com/g-truc/glm glm");
        os.chdir("glm");
        subprocess.call("git checkout 0.9.8");
        os.chdir(dir);

# ImGui class
class ImGui :

    @classmethod
    def Exists(cls) : return os.path.isdir("Thirdparty/imgui");

    @classmethod
    def Add(cls) :

        dir = os.getcwd();
        os.chdir("Thirdparty");
        subprocess.call("git clone https://github.com/ocornut/imgui imgui");
        os.chdir("imgui");
        subprocess.call("git checkout docking");
        os.chdir(dir);

# Premake class
class Premake5 :

    @classmethod
    def Exists(cls) : return os.path.isdir("Thirdparty/premake5");

    @classmethod
    def Add(cls) : subprocess.call("git clone https://github.com/premake/premake-core Thirdparty/premake5");

    @classmethod
    def Built(cls) : return os.path.isdir("Thirdparty/premake5/bin/release");

    @classmethod
    def Build(cls) : 

        dir = os.getcwd();
        os.chdir("Thirdparty/premake5");

        if(platform.system() == "Windows") : subprocess.call([os.path.abspath("Bootstrap.bat")]);
        if(platform.system() == "Linux") : subprocess.call([os.path.abspath("make -f Bootstrap.mak linux")]);
        if(platform.system() == "Darwin") : subprocess.call([os.path.abspath("make -f Bootstrap.mak osx")]);
        
        os.chdir(dir);

    @classmethod
    def Generate(cls) :

        if(platform.system() == "Windows") : subprocess.call("Thirdparty/premake5/bin/release/premake5 vs2022");
        if(platform.system() == "Linux") : subprocess.call("Thirdparty/premake5/bin/release/premake5 gmake2");
        if(platform.system() == "Darwin") : subprocess.call("Thirdparty/premake5/bin/release/premake5 xcode");


# Global logic
if(GLFW.Exists() is False) : GLFW.Add();
if(GLM.Exists() is False) : GLM.Add();
if(ImGui.Exists() is False) : ImGui.Add();
if(Premake5.Exists() is False) : Premake5.Add();
if(Premake5.Built() is False) : Premake5.Build();
Premake5.Generate();
# GLFW class # GLM class # ImGui class # Premake class # Global logic