summaryrefslogtreecommitdiffhomepage
path: root/tools/kfwrk.py
blob: 585e4c32d0a557a3a36d3d529e0f7e1bdfee3a94 (plain)
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
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import os, json, sys

"""
    Create directory structure for the framework.
"""
def create_directory_structure(base_path_fwrk, project_file_name, project_name):
    # Define the directory structure
    structure = {
        project_name: {
            "headers": {
                ".keep": None
            },
            "dist": {
                ".keep": None
            },
            "src": {
                ".keep": None,
                "DylibMain.cc": None,
            },
            "xml": {
                ".keep": None
            },
            ".keep": None,
            f"{project_file_name}.json": {}
        }
    }

    def create_structure(path, structure_in):
        for name, content in structure_in.items():
            current_path = os.path.join(path, name)
            # Create directories or files based on the content type
            if isinstance(content, dict) and current_path.endswith(".json") == False:
                os.makedirs(current_path, exist_ok=True)
                create_structure(current_path, content)
            elif content is None:
                # Create an empty file
                with open(current_path, 'w') as f:
                    pass

    # Create the base directory
    os.makedirs(base_path_fwrk, exist_ok=True)
    create_structure(base_path_fwrk, structure)

    # Create the JSON file
    proj_json_path = os.path.join(base_path_fwrk, project_name, f"{project_file_name}.json")

    manifest = {
        "compiler_path": "clang++",
        "compiler_std": "c++20",
        "headers_path": ["./", "../../../src/kernel", "../../../public/frameworks/", "../../../src/", "./"],
        "sources_path": [

        ],
        "output_name": f"./dist/lib{project_name}.dylib",
        "cpp_macros": [
            "kSampleFWVersion=0x0100",
            "kSampleFWVersionHighest=0x0100",
            "kSampleFWVersionLowest=0x0100",
            "__NE_SDK__"
        ]
    }

    with open(proj_json_path, 'w') as json_file:
        json.dump(manifest, json_file, indent=4)

    proj_cpp_path = os.path.join(base_path_fwrk, project_name, f"src/DylibMain.cc")

    cpp_file = "#include <libSystem/SystemKit/System.h>\n\nSInt32 _DylibAttach(SInt32 argc, Char* argv[]) {\n\treturn EXIT_FAILURE;\n}"

    with open(proj_cpp_path, 'w') as cpp_file_io:
        cpp_file_io.write(cpp_file)

    xml_blob = f"<PropertyList>\n<PLEntry Type=\"CFString\" Name=\"LibraryName\" Len=\"{len(project_name)}\" Value=\"{project_name}\" /></PropertyList>"
    proj_xml_path = os.path.join(base_path_fwrk, project_name, f"xml/app.xml")

    with open(proj_xml_path, 'w') as cpp_file_io:
        cpp_file_io.write(xml_blob)

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("HELP: mkfwrk.py <project_name>")
        sys.exit(os.EX_CONFIG)

    base_path = os.getcwd()  # Use the current working directory as the base path
    create_directory_structure(base_path, sys.argv[1], sys.argv[1] + '.fwrk')

    print("INFO: Framework created successfully.")