-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
55 lines (39 loc) · 1.06 KB
/
Copy pathMakefile
File metadata and controls
55 lines (39 loc) · 1.06 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
# Compiler and flags
CC = cc
CFLAGS = -Wall -Wextra -Iinclude
# Directories
SRC_DIR = src
OBJ_DIR = obj
INCLUDE_DIR = include
SRC_FILES = draw.c init.c keyhooks.c pixel.c utils.c
SRCS = $(patsubst %, $(SRC_DIR)/%, $(SRC_FILES))
OBJS = $(patsubst %.c, $(OBJ_DIR)/%.o, $(SRC_FILES))
# Target library
LIB = libftascii.a
EXAMPLE = example
EXAMPLE_SRC = main.c
EXAMPLE_OBJ= $(OBJ_DIR)/main.o
# Create object directory if it doesn't exist
$(shell mkdir -p $(OBJ_DIR))
# Default target
all: $(LIB) $(EXAMPLE)
# Compile each source file into an object file
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
# Compile the example program object file
$(OBJ_DIR)/main.o: $(EXAMPLE_SRC)
$(CC) $(CFLAGS) -c $< -o $@
# Archive the object files into a static library
$(LIB): $(OBJS)
ar rcs $(LIB) $(OBJS)
# Link the example program
$(EXAMPLE): $(EXAMPLE_OBJ) $(LIB)
$(CC) $(CFLAGS) $(EXAMPLE_OBJ) -L. -lftascii -lm -o $(EXAMPLE)
lib: clean
$(MAKE) $(LIB)
# Clean up the build files
clean:
rm -f $(OBJ_DIR)/*.o $(LIB) $(EXAMPLE)
re: clean all
run: all
./$(EXAMPLE)