-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
95 lines (75 loc) · 2.45 KB
/
Makefile
File metadata and controls
95 lines (75 loc) · 2.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
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
87
88
89
90
91
92
93
94
95
# Makefile for jsh project
# Compiler and compiler flags
CC = gcc
CFLAGS = -Wall -g
INCLUDES = -I include
LIBRARY = -lncurses -lreadline -lm
# Valgrind options
VALGRIND = valgrind
VFLAGS = --leak-check=full --show-leak-kinds=all --track-origins=yes -s
# Code formatting tool
CLANG_FORMAT = clang-format
FORMAT_FLAGS = -i
# Project structure
SRCDIR = src
BUILTINDIR = $(SRCDIR)/builtins
UTILSDIR = $(SRCDIR)/utils
PARSERDIR = $(SRCDIR)/parser
RUNDIR = $(SRCDIR)/run
TESTDIR = tests
BUILTINTESTDIR = $(TESTDIR)/builtins
UTILSTESTDIR = $(TESTDIR)/utils
PARSERTESTDIR = $(TESTDIR)/parser
OBJDIR = obj
BINDIR = bin
# Source, object, and test files
SOURCES = $(wildcard $(SRCDIR)/*.c) $(wildcard $(BUILTINDIR)/*.c) $(wildcard $(UTILSDIR)/*.c) $(wildcard $(PARSERDIR)/*.c) $(wildcard $(RUNDIR)/*.c)
APP_SOURCES = $(filter-out $(SRCDIR)/main.c, $(SOURCES))
APP_OBJECTS = $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(APP_SOURCES))
TEST_SOURCES = $(wildcard $(TESTDIR)/*.c) $(wildcard $(BUILTINTESTDIR)/*.c) $(wildcard $(UTILSTESTDIR)/*.c) $(wildcard $(PARSERTESTDIR)/*.c)
TEST_OBJECTS = $(APP_OBJECTS) $(patsubst $(TESTDIR)/%.c,$(OBJDIR)/%.o,$(TEST_SOURCES))
# Executable names
EXECUTABLE = $(BINDIR)/jsh
COPY_EXECUTABLE = jsh
TEST_EXECUTABLE = $(BINDIR)/test_main
# Default target
all: $(EXECUTABLE) $(COPY_EXECUTABLE)
# Linking the executable
$(EXECUTABLE): $(APP_OBJECTS) $(OBJDIR)/main.o
@mkdir -p $(BINDIR)
$(CC) $(CFLAGS) $(INCLUDES) $^ -o $@ $(LIBRARY)
$(COPY_EXECUTABLE): $(EXECUTABLE)
cp $(EXECUTABLE) $(COPY_EXECUTABLE)
# Compiling source files
$(OBJDIR)/%.o: $(SRCDIR)/%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ $(LIBRARY)
# Compiling test source files
$(OBJDIR)/%.o: $(TESTDIR)/%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ $(LIBRARY)
# Compile the test executable
$(TEST_EXECUTABLE): $(TEST_OBJECTS)
@mkdir -p $(BINDIR)
$(CC) $(CFLAGS) $(INCLUDES) $^ -o $@ $(LIBRARY)
# Running tests with Valgrind
test: $(TEST_EXECUTABLE)
@echo "Running tests with Valgrind"
$(VALGRIND) $(VFLAGS) ./$(TEST_EXECUTABLE)
@echo "Tests completed"
# Run the executable
run: $(EXECUTABLE)
./$(EXECUTABLE)
# Code formatting
format:
$(CLANG_FORMAT) $(FORMAT_FLAGS) $(SOURCES) $(wildcard include/*.h)
# Check code formatting
check-format:
$(CLANG_FORMAT) --dry-run --Werror $(SOURCES) $(wildcard include/*.h)
# Cleaning up
clean:
rm -rf $(OBJDIR) $(BINDIR) $(COPY_EXECUTABLE)
gdb: $(EXECUTABLE)
gdb $(EXECUTABLE)
# Phony targets
.PHONY: all clean test format run