-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
41 lines (31 loc) · 988 Bytes
/
Copy pathMakefile
File metadata and controls
41 lines (31 loc) · 988 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
41
# Makefile for linux-system-monitor
# Targets:
# make -> build the binary at build/sysmon
# make clean -> remove build artifacts
# make run -> build (if needed) and run the binary
CC := gcc
STD := -std=c17
WARN := -Wall -Wextra -Werror
CFLAGS := $(STD) $(WARN) -g -Iinclude
LDFLAGS :=
BUILD_DIR := build
TARGET := $(BUILD_DIR)/sysmon
# Source files: main.c plus every .c file in modules/
SRCS := src/main.c $(wildcard modules/*.c)
# Turn src/main.c -> build/src/main.o, modules/sysinfo.c -> build/modules/sysinfo.o
OBJS := $(patsubst %.c,$(BUILD_DIR)/%.o,$(SRCS))
.PHONY: all clean run
all: $(TARGET)
$(TARGET): $(OBJS)
@mkdir -p $(dir $@)
$(CC) $(OBJS) -o $(TARGET) $(LDFLAGS)
@echo "Build complete: $(TARGET)"
# Pattern rule: how to build any build/<path>.o from its matching <path>.c
$(BUILD_DIR)/%.o: %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
run: all
./$(TARGET)
clean:
rm -rf $(BUILD_DIR)
@echo "Cleaned build artifacts"