-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmakefile
More file actions
47 lines (38 loc) · 1.05 KB
/
makefile
File metadata and controls
47 lines (38 loc) · 1.05 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
CC = gcc
CFLAGS = -g -Wall -Wextra -Werror
LDFLAGS = -lcurl -ljansson
# Directories
SRC_DIR = src
OBJ_DIR = obj
TARGET = kpm
# Find all subdirectories of SRC_DIR
INCLUDE_DIRS := $(shell find $(SRC_DIR) -type d)
INCLUDE_FLAGS := $(addprefix -I, $(INCLUDE_DIRS))
CFLAGS += $(INCLUDE_FLAGS)
# Generate the list of source files recursively
SRCS := $(shell find $(SRC_DIR) -name '*.c')
OBJS := $(SRCS:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
# Default rule (build with DEBUG defined)
all: $(TARGET)
# Build without DEBUG defined
build: CFLAGS := $(filter-out -DDEBUG,$(CFLAGS))
build: $(TARGET)
mkdir -p "build"
cp $(TARGET) "build"
# Create object directory structure
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
mkdir -p $(@D)
$(CC) $(CFLAGS) -c $< -o $@
# Link the program
$(TARGET): $(OBJS)
$(CC) $(OBJS) $(LDFLAGS) -o $@
run: $(TARGET)
mkdir -p "tests"
(cd tests && ../$(TARGET) init)
run-d:
mkdir -p "tests"
(cd tests && valgrind --track-origins=yes --leak-check=full ../$(TARGET) init)
# Clean up build files
clean:
rm -rf $(OBJ_DIR) $(TARGET) build
.PHONY: all build run clean