-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
82 lines (66 loc) · 1.66 KB
/
Makefile
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
# Host system detection
HOST_OS := $(shell uname -s)
TARGET_OS ?= native
# Cross-compilation settings for Windows target
MINGW_PREFIX = x86_64-w64-mingw32-
WINE ?= wine
# Compiler and flags setup
ifeq ($(TARGET_OS),windows)
CC = $(MINGW_PREFIX)gcc
TARGET = rlite.exe
PLATFORM_FLAGS = -D_WIN32 -D_WIN -DWIN32_LEAN_AND_MEAN
RM = rm -f
# Windows specific flags - order is important!
CFLAGS += -pthread $(PLATFORM_FLAGS)
LDFLAGS = -static
LIBS = -lmingw32 -lpthread -lwinpthread -static-libgcc -static-libstdc++ -lmsvcrt
else
CC = gcc
TARGET = rlite.bin
PLATFORM_FLAGS = -D_UNIX
RM = rm -f
CFLAGS += -pthread $(PLATFORM_FLAGS)
LIBS = -pthread
endif
# Common compiler flags
CFLAGS += -O3 -s
# Source files
SRC = main.c \
advFile/advFile.c \
advFile/fhandle.c \
threading/yarn.c \
qsort_mt.c \
roaring.c \
msort.c
# Header files
HEADERS = xxhash.h
# Object files
OBJ = $(SRC:.c=.o)
# Default target
all: platform_info $(TARGET)
# Display platform information
platform_info:
@echo "Host OS: $(HOST_OS)"
@echo "Target OS: $(TARGET_OS)"
@echo "Using compiler: $(CC)"
@echo "Using flags: $(CFLAGS)"
@echo "Using libs: $(LIBS)"
# Linking - note the order here is important
$(TARGET): $(OBJ)
$(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
# Compiling
%.o: %.c $(HEADERS)
$(CC) $(CFLAGS) -c $< -o $@
# Clean build files
clean:
$(RM) $(TARGET) $(OBJ)
# Clean and rebuild
rebuild: clean all
# Cross-compile for Windows
windows:
$(MAKE) TARGET_OS=windows
# Test Windows binary using Wine
test-windows: windows
$(WINE) ./$(TARGET)
# Phony targets
.PHONY: all clean rebuild platform_info windows test-windows