about summary refs log tree commit diff stats
path: root/premake5.lua
blob: 1f312d1ad90ca6cd515cb280a323b7f5d3ce817a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
workspace("Pong")
    configurations {"Debug", "Release"}

project("Pong")
    kind("WindowedApp")
    language("C")
    files {"src/*.c", "src/*.h", }
    includedirs {"raylib/src"}
    -- Prefix Option
    newoption {
        trigger     = "prefix",
        value       = "path",
        description = "Prefix for where the game is to be installed."
    }
    prefix = _OPTIONS["prefix"] or "app"

    -- Flatpak
    newoption {
        trigger     = "flatpak",
        value       = "bool",
        description = "Build a flatpak."
    }
    flatpak = _OPTIONS["flatpak"] or "false"

    -- Find raylib
    RaylibStaticLibrary = os.findlib("libraylib.a", "raylib", "raylib/src")
    if(RaylibStaticLibrary == nil) then
        os.exit(1)
    end
    libdirs {RaylibStaticLibrary}

    -- Detect OS
    if(os.ishost("linux") == true) then
        links {RaylibStaticLibrary, "m", "pthread", "dl"}
    elseif(os.ishost("bsd") == true) then
        print("It is required you build raylib to an external glfw library when on bsd.")
        -- Which BSD?
        BSD_OS = io.popen("uname")
        BSD_OS_NAME = BSD_OS:read("*a")
        BSD_OS:close()
        -- Check Result
        if(BSD_OS_NAME == "netbsd") then
            links {RaylibStaticLibrary, "m", "pthread", "glfw"}
        elseif(BSD_OS_NAME == "freebsd") then
            links {RaylibStaticLibrary, "m", "glfw", "stdthreads"}
        elseif(BSD_OS_NAME == "openbsd") then
            print("Openbsd doesn't work currently due to lack of c11 threads support.")
            links {RaylibStaticLibrary, "m", "glfw", "pthread"}
        else
            print("Couldn't figure out BSD, assuming freebsd.")
            links {RaylibStaticLibrary, "m", "glfw", "stdthreads"}
        end
    elseif(os.ishost("windows") == true) then
        print("This script is expecting a MSYS2 or Cygwin environment. You've been warned.")
    else
        links {RaylibStaticLibrary, "m", "pthread", "dl"}
    end
    newaction {
        trigger = "install",
        description = "Install the game to prefix.",
        execute = function()
            os.executef("mkdir -pv %s/Pong", prefix)
            os.executef("cp -rv resources/ %s/Pong/", prefix)
            os.executef("install -Dvm755 bin/*/Pong %s/Pong/pong", prefix)
            if(flatpak == true) then
                os.executef("install -Dvm755 src/flatpak_launch.sh %s/bin/launch.sh", prefix)
            end
        end
    }
    newaction {
        trigger = "clean",
        description = "Clean the work environment.",
        execute = function()
            os.executef("rm -rvf %s/obj", _MAIN_SCRIPT_DIR)
            os.executef("rm -rvf %s/bin", _MAIN_SCRIPT_DIR)
            os.executef("rm -rvf %s/app", _MAIN_SCRIPT_DIR)
            os.executef("rm -vf %s/Makefile", _MAIN_SCRIPT_DIR)
            os.executef("rm -vf %s/Pong.make", _MAIN_SCRIPT_DIR)
        end
    }