-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
46 lines (34 loc) · 1.09 KB
/
Makefile
File metadata and controls
46 lines (34 loc) · 1.09 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
# Makefile for OpenGL Practice
# Created Feb 8, 2018
BUILD_DIR = obj
SRC_DIR = src
BIN_DIR = bin
CXX = g++ -std=c++14
CXXFLAGS = -Wall -O -g -MMD # -MMD generates dependencies
LIBFLAGS = -Ibuild/include lib/glad.c -lGLFW -lAssimp -lsfml-graphics -framework OpenGL -framework CoreFoundation
# compile all .cpp files in source directory & it's subdirectories
SOURCES = $(wildcard $(SRC_DIR)/*.cpp $(SRC_DIR)/*/*.cpp)
# .o files depend upon .cpp files with same names
OBJECTS = $(patsubst $(SRC_DIR)/%, $(BUILD_DIR)/%, $(SOURCES:.cpp=.o))
# .d file is list of dependencies for corresponding .cpp file
DEPS = ${OBJECTS:.o=.d}
TARGET = $(BIN_DIR)/opengl
### Set default make
.PHONY: default
default: $(TARGET)
### Link
# Note that the LIBFLAGS must come last
$(TARGET): $(OBJECTS)
@[ -d $(BIN_DIR) ] || mkdir -p $(BIN_DIR)
$(CXX) $(CXXFLAGS) $(OBJECTS) -o $(TARGET) $(LIBFLAGS)
### Compile
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
@[ -d $(dir $@) ] || mkdir -p $(dir $@)
$(CXX) -c -o $@ $< $(CXXFLAGS)
-include ${DEPS}
### Clean target
clean:
rm -rf $(BUILD_DIR)
### Run target
run:
@$(MAKE) && ./$(TARGET)