Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
61 lines (48 loc) · 1.45 KB
/
Copy pathMakefile
File metadata and controls
61 lines (48 loc) · 1.45 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
# This is a makefile for compiling your whole project.
# It is used to compile all the source files in the src directory and link them together.
# It is also used to clean up the build directory and remove all the object files and the executable.
# The makefile is used to compile the project using the gcc compiler.
# Things to explore:
# - Linux, MacOS, WSL for Windows
# - Makefile variables
# - Makefile rules
# - Makefile targets
# - Makefile dependencies
# - Makefile commands
# NOTE: YOU MAY CHANGE THIS MAKEFILE TO YOUR NEED
TARGET := bin/main
SRC_DIR := src
BUILD_DIR := build
SRC_FILES := $(shell find $(SRC_DIR) -name "*.c")
OBJ_FILES := $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRC_FILES))
# Compiler and Flags
CC := gcc
CFLAGS := -Wall -Wextra -I$(SRC_DIR) -I$(SRC_DIR)/adt/header
DEBUG_FLAGS := -g
# Define phony targets
.PHONY: all debug run clean clean-bin clean-all
# Build the program
all: $(TARGET)
# link the final executable
$(TARGET): $(OBJ_FILES)
@mkdir -p $(dir $@)
$(CC) $(OBJ_FILES) -o $@
# compile each .c into .o under build/
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(DEBUG_FLAGS) -c $< -o $@
# Debug build
debug: CFLAGS += -DDEBUG
debug: all
# Run the program
run: all
@./$(TARGET)
# Clean build files
clean:
@echo "Cleaning build files..."
rm -rf $(BUILD_DIR) $(TARGET)
# Clean binary file
clean-bin:
@echo "Removing bin directory..."
rm -rf bin
clean-all: clean clean-bin