about summary refs log tree commit diff stats
path: root/premake5.lua
blob: 53ee6d26128e8fc6e289703a279f8d7264ece410 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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}
    linkoptions {"`pkgconf --libs glfw3`", "`pkgconf --libs gl`"}

    -- 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\n") then
            links {RaylibStaticLibrary, "m", "pthread"}
        elseif(BSD_OS_NAME == "freebsd") then
            links {RaylibStaticLibrary, "m", "stdthreads"}
        elseif(BSD_OS_NAME == "OpenBSD\n") then
	    
	    -- Work around the fact openbsd doesn't have c11 threads.
	    includedirs {"src/openbsd"}
	    files {"src/openbsd/*.c", "src/openbsd/*.h"}

	    -- Tell compiler where libraries are.
	    libdirs {"/usr/local/lib"}
            links {RaylibStaticLibrary, "m", "pthread"}

        else
            print("Couldn't figure out BSD, assuming freebsd.")
            links {RaylibStaticLibrary, "m", "stdthreads"}
        end
    elseif(os.ishost("windows") == true) then
        print("This script is expecting a MSYS2 or Cygwin environment. You've been warned.")
        links {RaylibStaticLibrary, "-lopengl32", "-lgdi32", "-lwinmm", "-lpthread", "-lm"}
        includedirs {"raylib/src", "src/windows"}
    else
        links {RaylibStaticLibrary, "m", "pthread", "dl"}
    end

    newaction {
        trigger = "install",
        description = "Install the game to prefix.",
        execute = function()
            os.executef("mkdir -p %s/Pong", prefix)
            os.executef("cp -rv resources/ %s/Pong/", prefix)
            os.executef("install -Dm755 bin/*/Pong %s/Pong/pong", prefix)
        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)
            os.executef("rm -rvf %s/flatpak_repo", _MAIN_SCRIPT_DIR)
            os.executef("rm -rvf %s/.flatpak-builder", _MAIN_SCRIPT_DIR)
            os.executef("rm -rvf %s/build-dir", _MAIN_SCRIPT_DIR)
            os.executef("rm -vf %s/*.flatpak", _MAIN_SCRIPT_DIR)
        end
    }