-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
168 lines (137 loc) · 4.6 KB
/
Copy pathMakefile
File metadata and controls
168 lines (137 loc) · 4.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
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
# Selection Logger Makefile
# Cross-platform build system for Windows (Wine testing) and Linux
# Directories
SRC_DIR = src
# Compiler settings
CXX = g++
CXXFLAGS = -std=c++11 -Wall -Wextra -O2 -I$(SRC_DIR)
LDFLAGS =
# Platform settings (can be overridden)
PLATFORM ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
EXE_EXT =
# Static linking option (for Windows release)
STATIC ?= 0
# Default to Linux if not specified
ifeq ($(PLATFORM),windows)
EXE_EXT = .exe
CXX = x86_64-w64-mingw32-g++
CXXFLAGS += -D_WIN32_WINNT=0x0600 -DWIN32_LEAN_AND_MEAN -D_WIN32
LDFLAGS += -lole32 -luser32 -ladvapi32 -lshell32
# Static linking for release builds
ifeq ($(STATIC),1)
CXXFLAGS += -static
LDFLAGS += -static-libgcc -static-libstdc++ -Wl,-Bstatic
endif
else
# Default to Linux
PLATFORM = linux
CXXFLAGS +=
LDFLAGS += -lX11 -lpthread
endif
# Targets
TARGET = selection-logger$(EXE_EXT)
# Source files (relative to SRC_DIR)
COMMON_SRCS = clipboard.cpp platform.cpp win32_compat.cpp
MAIN_SRC = memory_daemon_auto_cross.cpp
# All sources with paths
SRCS = $(MAIN_SRC) $(COMMON_SRCS)
OBJS = $(addprefix $(SRC_DIR)/, $(SRCS:.cpp=.o))
# Windows-specific objects
ifeq ($(PLATFORM),windows)
WIN32_OBJS = $(SRC_DIR)/service_win32.o $(SRC_DIR)/main_win32.o
else
WIN32_OBJS =
endif
# Default target
all: $(TARGET)
# Release target (statically linked for Windows)
release: clean
ifeq ($(PLATFORM),windows)
$(MAKE) STATIC=1
else
$(MAKE)
endif
# Clean target
clean:
rm -f $(SRC_DIR)/*.o $(TARGET) test/test_selection test/test_clipboard_formats test/test_file_copy test/test_platform
# Link
$(TARGET): $(OBJS) $(WIN32_OBJS)
$(CXX) -o $@ $(OBJS) $(WIN32_OBJS) $(LDFLAGS)
# Compile rules
$(SRC_DIR)/%.o: $(SRC_DIR)/%.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
# Windows-specific sources compilation (stubs on non-Windows)
$(SRC_DIR)/service_win32.o: $(SRC_DIR)/service_win32.cpp $(SRC_DIR)/service_win32.h
ifeq ($(PLATFORM),windows)
$(CXX) $(CXXFLAGS) -c $< -o $@
else
@echo "Skipping Windows-only file: $<"
@touch $@ # Create empty object file for Linux builds
endif
$(SRC_DIR)/main_win32.o: $(SRC_DIR)/main_win32.cpp
ifeq ($(PLATFORM),windows)
$(CXX) $(CXXFLAGS) -c $< -o $@
else
@echo "Skipping Windows-only file: $<"
@touch $@ # Create empty object file for Linux builds
endif
# Test build rules
TEST_SRCS = test/test_selection.cpp test/test_clipboard_formats.cpp test/test_file_copy.cpp test/test_platform.cpp
TEST_BINS = test/test_selection test/test_clipboard_formats test/test_file_copy test/test_platform
COMMON_OBJS = $(addprefix $(SRC_DIR)/, clipboard.o platform.o win32_compat.o)
test_bins: $(TEST_BINS)
test/test_selection: test/test_selection.cpp $(COMMON_OBJS)
$(CXX) $(CXXFLAGS) -o $@ $< $(COMMON_OBJS) $(LDFLAGS)
test/test_clipboard_formats: test/test_clipboard_formats.cpp $(COMMON_OBJS)
$(CXX) $(CXXFLAGS) -o $@ $< $(COMMON_OBJS) $(LDFLAGS)
test/test_file_copy: test/test_file_copy.cpp $(COMMON_OBJS)
$(CXX) $(CXXFLAGS) -o $@ $< $(COMMON_OBJS) $(LDFLAGS)
test/test_platform: test/test_platform.cpp $(COMMON_OBJS)
$(CXX) $(CXXFLAGS) -o $@ $< $(COMMON_OBJS) $(LDFLAGS)
# Test targets
test: all test_bins
ifeq ($(PLATFORM),linux)
@echo "Running Linux tests..."
cd test && ./test_selection || true
cd test && ./test_clipboard_formats || true
cd test && ./test_platform || true
else
@echo "Windows build - use 'make test-wine' for Wine testing"
endif
# Wine testing
test-wine: $(TARGET)
@echo "Testing with Wine..."
@echo "Note: Wine clipboard access may require X11 integration"
wine $(TARGET) --help || true
# Build for Windows (cross-compile)
windows: clean
$(MAKE) CXX=x86_64-w64-mingw32-g++ PLATFORM=windows
# Build for Linux (native)
linux: clean
$(MAKE) PLATFORM=linux
# Install (Linux only)
install: $(TARGET)
@echo "Installing to /usr/local/bin..."
cp $(TARGET) /usr/local/bin/
@echo "Done."
# Uninstall (Linux only)
uninstall:
@echo "Removing from /usr/local/bin..."
sudo rm -f /usr/local/bin/$(TARGET)
# Help
help:
@echo "Selection Logger Build System"
@echo ""
@echo "Targets:"
@echo " all - Build for current platform (default)"
@echo " windows - Cross-compile for Windows"
@echo " linux - Build for Linux (native)"
@echo " clean - Remove build artifacts"
@echo " test - Run tests (Linux only)"
@echo " test-wine - Test Windows build with Wine"
@echo " install - Install to /usr/local/bin (Linux)"
@echo " uninstall - Uninstall from /usr/local/bin"
@echo ""
@echo "Current platform: $(PLATFORM)"
@echo "Compiler: $(CXX)"
.PHONY: all clean test test-wine windows linux install uninstall help