-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
86 lines (69 loc) · 1.97 KB
/
Makefile
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
# Compiler
CC = gcc
# Directories
SRC = ./src
INCLUDE = ./include
BIN = ./bin
BUILD = ./build
COMMANDS_DIR := $(SRC)/commands
HELPING_DIR := $(SRC)/helping
# Compiler flags
CFLAGS = -pthread -Wall -g3 -std=c99 -I$(INCLUDE)
# Source files in src/commands
COMMAND_SRCS := $(wildcard $(COMMANDS_DIR)/*.c)
# Object files for commands
COMMAND_OBJS := $(patsubst $(COMMANDS_DIR)/%.c,$(BUILD)/%.o,$(COMMAND_SRCS))
# Source files in src/helping
HELPING_SRCS := $(wildcard $(HELPING_DIR)/*.c)
# Object files for helping
HELPING_OBJS := $(patsubst $(HELPING_DIR)/%.c,$(BUILD)/%.o,$(HELPING_SRCS))
# Source files
SRCS := $(wildcard $(SRC)/*.c)
# Object files
OBJS := $(patsubst $(SRC)/%.c,$(BUILD)/%.o,$(SRCS))
# Add command object files to the list of object files
OBJS += $(COMMAND_OBJS)
# Add helping object files to the list of object files
OBJS += $(HELPING_OBJS)
# Executable name
TARGET = $(BIN)/mysh
# Create directories if they don't exist
.PHONY: directories
directories:
@mkdir -p $(BIN) $(BUILD)
# Rule to build object files from command source files
$(BUILD)/%.o: $(COMMANDS_DIR)/%.c | directories
$(CC) $(CFLAGS) -c -o $@ $<
# Rule to build object files from helping source files
$(BUILD)/%.o: $(HELPING_DIR)/%.c | directories
$(CC) $(CFLAGS) -c -o $@ $<
# Rule to build object files from source files
$(BUILD)/%.o: $(SRC)/%.c | directories
$(CC) $(CFLAGS) -c -o $@ $<
# Rule to build the executable
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) -o $@ $^
# Run the executable
.PHONY: run
run: $(TARGET)
./$(TARGET)
# Run valgrind on the executable
.PHONY: valgrind
valgrind: $(TARGET)
valgrind ./$(TARGET) --leak-check=full
# Clean rule
.PHONY: clean
clean:
rm -f $(BUILD)/*.o $(TARGET)
# All rule
.PHONY: all
all: $(TARGET)
# Help rule
.PHONY: help
help:
@echo "Available targets:"
@echo " all: Build all executables"
@echo " clean: Clean object files and executables"
@echo " help: Display this help message"
@echo " run: Run the executable"
@echo " valgrind: Run valgrind on the executable"