-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
42 lines (30 loc) · 944 Bytes
/
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
# Define the compiler
CC = gcc
# Define compile-time flags
CFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -Werror -Wextra -g -Iinclude -O3
# Define the name of the executable
TARGET = vm
# Define source and object directories
SRCDIR = src
OBJDIR = obj
# Collect all source files
SOURCES = $(wildcard $(SRCDIR)/*.c)
# Convert the .c files to .o files in the object directory
OBJECTS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(SOURCES))
# The first rule is the one executed when no parameters are fed to the Makefile
all: $(TARGET)
# Rule for creating the object directory
$(OBJDIR):
mkdir -p $(OBJDIR)
# Rule for building the final executable - depends on all object files
$(TARGET): $(OBJECTS)
$(CC) $(CFLAGS) -o $(TARGET) $^
# To obtain object files
$(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
$(CC) $(CFLAGS) -c $< -o $@
# Clean up
clean:
rm -f $(TARGET) $(OBJECTS)
rm -rf $(OBJDIR)
# Phony targets
.PHONY: all clean