-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
73 lines (49 loc) · 1.13 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Project name
PROJECT := objviewer
# Directories
SRC := src
INCLUDE := include
LIB := lib
BUILD := build
BIN := bin
# Directories management
MKDIR := mkdir -pv
RM := rm -rfv
CP := cp -ruv
# Compiler
LINK := -ldl -lGL -lglfw
FLAGS = -Wall -Wextra
CCFLAGS = -std=c11 $(FLAGS)
CXXFLAGS = -std=c++11 $(FLAGS)
# Main target
TARGET := $(BIN)/$(PROJECT)
# Targets
.PHONY: release debug clean
release: FLAGS += -Os
release: $(TARGET)
debug: FLAGS += -ggdb3
debug: $(TARGET)
clean:
$(RM) $(BUILD) $(BIN)
# Directories creation
.PRECIOUS: $(BUILD)/ $(BUILD)%/ $(BIN)/
.SECONDEXPANSION:
$(BUILD)/:
$(MKDIR) $@
$(BUILD)%/:
$(MKDIR) $@
$(BIN)/:
$(MKDIR) $@
# C files
CCSOURCES := $(shell find $(SRC) -type f -name *.c)
CCOBJECTS := $(patsubst $(SRC)/%,$(BUILD)/%,$(CCSOURCES:.c=.o))
# CXX files
CXXSOURCES := $(shell find $(SRC) -type f -name *.cpp)
CXXOBJECTS := $(patsubst $(SRC)/%,$(BUILD)/%,$(CXXSOURCES:.cpp=.o))
# Compilation
$(TARGET): $(CCOBJECTS) $(CXXOBJECTS) | $$(@D)/
$(CXX) -o $@ $^ $(LINK)
$(BUILD)/%.o: $(SRC)/%.c | $$(@D)/
$(CC) $(CCFLAGS) -o $@ -c $<
$(BUILD)/%.o: $(SRC)/%.cpp | $$(@D)/
$(CXX) $(CXXFLAGS) -o $@ -c $<