-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·300 lines (262 loc) · 9.85 KB
/
Makefile
File metadata and controls
executable file
·300 lines (262 loc) · 9.85 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# Makefile for RODOS-5NS Daemon
CC = gcc
CXX = g++
# DAEMON version information
DAEMON_MAJOR_VERSION = 1
DAEMON_MINOR_VERSION = 0
DAEMON_PATCH_VERSION = 0
# Full version string
DAEMON_VERSION = $(DAEMON_MAJOR_VERSION).$(DAEMON_MINOR_VERSION).$(DAEMON_PATCH_VERSION)
# Platform detection
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)
# Compiler flags
CFLAGS = -std=c11 -Wall -Wextra -O2 -I./include -D_POSIX_C_SOURCE=200809L
CXXFLAGS = -std=c++17 -Wall -Wextra -O2 -I./include -Wno-sign-compare
# Linker flags
LDFLAGS = -lusb-1.0 -lpthread -lm
GTEST_FLAGS = -lgtest -lgtest_main -lgmock -lgmock_main -lpthread
# Platform-specific adjustments
ifeq ($(UNAME_S),Darwin)
# macOS specific settings - Apple Silicon (M1/M2/M3) Homebrew path
ifeq ($(UNAME_M),arm64)
# Apple Silicon Homebrew path
HOMEBREW_PREFIX = /opt/homebrew
else
# Intel Homebrew path
HOMEBREW_PREFIX = /usr/local
endif
# Find libusb path dynamically
LIBUSB_PATH := $(shell find $(HOMEBREW_PREFIX)/Cellar/libusb -name "libusb.h" 2>/dev/null | head -1 | xargs dirname)
ifneq ($(LIBUSB_PATH),)
CFLAGS += -I$(LIBUSB_PATH)
CXXFLAGS += -I$(LIBUSB_PATH)
else
CFLAGS += -I$(HOMEBREW_PREFIX)/include
CXXFLAGS += -I$(HOMEBREW_PREFIX)/include
endif
# Find libusb library path
LIBUSB_LIB_PATH := $(shell find $(HOMEBREW_PREFIX)/Cellar/libusb -name "libusb-1.0.dylib" -o -name "libusb-1.0.a" 2>/dev/null | head -1 | xargs dirname)
ifneq ($(LIBUSB_LIB_PATH),)
LDFLAGS = -L$(LIBUSB_LIB_PATH) -lusb-1.0 -lpthread -lm
else
LDFLAGS = -L$(HOMEBREW_PREFIX)/lib -lusb-1.0 -lpthread -lm
endif
# Google Test paths (fixed)
GTEST_BASE := /opt/homebrew/Cellar/googletest/1.17.0
ifneq ($(wildcard $(GTEST_BASE)),)
CXXFLAGS += -I$(GTEST_BASE)/include
GTEST_FLAGS = -L$(GTEST_BASE)/lib -lgtest -lgtest_main -lgmock -lgmock_main -lpthread
else
# Fallback: try to find it
GTEST_BASE := $(shell find $(HOMEBREW_PREFIX)/Cellar/googletest -maxdepth 1 -type d 2>/dev/null | sort -r | head -1)
ifneq ($(GTEST_BASE),)
CXXFLAGS += -I$(GTEST_BASE)/include
GTEST_FLAGS = -L$(GTEST_BASE)/lib -lgtest -lgtest_main -lgmock -lgmock_main -lpthread
else
GTEST_FLAGS = -lgtest -lgtest_main -lgmock -lgmock_main -lpthread
endif
endif
DEVICE_PATH = /tmp/rodos5ns
else
# Linux specific settings
CFLAGS += -I./include
CXXFLAGS += -I./include
DEVICE_PATH = /dev/rodos5ns
endif
# Project info
DAEMON_TARGET = rodosDev_$(DAEMON_VERSION)
TEST_PARSER = test_parser
TEST_INTEGRATION = test_integration
TEST_SIGNAL = test_signal
TEST_USB_MOCK = test_usb_mock
# Source files
DAEMON_SRC = src/daemon.c src/parser.c
TEST_PARSER_SRC = test/test_parser.cpp
TEST_INTEGRATION_SRC = test/test_integration.cpp
TEST_SIGNAL_SRC = test/test_signal.cpp
TEST_USB_MOCK_SRC = test/test_usb_mock.cpp
# Default target - build daemon
all: $(DAEMON_TARGET)
# Build daemon executable
$(DAEMON_TARGET): obj/daemon.o obj/parser.o obj/daemon_io.o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
@echo "✅ Daemon built: $@"
# Build parser tests
# Object files for tests
PARSER_OBJ = obj/parser.o
# Build parser tests
$(TEST_PARSER): $(TEST_PARSER_SRC) $(PARSER_OBJ) include/rodos5ns.h include/parser.h
$(CXX) $(CXXFLAGS) -I./include -o $@ $(TEST_PARSER_SRC) $(PARSER_OBJ) $(GTEST_FLAGS)
@echo "✅ Parser tests built: $@"
# Build integration tests
$(TEST_INTEGRATION): $(TEST_INTEGRATION_SRC) include/daemon_io.h
$(CXX) $(CXXFLAGS) -I./include -o $@ $(TEST_INTEGRATION_SRC) obj/daemon_io.o $(GTEST_FLAGS)
@echo "✅ Integration tests built: $@"
# Build signal tests
$(TEST_SIGNAL): $(TEST_SIGNAL_SRC) include/rodos5ns.h
$(CXX) $(CXXFLAGS) -o $@ $(TEST_SIGNAL_SRC) $(GTEST_FLAGS)
@echo "✅ Signal tests built: $@"
# Build USB mock tests
$(TEST_USB_MOCK): $(TEST_USB_MOCK_SRC) include/rodos5ns.h
$(CXX) $(CXXFLAGS) -o $@ $(TEST_USB_MOCK_SRC) $(GTEST_FLAGS)
@echo "✅ USB mock tests built: $@"
# Compile daemon source with platform-specific flags
obj/daemon.o: src/daemon.c include/daemon_io.h
@mkdir -p obj
ifeq ($(UNAME_S),Darwin)
$(CC) $(CFLAGS) -D__APPLE__ -c $< -o $@
else
$(CC) $(CFLAGS) -c $< -o $@
endif
obj/parser.o: src/parser.c include/parser.h include/rodos5ns.h
@mkdir -p obj
ifeq ($(UNAME_S),Darwin)
$(CC) $(CFLAGS) -D__APPLE__ -c $< -o $@
else
$(CC) $(CFLAGS) -c $< -o $@
endif
obj/daemon_io.o: src/daemon_io.c include/daemon_io.h
@mkdir -p obj
ifeq ($(UNAME_S),Darwin)
$(CC) $(CFLAGS) -D__APPLE__ -c $< -o $@
else
$(CC) $(CFLAGS) -c $< -o $@
endif
# Build all tests
tests: $(TEST_PARSER) $(TEST_INTEGRATION) $(TEST_SIGNAL) $(TEST_USB_MOCK)
# Run daemon in foreground
run: $(DAEMON_TARGET)
@echo "🚀 Running daemon..."
@echo "Device file will be at $(DEVICE_PATH)"
sudo ./$(DAEMON_TARGET)
# Run all tests
test: tests
@echo "🧪 Running parser tests..."
./$(TEST_PARSER)
@echo "🧪 Running integration tests..."
./$(TEST_INTEGRATION)
@echo "🧪 Running signal tests..."
./$(TEST_SIGNAL)
@echo "🧪 Running USB mock tests..."
./$(TEST_USB_MOCK)
@echo "✅ All tests passed!"
# Run specific tests
test-parser: $(TEST_PARSER)
@echo "🧪 Running parser tests..."
./$(TEST_PARSER)
test-integration: $(TEST_INTEGRATION)
@echo "🧪 Running integration tests..."
./$(TEST_INTEGRATION)
test-signal: $(TEST_SIGNAL)
@echo "🧪 Running signal tests..."
./$(TEST_SIGNAL)
test-usb-mock: $(TEST_USB_MOCK)
@echo "🧪 Running USB mock tests..."
./$(TEST_USB_MOCK)
# Install dependencies (macOS - Apple Silicon)
install-macos:
@echo "📦 Installing dependencies for macOS (Apple Silicon)..."
@if ! command -v brew &> /dev/null; then \
echo "Installing Homebrew..."; \
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"; \
fi
brew install libusb pkg-config googletest
@echo "✅ Dependencies installed"
@echo ""
@echo "Note: For Apple Silicon Macs, Homebrew installs to /opt/homebrew"
@echo " Libraries are in /opt/homebrew/lib"
@echo " Headers are in /opt/homebrew/include"
# Install dependencies (Ubuntu/Debian)
install-ubuntu:
@echo "📦 Installing dependencies for Ubuntu/Debian..."
sudo apt-get update
sudo apt-get install -y libusb-1.0-0-dev libgtest-dev libgmock-dev g++ pkg-config
@echo "✅ Dependencies installed"
# Check test dependencies
check-deps:
@echo "🔍 Checking dependencies..."
@echo "OS: $(UNAME_S) $(UNAME_M)"
@echo "C compiler: $(CC)"
@which $(CC) >/dev/null && echo "✅ Found $(CC)" || echo "❌ $(CC) not found"
@echo "C++ compiler: $(CXX)"
@which $(CXX) >/dev/null && echo "✅ Found $(CXX)" || echo "❌ $(CXX) not found"
@echo "pkg-config:"
@which pkg-config >/dev/null && echo "✅ Found pkg-config" || echo "❌ pkg-config not found"
@echo "libusb:"
@pkg-config --exists libusb-1.0 && echo "✅ libusb available via pkg-config" || echo "⚠️ libusb not found via pkg-config"
@echo "libusb header path:"
@find $(HOMEBREW_PREFIX) -name "libusb.h" 2>/dev/null | head -1 && echo "✅ libusb.h found" || echo "❌ libusb.h not found"
@echo "libusb library path:"
@find $(HOMEBREW_PREFIX) -name "libusb-1.0.dylib" -o -name "libusb-1.0.a" 2>/dev/null | head -1 && echo "✅ libusb library found" || echo "❌ libusb library not found"
@echo "Google Test:"
@if [ -f "/opt/homebrew/lib/libgtest.a" ] || [ -f "/usr/local/lib/libgtest.a" ] || [ -f "/usr/lib/libgtest.a" ] || pkg-config --exists gtest; then \
echo "✅ Google Test available"; \
else \
echo "❌ Google Test not found. Run 'make install-macos'"; \
fi
@echo ""
@echo "Current paths:"
@echo "CFLAGS: $(CFLAGS)"
@echo "LDFLAGS: $(LDFLAGS)"
@echo "Available test targets:"
@echo " - test-parser"
@echo " - test-integration"
@echo " - test-signal"
@echo " - test-usb-mock"
@echo " - test (all tests)"
# Clean build files
clean:
rm -rf obj
rm -f $(DAEMON_TARGET) $(TEST_PARSER) $(TEST_INTEGRATION) $(TEST_SIGNAL) $(TEST_USB_MOCK)
@echo "🧹 Clean complete"
# Deep clean (including device files)
distclean: clean
rm -f /tmp/rodos5ns /dev/rodos5ns 2>/dev/null || true
@echo "🧹 Deep clean complete"
# Show system information
info:
@echo "📋 System Information:"
@echo " OS: $(UNAME_S) $(UNAME_M)"
@echo " Homebrew prefix: $(HOMEBREW_PREFIX)"
@echo " libusb include path: $(LIBUSB_PATH)"
@echo " libusb lib path: $(LIBUSB_LIB_PATH)"
@echo " C Compiler: $(CC)"
@echo " C++ Compiler: $(CXX)"
@echo " Device path: $(DEVICE_PATH)"
@echo " C Flags: $(CFLAGS)"
@echo " C++ Flags: $(CXXFLAGS)"
@echo " Targets:"
@echo " - $(DAEMON_TARGET) (daemon)"
@echo " - $(TEST_PARSER) (parser tests)"
@echo " - $(TEST_INTEGRATION) (integration tests)"
@echo " - $(TEST_SIGNAL) (signal tests)"
@echo " - $(TEST_USB_MOCK) (USB mock tests)"
# Show help
help:
@echo "RODOS-5NS Daemon Makefile"
@echo "========================"
@echo "Build targets:"
@echo " all - Build daemon (default)"
@echo " tests - Build all tests"
@echo ""
@echo "Run targets:"
@echo " run - Run daemon in foreground (requires sudo)"
@echo " test - Build and run all tests"
@echo " test-parser - Run parser tests only"
@echo " test-integration - Run integration tests only"
@echo " test-signal - Run signal tests only"
@echo " test-usb-mock - Run USB mock tests only"
@echo ""
@echo "Installation:"
@echo " install-macos - Install dependencies on macOS"
@echo " install-ubuntu - Install dependencies on Ubuntu/Debian"
@echo " check-deps - Check if dependencies are installed"
@echo ""
@echo "Maintenance:"
@echo " clean - Clean build files"
@echo " distclean - Clean everything including device files"
@echo " info - Show build information"
@echo " help - Show this help"
.PHONY: all tests run test test-parser test-integration test-signal test-usb-mock \
install-macos install-ubuntu check-deps clean distclean info help