-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
37 lines (27 loc) · 867 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
CC := gcc
C_WARNINGS := -Wall -Wpedantic -Wextra
C_WARNINGS_TESTS := -Wall -Wextra
C_FLAGS := $(C_WARNINGS) -std=c11
C_FLAGS_TESTS := $(C_WARNINGS_TESTS) -std=c11
C_LIBS := -lncurses -lm
BUILD_DIR := ./build
TEST_DIR := ./tests
SRC_DIR := src
# name of the executable
OUTPUT := cellulose
TEST_OUTPUT := cellulose_test
# find all of the c files
C_FILES := $(shell find $(SRC_DIR) -not -name "main.c" -and -name '*.c' )
# append .o to all of the files
OBJ_FILES := $(C_FILES:%=$(BUILD_DIR)/%.o)
all: $(BUILD_DIR)/$(OUTPUT)
test: $(TEST_DIR)/$(TEST_OUTPUT)
$(TEST_DIR)/$(TEST_OUTPUT): $(OBJ_FILES) tests/test.c
$(CC) $(C_FLAGS_TESTS) -o $@ $^ $(C_LIBS) -g
$(BUILD_DIR)/$(OUTPUT): $(OBJ_FILES) src/main.c
$(CC) $(C_FLAGS) -o $@ $^ $(C_LIBS) -g
$(BUILD_DIR)/%.c.o: %.c
mkdir -p $(dir $@)
$(CC) $(C_FLAGS) -c $< -o $@ -g
clean:
rm -r $(BUILD_DIR)/$(SRC_DIR)