-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
·38 lines (30 loc) · 989 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
CC = gcc
CFLAGS = -Wall -Wextra -Werror -I$(INCDIR) `pkg-config --cflags glib-2.0 libxml-2.0`
LIBS = `pkg-config --libs glib-2.0 libxml-2.0` -lm
BINDIR = bin
OBJDIR = obj
SRCDIR = src
INCDIR = include
TARGET = $(BINDIR)/main
# Recursively find all .c files in the src directory and its subdirectories
SOURCES := $(shell find $(SRCDIR) -type f -name '*.c')
# Convert each .c file path to a corresponding .o file path
OBJECTS := $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SOURCES))
all: $(BINDIR) $(OBJDIR) $(TARGET)
# Create the bin directory if it does not exist
$(BINDIR):
mkdir -p $(BINDIR)
# Create the obj directory if it does not exist
$(OBJDIR):
mkdir -p $(OBJDIR)
# Compile each source file into an object file
$(OBJDIR)/%.o: $(SRCDIR)/%.c
@mkdir -p $(dir $(OBJDIR)/$*.o)
$(CC) $(CFLAGS) -c $< -o $@
# Create the executable
$(TARGET): $(OBJECTS)
$(CC) $(CFLAGS) $^ -o $@ $(LIBS)
# Clean up the obj and bin directories
clean:
rm -rf $(OBJDIR) $(BINDIR)
.PHONY: all clean