#!/usr/bin/python

import os

BUILD_DIR = "build"
PLUGINS_DIR_2 = os.path.expanduser("~/.config/GIMP/2.10/plug-ins")
PLUGINS_DIR_3 = os.path.expanduser("~/.config/GIMP/3.0/plug-ins")

def main():
    if not os.path.exists(BUILD_DIR):
        print("Setting up...")
        os.system("meson setup " + BUILD_DIR)
    os.chdir(BUILD_DIR)
    print("Compiling...")
    os.system("meson compile")

    if not os.path.exists(PLUGINS_DIR_2):
        os.system("mkdir -p " + PLUGINS_DIR_2)
    print("Copying the 'texturize' binary to " + PLUGINS_DIR_2 + "...")
    os.system("cp texturize " + PLUGINS_DIR_2 + "/")
    if not os.path.exists(PLUGINS_DIR_3):
        os.system("mkdir -p " + PLUGINS_DIR_3)
    if os.path.exists(PLUGINS_DIR_3):
        subdir = os.path.join(PLUGINS_DIR_3, "texturize")
        if not os.path.exists(subdir):
            os.system("mkdir " + subdir)
        print("Copying the 'texturize' binary to " + subdir + "...")
        os.system("cp texturize " + subdir)

if __name__ == "__main__":
    main()
