-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
99 lines (75 loc) · 3.16 KB
/
Makefile
File metadata and controls
99 lines (75 loc) · 3.16 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
# Makefile for Nutshell
CC = x86_64-w64-mingw32-gcc
WINDRES = x86_64-w64-mingw32-windres
VCPKG_LIB = $(HOME)/vcpkg/installed/x64-mingw-gcc-static/lib
VCPKG_INC = $(HOME)/vcpkg/installed/x64-mingw-gcc-static/include
CFLAGS = -std=c11 -Wall -Wextra -Werror -Wpedantic -Wshadow -Wformat=2 -Wconversion \
-Os -ffunction-sections -fdata-sections -flto \
-Isrc -Isrc/core -Isrc/config -Isrc/crypto -I$(VCPKG_INC) -Isrc/term -Isrc/ssh -Isrc/ui
LDFLAGS = -mwindows -Os -flto -Wl,--gc-sections -s \
-L$(VCPKG_LIB) -lssh2 -lssl -lcrypto -lzlib -lcrypt32 -lbcrypt \
-lws2_32 -lgdi32 -luser32 -lcomctl32 -ldwmapi -lwinhttp -lm
# Source directories
SRC_DIRS = src src/core src/config src/crypto src/term src/ssh src/ui
# Find all .c files in source directories
SRCS = $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
# Resources
RC_SRCS = src/ui/resource.rc src/ui/nutshell.rc
# Object files
OBJS = $(SRCS:.c=.o) $(RC_SRCS:.rc=.o)
# Build directory and target
BUILD_DIR = build/win
TARGET = $(BUILD_DIR)/nutshell.exe
# Test configuration (Native Linux)
TEST_CC = gcc
TEST_CFLAGS = -std=c11 -Wall -Wextra -g \
-Isrc -Isrc/core -Isrc/config -Isrc/crypto -Isrc/term -Isrc/ssh -Isrc/ui \
-D_TEST -Wno-unused-function
# Auto-detect libssh2 availability for test linking
HAS_LIBSSH2 := $(shell echo 'int main(){}' | gcc -xc - -lssh2 -lssl -lcrypto -o /dev/null 2>/dev/null && echo yes || echo no)
# Auto-detect OpenSSL availability (may be present even without libssh2)
HAS_OPENSSL := $(shell echo 'int main(){}' | gcc -xc - -lssl -lcrypto -o /dev/null 2>/dev/null && echo yes || echo no)
ifeq ($(HAS_LIBSSH2),yes)
TEST_LDFLAGS = -lssh2 -lssl -lcrypto -lm
else ifeq ($(HAS_OPENSSL),yes)
TEST_CFLAGS += -DNO_SSH_LIBS
TEST_LDFLAGS = -lssl -lcrypto -lm
else
TEST_CFLAGS += -DNO_SSH_LIBS
TEST_LDFLAGS = -lm
endif
# Exclude Windows-only UI files and main entry point from test build
NON_TEST_SRCS = src/main.c $(wildcard src/ui/*.c)
# Exclude SSH/knownhosts networking files when libssh2 is unavailable
ifeq ($(HAS_LIBSSH2),no)
NON_TEST_SRCS += src/term/ssh_session.c src/term/ssh_channel.c src/term/ssh_pty.c \
src/config/ssh_io.c src/term/knownhosts.c
NON_TEST_IMPL = tests/test_ssh.c tests/session.c tests/test_knownhosts.c tests/test_key_auth.c
else
NON_TEST_IMPL =
endif
# All test implementation files
TEST_IMPL_SRCS = $(filter-out $(NON_TEST_IMPL),$(wildcard tests/*.c))
# All source files, excluding non-test sources
APP_SRCS = $(filter-out $(NON_TEST_SRCS),$(SRCS))
TEST_SRCS = $(APP_SRCS) $(TEST_IMPL_SRCS)
TEST_TARGET = build/test_runner
.PHONY: all clean test lint debug release
all: $(TARGET)
release: $(TARGET)
upx --best --lzma $(TARGET)
$(TARGET): $(OBJS)
@mkdir -p $(dir $@)
$(CC) $(OBJS) -o $@ $(LDFLAGS)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
%.o: %.rc
$(WINDRES) -Isrc/ui $< $@
test:
@mkdir -p build
$(TEST_CC) $(TEST_CFLAGS) $(TEST_SRCS) -o $(TEST_TARGET) $(TEST_LDFLAGS)
./$(TEST_TARGET)
clean:
rm -f $(OBJS) $(TARGET) $(TEST_TARGET) *.o tests/*.o
lint:
cppcheck --enable=warning,style,performance,portability --std=c11 src/