-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
132 lines (110 loc) · 3.75 KB
/
Copy pathMakefile
File metadata and controls
132 lines (110 loc) · 3.75 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
# Inky Display Library Makefile
# Supports hardware-only, emulator, and test builds
CC = gcc
CFLAGS = -Wall -Wextra -O2 -std=gnu99 -D_GNU_SOURCE -I./include
LDFLAGS = -lm
# Directories
SRC_DIR = src
INC_DIR = include
TEST_DIR = test
BUILD_DIR = build
LIB_DIR = lib
# Source files
COMMON_SRC = $(SRC_DIR)/inky_common.c
HARDWARE_SRC = $(SRC_DIR)/inky_hardware.c
EMULATOR_SRC = $(SRC_DIR)/inky_emulator.c
# Object files
COMMON_OBJ = $(BUILD_DIR)/inky_common.o
HARDWARE_OBJ = $(BUILD_DIR)/inky_hardware.o
EMULATOR_OBJ = $(BUILD_DIR)/inky_emulator.o
# Library targets
LIBINKY_HW = $(LIB_DIR)/libinky_hw.a
LIBINKY_EMU = $(LIB_DIR)/libinky_emu.a
# Test executables
TEST_MODELS = $(BUILD_DIR)/test_models
# Default target
.PHONY: all
all: emulator
# Create build directories
$(BUILD_DIR) $(LIB_DIR):
mkdir -p $@
# Compile common source (used by both hardware and emulator)
$(COMMON_OBJ): $(COMMON_SRC) $(INC_DIR)/inky.h $(INC_DIR)/inky_internal.h | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Compile hardware source
$(HARDWARE_OBJ): $(HARDWARE_SRC) $(INC_DIR)/inky.h $(INC_DIR)/inky_internal.h | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Compile emulator source
$(EMULATOR_OBJ): $(EMULATOR_SRC) $(INC_DIR)/inky.h $(INC_DIR)/inky_internal.h | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Build hardware-only library (for Raspberry Pi - Linux only)
.PHONY: hardware
hardware:
@if [ "$$(uname)" != "Linux" ]; then \
echo "Error: Hardware library can only be built on Linux (Raspberry Pi)"; \
echo "The hardware implementation requires Linux-specific SPI, GPIO, and I2C interfaces."; \
echo "Use 'make emulator' to build the emulator library for development on macOS/other platforms."; \
exit 1; \
fi
@$(MAKE) $(LIBINKY_HW)
$(LIBINKY_HW): $(COMMON_OBJ) $(HARDWARE_OBJ) | $(LIB_DIR)
ar rcs $@ $^
@echo "Hardware library built: $@"
@echo "Link with: -L./lib -linky_hw"
# Build emulator library (for development/testing)
.PHONY: emulator
emulator: $(LIBINKY_EMU)
$(LIBINKY_EMU): $(COMMON_OBJ) $(EMULATOR_OBJ) | $(LIB_DIR)
ar rcs $@ $^
@echo "Emulator library built: $@"
@echo "Link with: -L./lib -linky_emu"
# Build test programs
.PHONY: test
test: $(TEST_MODELS)
$(TEST_MODELS): $(TEST_DIR)/test_models.c $(LIBINKY_EMU) | $(BUILD_DIR)
$(CC) $(CFLAGS) $< -L./$(LIB_DIR) -linky_emu $(LDFLAGS) -o $@
@echo "Test executable built: $@"
# Run tests
.PHONY: run-test
run-test: $(TEST_MODELS)
@echo "Running display model tests..."
@cd $(BUILD_DIR) && ./test_models
@echo ""
@echo "Test images generated in $(BUILD_DIR)/"
# Clean build artifacts
.PHONY: clean
clean:
rm -rf $(BUILD_DIR) $(LIB_DIR)
@echo "Cleaned build artifacts"
# Clean everything including test outputs
.PHONY: distclean
distclean: clean
rm -f $(TEST_DIR)/*.ppm
@echo "Cleaned all generated files"
# Help target
.PHONY: help
help:
@echo "Inky Display Library - Build Targets:"
@echo ""
@echo " make hardware - Build hardware-only library (libinky_hw.a)"
@echo " Use this for Raspberry Pi deployment"
@echo ""
@echo " make emulator - Build emulator library (libinky_emu.a) [default]"
@echo " Use this for development and testing"
@echo ""
@echo " make test - Build test programs using emulator"
@echo ""
@echo " make run-test - Build and run test programs"
@echo ""
@echo " make all - Build emulator (same as 'make emulator')"
@echo ""
@echo " make clean - Remove build artifacts"
@echo ""
@echo " make distclean - Remove all generated files including test images"
@echo ""
@echo "Library API: include/inky.h"
@echo ""
@echo "Examples:"
@echo " Compile for hardware: make clean && make hardware"
@echo " Compile for testing: make clean && make test run-test"
.PHONY: all emulator hardware test run-test clean distclean help