-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
141 lines (111 loc) · 5.6 KB
/
Makefile
File metadata and controls
141 lines (111 loc) · 5.6 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
CC = gcc
ifneq ("$(wildcard ./cJSON/libcjson.a)","")
LIB_CJSON = ./cJSON/libcjson.a
INC_CJSON = -I./cJSON
else
LIBCJSON = -lcjson
INC_CJSON = -I/usr/include/cjson
endif
INC_LODE_PNG = -I./libs
# Define the LVGL directory relative to this script
LVGL_DIR = $(PWD)/lvgl
LVGL_BUILD_DIR = $(LVGL_DIR)/build
LV_CONF_PATH = $(LVGL_DIR)/../viewer/lv_conf.h
# Define the path to the LVGL static library
LVGL_LIB = $(LVGL_BUILD_DIR)/lib/liblvgl.a
SDL_LIBS = `pkg-config sdl2 -libs`
SDL_CFLAGS = `pkg-config sdl2 -cflags`
LVGL_INC = -I./lvgl/src
# Set __DEV_MODE__ for debug logging in the main generator tool
CFLAGS = -Wall -g -std=c11 -I. -D__DEV_MODE__ $(INC_CJSON) -I./cJSON -D_GNU_SOURCE -I./lvgl -DLV_CONF_PATH='"$(LV_CONF_PATH)"' -DLV_BUILD_CONF_PATH='"$(LV_CONF_PATH)"' $(SDL_CFLAGS) $(LVGL_INC) -I./viewer
LIBS = $(LIB_CJSON) -lm $(LVGL_LIB) $(SDL_LIBS)
TARGET = lvgl_ui_generator
# Python script for generating lvgl_dispatch.c and .h
API_SPEC_GENERATOR_PY = ./generate_dynamic_lvgl_dispatch.py
LV_DEF_JSON = ./data/lv_def.json
API_SPEC_JSON = ./api_spec.json
API_SPEC_LVGL = ./api_spec_lvgl.json
DYNAMIC_LVGL_H = ./c_gen/lvgl_dispatch.h
DYNAMIC_LVGL_C = ./c_gen/lvgl_dispatch.c
DYNAMIC_LVGL_O = $(DYNAMIC_LVGL_C:.c=.o)
# Options for the python script
CONSOLIDATION_MODE ?= aggressive # Default to aggressive, can be overridden: make CONSOLIDATION_MODE=typesafe
#CONSOLIDATION_MODE ?= typesafe # Default to typesafe, can be overridden: make CONSOLIDATION_MODE=aggressive
# To enable specific input methods for dynamic_lvgl:
# Override with make DYNAMIC_LVGL_CFLAGS="-DENABLE_CJSON_INPUTS -DENABLE_IR_INPUTS"
DYNAMIC_LVGL_CFLAGS ?= -DENABLE_IR_INPUTS # Default to only IR inputs
# Add DYNAMIC_LVGL_CFLAGS to general CFLAGS
CFLAGS += $(DYNAMIC_LVGL_CFLAGS)
SOURCES = api_spec.c ir.c registry.c generator.c ir_printer.c ir_debug_printer.c c_code_printer.c lvgl_ui_utils.c debug_log.c cJSON/cJSON.c $(DYNAMIC_LVGL_C) viewer/sdl_viewer.c viewer/lvgl_assert_handler.c viewer/view_inspector.c lvgl_renderer.c yaml_parser.c warning_printer.c data_binding.c libs/lodepng.c ui_sim.c deferred_loader.c
OBJECTS = $(SOURCES:.c=.o)
# Main target rule now depends on the LVGL library
$(TARGET): $(OBJECTS) main.o $(LVGL_LIB)
$(CC) $(CFLAGS) -o $(TARGET) $(OBJECTS) main.o $(LIBS)
$(OBJECTS): %.o: %.c
@echo "Compiling $<..."
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c $< -o $@
# Rule to build the LVGL static library if it doesn't exist.
# This rule is triggered because $(LVGL_LIB) is a prerequisite for $(TARGET).
$(LVGL_LIB):
@echo "LVGL library not found or out of date. Building it..."
./build_lvgl.sh
$(API_SPEC_LVGL) : ./generate_api_spec.py $(LV_DEF_JSON)
@echo "Generating LVGL API Spec: $(API_SPEC_LVGL)"
python3 ./generate_api_spec.py ./data/lv_def.json --lvgl-conf $(LV_CONF_PATH) > $(API_SPEC_LVGL)
$(API_SPEC_JSON): $(API_SPEC_LVGL) ./api_spec_custom.json merge_custom_json.sh
@echo "Producing final API Spec: $(API_SPEC_JSON) (merging custom if present)"
bash merge_custom_json.sh
$(LV_DEF_JSON): $(LV_CONF_PATH)
python3 $(LVGL_DIR)/scripts/gen_json/gen_json.py --lvgl-config="$(LV_CONF_PATH)" > $(LV_DEF_JSON)
# Rule to generate dynamic_lvgl.h and dynamic_lvgl.c
# These files depend on the Python script and the api_spec.json
$(DYNAMIC_LVGL_H) $(DYNAMIC_LVGL_C): $(API_SPEC_GENERATOR_PY) $(API_SPEC_JSON)
@echo "Generating $(DYNAMIC_LVGL_H) and $(DYNAMIC_LVGL_C)"
python3 $(API_SPEC_GENERATOR_PY) $(API_SPEC_JSON) \
--header-out $(DYNAMIC_LVGL_H) \
--source-out $(DYNAMIC_LVGL_C)
# Ensure generated files are created before objects that depend on them are compiled.
# Specifically, main.o or any other .o that might include dynamic_lvgl.h
# and the dynamic_lvgl.o itself.
$(DYNAMIC_LVGL_O): $(DYNAMIC_LVGL_C) $(DYNAMIC_LVGL_H)
main.o: $(DYNAMIC_LVGL_H)
.PHONY: all clean run ex_cnc_rendered ex_cnc_native
all: $(TARGET)
run: $(TARGET)
./$(TARGET) $(API_SPEC_JSON) ./ui.json
# --- CNC Example Targets ---
TARGET_CNC_RENDERED = ./ex_cnc/ex_cnc_rendered
ex_cnc_rendered: $(TARGET_CNC_RENDERED)
$(TARGET_CNC_RENDERED): $(OBJECTS) $(LVGL_LIB) ex_cnc/cnc_app.o ex_cnc/cnc_main_live.o
@echo "\n--- Building CNC Example (Renderer) ---\n"
# $(MAKE) -C ex_cnc run_renderer
$(CC) $(CFLAGS) -o $(TARGET_CNC_RENDERED) $^ $(LIBS)
-$(TARGET_CNC_RENDERED)
TARGET_CNC_NATIVE = ./ex_cnc/ex_cnc_native
ex_cnc_native: $(TARGET_CNC_NATIVE)
C_GEN_DIR = ./c_gen
GENERATED_UI_SOURCE = $(C_GEN_DIR)/create_ui.c
GENERATED_UI_HEADER = $(C_GEN_DIR)/create_ui.h
GENERATED_UI_OBJ = $(GENERATED_UI_SOURCE:.c=.o)
EX_CNC_UI_YAML = ex_cnc/cnc_ui.yaml
$(GENERATED_UI_SOURCE) $(GENERATED_UI_HEADER): $(EX_CNC_UI_YAML) $(TARGET)
@echo "--- Generating C code from ui.yaml ---"
@mkdir -p $(C_GEN_DIR)
@rm -f $(GENERATED_UI_SOURCE)
./$(TARGET) $(API_SPEC_JSON) $(EX_CNC_UI_YAML) --codegen c_code > $(GENERATED_UI_SOURCE)
@echo "// Generated header\n#ifndef CREATE_UI_H\n#define CREATE_UI_H\n#include \"lvgl.h\"\nvoid create_ui(lv_obj_t* parent);\n#endif" > $(GENERATED_UI_HEADER)
$(TARGET_CNC_NATIVE): $(OBJECTS) $(LVGL_LIB) ex_cnc/cnc_app.o ex_cnc/cnc_main_native.o $(GENERATED_UI_OBJ)
@echo "\n--- Delegating to CNC Example Makefile (Native) ---\n"
# $(MAKE) -C ex_cnc all
$(CC) $(CFLAGS) -o $(TARGET_CNC_NATIVE) $^ $(LIBS)
$(TARGET_CNC_NATIVE)
ex_cnc/cnc_main_live.o: ex_cnc/cnc_main.c
$(CC) $(CFLAGS) -DCNC_LIVE_RENDER_MODE -c $< -o $@
ex_cnc/cnc_main_native.o: ex_cnc/cnc_main.c $(GENERATED_UI_HEADER)
$(CC) $(CFLAGS) -DCNC_STATIC_BUILD_MODE -c $< -o $@
clean:
@rm $(API_SPEC_JSON) api_spec_lvgl.json $(LV_DEF_JSON)
@rm -f $(OBJECTS) $(TARGET) $(DYNAMIC_LVGL_H) $(DYNAMIC_LVGL_C) $(DYNAMIC_LVGL_O)
@# rm -rf $(LVGL_BUILD_DIR)
@rm -f $(TARGET_CNC_NATIVE) $(TARGET_CNC_RENDERED) $(GENERATED_UI_OBJ)