-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
91 lines (69 loc) · 2.02 KB
/
Copy pathMakefile
File metadata and controls
91 lines (69 loc) · 2.02 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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# define the compiler to use
CXX = g++
CC = gcc
LD = $(CXX)
# define any compile-time flags
CXXFLAGS = -Wfatal-errors -Wall -Wextra -Wconversion -Wshadow
CFLAGS = $(CXXFLAGS)
LFLAGS = $(CXXFLAGS)
# Final binary
BIN = main
# define output directory
OUTPUT = bin
# define source directory
SRC = src
# define include directory
INCLUDE = include
# define lib directory
#LIB = lib
# define object directory
OBJ = build
LIBRARIES = -lglfw -lGL -lX11 -lpthread -lXrandr -lXi -ldl
SOURCEDIRS := $(shell find $(SRC) -type d)
INCLUDEDIRS := $(shell find $(INCLUDE) -type d)
#LIBDIRS := $(shell find $(LIB) -type d)
# define any directories containing header files other than /usr/include
INCLUDES := $(patsubst %,-I%, $(INCLUDEDIRS:%/=%))
# define the local libs
#LIBS := $(patsubst %,-L%, $(LIBDIRS:%/=%))
# define the source files
C_SOURCES := $(wildcard $(patsubst %,%/*.c, $(SOURCEDIRS)))
CPP_SOURCES := $(wildcard $(patsubst %,%/*.cpp, $(SOURCEDIRS)))
# define the object files
C_OBJECTS := $(C_SOURCES:$(SRC)/%.c=$(OBJ)/%.o)
CPP_OBJECTS := $(CPP_SOURCES:$(SRC)/%.cpp=$(OBJ)/%.o)
# define the dependency files
C_DEPS := $(C_OBJECTS:%.o=%.d)
CPP_DEPS := $(CPP_OBJECTS:%.o=%.d)
# define some utilities
RM = rm -f
RMD = rm -rf
MD = mkdir -p
#
# Makefile targets start from here
#
# Default target named after the binary.
.SILENT:
$(BIN) : $(OUTPUT)/$(BIN)
# Actual target of the binary - depends on all .o files.
$(OUTPUT)/$(BIN) : $(C_OBJECTS) $(CPP_OBJECTS)
$(MD) $(@D)
@echo "Linking"
$(LD) $(LFLAGS) $(INCLUDES) -o $@ $^ $(LIBS) $(LIBRARIES)
@echo "Done"
# Include all .d files
-include $(C_DEPS) $(CPP_DEPS)
$(C_OBJECTS):
$(eval SOURCE = $(patsubst $(OBJ)/%.o,$(SRC)/%.c,$@))
$(MD) $(@D)
@echo "Compiling $(SOURCE)"
$(CC) $(CFLAGS) $(INCLUDES) -MMD -c $(SOURCE) -o $@
$(CPP_OBJECTS):
$(eval SOURCE = $(patsubst $(OBJ)/%.o,$(SRC)/%.cpp,$@))
$(MD) $(@D)
@echo "Compiling $(SOURCE)"
$(CXX) $(CXXFLAGS) $(INCLUDES) -MMD -c $(SOURCE) -o $@
.PHONY: clean
clean:
@echo "Removing $(OUTPUT) $(OBJ)"
$(RMD) $(OUTPUT) $(OBJ)