-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
51 lines (38 loc) · 1.3 KB
/
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
42
43
44
45
46
47
48
49
50
51
################################################################
# Builds all source files in the src directory
# It ignores all file paths that include an underscore
#
# debug - makes a debug build
# test - builds test files
# clean - removes build directory
SOURCE_DIR := src
BUILD_DIR := build
TEST_DIR := tests
COMPILER_SETTINGS := -Iinclude
LINKER_SETTINGS := -lcurses
#default#debug##################################################
SOURCES := $(shell find $(SOURCE_DIR) -name *.c -a ! -name _*.c)
OBJECTS := $(SOURCES:$(SOURCE_DIR)/%.c=$(BUILD_DIR)/%.o)
$(BUILD_DIR)/prog: $(OBJECTS)
$(CC) $(OBJECTS) -o $@ $(LINKER_SETTINGS)
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c
mkdir -p $(dir $@)
$(CC) -c $< -o $@ $(COMPILER_SETTINGS)
.PHONY: debug
debug: $(OBJECTS)
$(CC) -g $(OBJECTS) -o $(BUILD_DIR)/debug $(LINKER_SETTINGS)
#test###########################################################
TEST_SOURCES := $(shell find $(TEST_DIR) -name *.c)
FILTERED_OBJECTS := $(filter-out %main.o,$(OBJECTS))
.PHONY: test
test: $(FILTERED_OBJECTS)
$(foreach var,\
$(TEST_SOURCES),\
$(CC) \
-g $(var) $(FILTERED_OBJECTS) \
-o $(BUILD_DIR)/$(basename $(notdir $(var))) \
$(COMPILER_SETTINGS) $(LINKER_SETTINGS))
#clean##########################################################
.PHONY: clean
clean:
rm -r $(BUILD_DIR)