-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile-general
More file actions
96 lines (79 loc) · 2.42 KB
/
Copy pathMakefile-general
File metadata and controls
96 lines (79 loc) · 2.42 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
92
93
94
95
96
#=============================================================================
# Makefile-general: General-purpose C++ makefile rules.
#
# Makefiles should define the following variables before including this file:
# Directories:
# SRC_DIRS = source code directories
# BUILD_DIR = intermediate file directory
# Compiler/linker options:
# CXX = C++ compiler
# CXXFLAGS = C++ compiler options
# LDFLAGS = linker options
# LIBS = libraries
# Files:
# OBJS = object files
# OUT = output file
#
# Created by Mike Danylchuk
#=============================================================================
# Disable implicit suffix rules.
.SUFFIXES:
# Set search path.
vpath
vpath %.cpp $(SRC_DIRS)
vpath %.d $(BUILD_DIR)
vpath %.o $(BUILD_DIR)
# Add build path to object filenames.
BUILD_OBJS = $(OBJS:%.o=$(BUILD_DIR)/%.o)
# Dependencies are updated automatically, so only include them when necessary.
USE_DEPENDENCIES = unknown
ifeq ($(USE_DEPENDENCIES),unknown)
.DEFAULT : usedeps
.PHONY : usedeps
usedeps : dirs
@$(MAKE) USE_DEPENDENCIES=yes --no-print-directory
.PHONY : nodeps
nodeps : dirs
@$(MAKE) USE_DEPENDENCIES=no --no-print-directory
else
#-----------------------------------------------------------------------------
# Rules
#-----------------------------------------------------------------------------
# Default goal - build the output file.
$(OUT) : $(BUILD_OBJS)
$(CXX) -o $@ $(LDFLAGS) $^ $(LIBS)
# Compile a C++ file.
$(BUILD_DIR)/%.o : %.cpp
$(CXX) -c $(CXXFLAGS) -o $@ $<
# Generate dependencies from a C++ file.
$(BUILD_DIR)/%.d : %.cpp
@echo Generating dependencies for $(notdir $<)
@echo $(@:%.d=%.o) $@ : \\ > $@
@$(SHELL) -ec '$(CXX) -MM $(CXXFLAGS) $< | \
sed -e '\''s/.*://'\'' >> $@'
# Include dependency files.
ifeq ($(USE_DEPENDENCIES),yes)
-include $(BUILD_OBJS:%.o=%.d)
endif
endif
#-----------------------------------------------------------------------------
# Maintenance
#-----------------------------------------------------------------------------
.PHONY : dirs
dirs :
@-mkdir -p $(BUILD_DIR)
@-mkdir -p $(dir $(OUT))
.PHONY : clean
clean : clean-objs clean-deps
.PHONY : clean-objs
clean-objs :
-rm -f $(BUILD_DIR)/*.o
.PHONY : clean-deps
clean-deps :
-rm -f $(BUILD_DIR)/*.d
.PHONY : clean-out
clean-out :
-rm -f $(OUT)
#-----------------------------------------------------------------------------
# End
#-----------------------------------------------------------------------------