-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
40 lines (30 loc) · 732 Bytes
/
Makefile
File metadata and controls
40 lines (30 loc) · 732 Bytes
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
# Compiler and flags
CC := gcc
CFLAGS := -fPIC -Wall -Wextra -O2
LDFLAGS := -shared
# Directories
SRC_DIR := src
BUILD_DIR := build
# Source and object files
SRCS := $(wildcard $(SRC_DIR)/*.c)
OBJS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRCS))
# Targets
TARGET_SO := $(BUILD_DIR)/libacl.so
TARGET_A := $(BUILD_DIR)/libacl.a
# Default target builds both
all: $(TARGET_SO) $(TARGET_A)
# Shared library
$(TARGET_SO): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $^
# Static library
$(TARGET_A): $(OBJS)
ar rcs $@ $^
# Compile .c to .o
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Ensure build directory exists
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
clean:
rm -rf $(BUILD_DIR)
.PHONY: all clean