-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmakefile
More file actions
121 lines (100 loc) · 2.89 KB
/
makefile
File metadata and controls
121 lines (100 loc) · 2.89 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
# Library name
LIBNAME = kolibri
VERSION = 0.1.0
# Compiler
CC = gcc-14
AR = ar
ARFLAGS = rcs
# Auto-detect platform
PLATFORM := $(shell uname -s)
# Platform-specific adjustments
ifeq ($(PLATFORM),Darwin)
# macOS
endif
ifeq ($(findstring MINGW,$(PLATFORM)),MINGW)
PLATFORM = mingw
endif
ifeq ($(findstring CYGWIN,$(PLATFORM)),CYGWIN)
PLATFORM = cygwin
endif
# Allow manual override: make PLATFORM_OVERRIDE=dc
ifdef PLATFORM_OVERRIDE
PLATFORM = $(PLATFORM_OVERRIDE)
endif
# Directories
SRCDIR = src
INCDIR = include
OBJDIR = obj/$(PLATFORM)
LIBDIR = lib
INSTALLDIR = /usr/local
# Output libraries
LIB_RELEASE = $(LIBDIR)/lib$(LIBNAME).a
LIB_DEBUG = $(LIBDIR)/lib$(LIBNAME)_debug.a
# Source files
SRCS = $(wildcard $(SRCDIR)/*.c)
# Object files
OBJS_RELEASE = $(SRCS:$(SRCDIR)/%.c=$(OBJDIR)/release/%.o)
OBJS_DEBUG = $(SRCS:$(SRCDIR)/%.c=$(OBJDIR)/debug/%.o)
# Compiler flags
CFLAGS_COMMON = -I$(INCDIR) -I./examples -Wall -Wextra -Wpedantic
CFLAGS_RELEASE = $(CFLAGS_COMMON) -O3 -DRELEASE
CFLAGS_DEBUG = $(CFLAGS_COMMON) -g3 -O0 -DDEBUG
.PHONY: all clean install uninstall release debug info
# Default target builds both versions
all: release debug
# Release build
release: $(LIB_RELEASE)
$(LIB_RELEASE): $(OBJS_RELEASE)
@mkdir -p $(LIBDIR)
$(AR) $(ARFLAGS) $@ $^
@echo "Built release library: $@"
$(OBJDIR)/release/%.o: $(SRCDIR)/%.c
@mkdir -p $(OBJDIR)/release
$(CC) $(CFLAGS_RELEASE) -c $< -o $@
# Debug build
debug: $(LIB_DEBUG)
$(LIB_DEBUG): $(OBJS_DEBUG)
@mkdir -p $(LIBDIR)
$(AR) $(ARFLAGS) $@ $^
@echo "Built debug library: $@"
$(OBJDIR)/debug/%.o: $(SRCDIR)/%.c
@mkdir -p $(OBJDIR)/debug
$(CC) $(CFLAGS_DEBUG) -c $< -o $@
# Clean build artifacts
clean:
rm -rf $(LIBDIR) $(OBJDIR)
# Install headers and libraries
install: all
@echo "Installing headers to $(INSTALLDIR)/include/$(LIBNAME)/"
install -d $(INSTALLDIR)/include/$(LIBNAME)
install -m 644 $(INCDIR)/*.h $(INSTALLDIR)/include/$(LIBNAME)/
@echo "Installing libraries to $(INSTALLDIR)/lib/"
install -d $(INSTALLDIR)/lib
install -m 644 $(LIB_RELEASE) $(INSTALLDIR)/lib/
install -m 644 $(LIB_DEBUG) $(INSTALLDIR)/lib/
@echo "Installation complete"
@echo ""
@echo "To use in your project:"
@echo " CFLAGS += -I$(INSTALLDIR)/include"
@echo " LDFLAGS += -L$(INSTALLDIR)/lib -l$(LIBNAME) # Release"
@echo " LDFLAGS += -L$(INSTALLDIR)/lib -l$(LIBNAME)_debug # Debug"
# Uninstall
uninstall:
rm -rf $(INSTALLDIR)/include/$(LIBNAME)
rm -f $(INSTALLDIR)/lib/lib$(LIBNAME).a
rm -f $(INSTALLDIR)/lib/lib$(LIBNAME)_debug.a
@echo "Uninstallation complete"
# Show build info
info:
@echo "Library: $(LIBNAME) v$(VERSION)"
@echo "Platform: $(PLATFORM)"
@echo "Compiler: $(CC)"
@echo "Sources: $(SRCS)"
@echo ""
@echo "Build outputs:"
@echo " Release: $(LIB_RELEASE)"
@echo " Debug: $(LIB_DEBUG)"
@echo ""
@echo "Object directories:"
@echo " Release: $(OBJDIR)/release/"
@echo " Debug: $(OBJDIR)/debug/"