aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: d4bdf64d414fe08967187fb2ccfa64c09af75512 (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
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
# SRDWM Makefile
# Builds the project without requiring cmake

CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra -Wpedantic -fPIC
INCLUDES = -Isrc -Isrc/core -Isrc/layouts -Isrc/input -Isrc/platform -Isrc/config -Isrc/utils

# Platform detection
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)

# Platform-specific flags and libraries
ifeq ($(UNAME_S),Linux)
    PLATFORM = LINUX_PLATFORM
    CXXFLAGS += -DLINUX_PLATFORM
    
    # Check for Wayland support
    ifeq ($(shell pkg-config --exists wayland-client 2>/dev/null && echo yes),yes)
        ifeq ($(shell pkg-config --exists wlroots 2>/dev/null && echo yes),yes)
            CXXFLAGS += -DWAYLAND_ENABLED
            WAYLAND_LIBS = $(shell pkg-config --libs wayland-client wlroots 2>/dev/null)
            WAYLAND_CFLAGS = $(shell pkg-config --cflags wayland-client wlroots 2>/dev/null)
        endif
    endif
    
    # X11 libraries (always available on Linux)
    X11_LIBS = -lX11 -lXrandr -lXinerama -lXfixes -lXcursor
    X11_CFLAGS = $(shell pkg-config --cflags x11 xrandr xinerama xfixes xcursor 2>/dev/null || echo "")
    
else ifeq ($(UNAME_S),Darwin)
    PLATFORM = MACOS_PLATFORM
    CXXFLAGS += -DMACOS_PLATFORM
    LIBS = -framework Cocoa -framework Carbon -framework IOKit
    
else ifeq ($(UNAME_S),MINGW32_NT-10.0)
    PLATFORM = WIN32_PLATFORM
    CXXFLAGS += -DWIN32_PLATFORM
    LIBS = -luser32 -lgdi32 -ldwmapi
    
else ifeq ($(UNAME_S),MINGW64_NT-10.0)
    PLATFORM = WIN32_PLATFORM
    CXXFLAGS += -DWIN32_PLATFORM
    LIBS = -luser32 -lgdi32 -ldwmapi
    
else ifeq ($(UNAME_S),MSYS_NT-10.0)
    PLATFORM = WIN32_PLATFORM
    CXXFLAGS += -DWIN32_PLATFORM
    LIBS = -luser32 -lgdi32 -ldwmapi
    
else
    PLATFORM = UNKNOWN
    $(warning Unknown platform: $(UNAME_S))
endif

# Lua support (optional)
LUA_AVAILABLE := $(shell ldconfig -p | grep -q liblua5.4 && echo yes)
ifeq ($(LUA_AVAILABLE),yes)
    # Check for Lua headers
    LUA_HEADERS := $(shell find /usr/include -name "lua.h" 2>/dev/null | head -1)
    ifneq ($(LUA_HEADERS),)
        CXXFLAGS += -DLUA_ENABLED
        LUA_LIBS = -llua5.4
        LUA_CFLAGS = -I$(dir $(LUA_HEADERS))
        LUA_SOURCES = src/config/lua_manager.cc
        $(info Lua support enabled)
    else
        $(warning Lua runtime found but headers not found - Lua support disabled)
        LUA_SOURCES = 
    endif
else
    $(warning Lua not found - Lua support disabled)
    LUA_SOURCES = 
endif

# Source files
SOURCES = \
    src/main.cc \
    src/core/window.cc \
    src/core/window_manager.cc \
    src/layouts/layout_engine.cc \
    src/layouts/dynamic_layout.cc \
    src/layouts/tiling_layout.cc \
    src/layouts/smart_placement.cc \
    src/platform/platform_factory.cc

# Add Lua sources if available
ifneq ($(LUA_SOURCES),)
    SOURCES += $(LUA_SOURCES)
endif

# Platform-specific source files
ifeq ($(PLATFORM),LINUX_PLATFORM)
    SOURCES += src/platform/x11_platform.cc
    ifeq ($(shell pkg-config --exists wlroots 2>/dev/null && echo yes),yes)
        SOURCES += src/platform/wayland_platform.cc
    endif
else ifeq ($(PLATFORM),WIN32_PLATFORM)
    SOURCES += src/platform/windows_platform.cc
else ifeq ($(PLATFORM),MACOS_PLATFORM)
    SOURCES += src/platform/macos_platform.cc
endif

# Object files
OBJECTS = $(SOURCES:.cc=.o)

# Target executable
TARGET = srdwm

# Default target
all: $(TARGET)

