-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
30 lines (23 loc) · 962 Bytes
/
makefile
File metadata and controls
30 lines (23 loc) · 962 Bytes
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
PROG = bin/exe # The name of the program
CC = gcc # Compilator
# Necessary Flags
FLAGS = -Wall -Wextra -g -Ilib # -Ilib looks for headers in the lib/ directory; -Wall and -Wextra give warnings
LIBS = -lncursesw # Necessay libraries
# Source files and objects
SRC = $(wildcard src/*.c) # Looks for all the files .c
OBJ = $(patsubst src/%.c, build/%.o, $(SRC)) # Creates .o files for each .c and puts it into the build/
all: $(PROG) # Main Rule
# Link all .o files into the final executable
$(PROG): $(OBJ)
@mkdir -p bin # Creates bin/ directory if it doesn't exist
$(CC) $(FLAGS) $(OBJ) -o $(PROG) $(LIBS)
# Compile each .c file into its corresponding .o
build/%.o: src/%.c
@mkdir -p build # Create build/ if it doesn't exist
$(CC) $(FLAGS) -c $< -o $@
# Clean rule (to delete objects and executable)
clean:
rm -f build/*.o $(PROG)
# Run rule: compile and execute the program
run: all
./$(PROG)