# Build the executable
$(TARGET): $(OBJECTS)
	@echo "Linking $(TARGET)..."
	$(CXX) $(OBJECTS) -o $(TARGET) $(LIBS) $(X11_LIBS) $(WAYLAND_LIBS) $(LUA_LIBS)
	@echo "Build complete: $(TARGET)"

# Compile source files
%.o: %.cc
	@echo "Compiling $<..."
	$(CXX) $(CXXFLAGS) $(INCLUDES) $(X11_CFLAGS) $(WAYLAND_CFLAGS) $(LUA_CFLAGS) -c $< -o $@

# Clean build artifacts
clean:
	@echo "Cleaning build artifacts..."
	rm -f $(OBJECTS) $(TARGET)
	@echo "Clean complete"

# Install (requires sudo)
install: $(TARGET)
	@echo "Installing $(TARGET)..."
	sudo cp $(TARGET) /usr/local/bin/
	sudo mkdir -p /usr/local/share/srdwm/config
	sudo cp -r config/* /usr/local/share/srdwm/config/
	sudo mkdir -p /usr/local/share/srdwm/docs
	sudo cp docs/*.md /usr/local/share/srdwm/docs/
	@echo "Installation complete"

# Uninstall (requires sudo)
uninstall:
	@echo "Uninstalling $(TARGET)..."
	sudo rm -f /usr/local/bin/$(TARGET)
	sudo rm -rf /usr/local/share/srdwm
	@echo "Uninstallation complete"

# Show build information
info:
	@echo "=== SRDWM Build Information ==="
	@echo "Platform: $(PLATFORM)"
	@echo "Compiler: $(CXX)"
	@echo "C++ Standard: C++17"
	@echo "Architecture: $(UNAME_M)"
	@echo "Sources: $(words $(SOURCES)) files"
	@echo "Target: $(TARGET)"
	@echo "Lua Support: $(if $(LUA_SOURCES),Enabled,Disabled)"
	@echo "================================"

# Show platform-specific information
platform-info:
	@echo "=== Platform Information ==="
	@echo "Platform: $(PLATFORM)"
ifeq ($(PLATFORM),LINUX_PLATFORM)
	@echo "Linux Platform: Enabled"
	@echo "X11 Support: Enabled"
ifeq ($(shell pkg-config --exists wlroots 2>/dev/null && echo yes),yes)
	@echo "Wayland Support: Enabled"
else
	@echo "Wayland Support: Disabled (wlroots not found)"
endif
else ifeq ($(PLATFORM),WIN32_PLATFORM)
	@echo "Windows Platform: Enabled"
else ifeq ($(PLATFORM),MACOS_PLATFORM)
	@echo "macOS Platform: Enabled"
endif
	@echo "============================="

# Dependencies
deps:
	@echo "=== Dependencies ==="
ifeq ($(PLATFORM),LINUX_PLATFORM)
	@echo "Checking Linux dependencies..."
	@echo "X11 libraries:"
	@echo "  - libx11-dev"
	@echo "  - libxrandr-dev"
	@echo "  - libxinerama-dev"
	@echo "  - libxfixes-dev"
	@echo "  - libxcursor-dev"
ifeq ($(shell pkg-config --exists wlroots 2>/dev/null && echo yes),yes)
	@echo "Wayland libraries:"
	@echo "  - libwayland-dev"
	@echo "  - libwlroots-dev"
else
	@echo "Wayland libraries: Not available"
endif
	@echo "Lua: $(if $(LUA_SOURCES),Available,Not available)"
else ifeq ($(PLATFORM),WIN32_PLATFORM)
	@echo "Windows dependencies:"
	@echo "  - MinGW-w64"
	@echo "  - Lua for Windows"
else ifeq ($(PLATFORM),MACOS_PLATFORM)
	@echo "macOS dependencies:"
	@echo "  - Xcode Command Line Tools"
	@echo "  - Lua (via Homebrew: brew install lua)"
endif
	@echo "==================="

# Help
help:
	@echo "=== SRDWM Makefile Help ==="
	@echo "Available targets:"
	@echo "  all          - Build the project (default)"
	@echo "  clean        - Remove build artifacts"
	@echo "  install      - Install to system (requires sudo)"
	@echo "  uninstall    - Remove from system (requires sudo)"
	@echo "  info         - Show build information"
	@echo "  platform-info - Show platform-specific information"
	@echo "  deps         - Show dependency information"
	@echo "  help         - Show this help"
	@echo ""
	@echo "Environment variables:"
	@echo "  CXX          - C++ compiler (default: g++)"
	@echo "  CXXFLAGS     - Additional compiler flags"
	@echo "  LIBS         - Additional libraries"
	@echo "========================"

.PHONY: all clean install uninstall info platform-info deps help