-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
110 lines (97 loc) · 2.94 KB
/
makefile
File metadata and controls
110 lines (97 loc) · 2.94 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#### PROJECT SETTINGS ####
# The name of the executable to be created
export BIN_NAME = beemon
# Compiler used
export CXX = g++
# Extension of source files used in the project
SRC_EXT = cpp
# Path to the source directory, relative to the makefile
SRC_PATH = src
# Set additional compiler flags
override CXXFLAGS := $(CXXFLAGS) -std=c++11 -Wall
# Addtional compiler flags for the debug build
debug: export CXXFLAGS += -g -D NDEBUG
# Add additional include paths
export INCLUDES = -I$(SRC_PATH)/
# Add additional libraries
export LIBS = -lwiringPi -lrt
# install path (bin/ is appended automatically
INSTALL_PREFIX = /usr/local
#### END PROJECT SETTINGS ####
# Generally should not need to edit below this line
# Build and output paths
release: export BUILD_PATH = build/release
release: export BIN_PATH := bin/release
debug: export BUILD_PATH := build/debug
debug: export BIN_PATH := bin/debug
# Find all source files in the source directory
SOURCES = $(shell find $(SRC_PATH)/ -name '*.$(SRC_EXT)')
# Set the object file names, with the root source directory stripped
# from the path
OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o)
# Set the dependency files that will be used to add header dependencies
DEPS = $(OBJECTS:.o=.d)
TFILE = $(dir $@).$(notdir $@)_time
STIME = date '+%s' > $(TFILE)
ETIME = read st < $(TFILE) ; \
$(RM) $(TFILE) ; \
st=$$((`date '+%s'` - $$st - 86400)) ; \
echo `date -u -d @$$st '+%H:%M:%S'`
# Standard, non-optimized release build
.PHONY: release
release: dirs
@echo "Beginning release build"
@$(STIME)
@$(MAKE) all --no-print-directory
@echo -n "Total build time: "
@$(ETIME)
# Debug build for gdb debugging
.PHONY: debug
debug: dirs
@echo "Beginning debug build"
@$(STIME)
@$(MAKE) all --no-print-directory
@echo -n "Total build time: "
@$(ETIME)
# Create the directories used in the build
.PHONY: dirs
dirs:
@echo "Creating directories"
@mkdir -p $(dir $(OBJECTS))
@mkdir -p $(BIN_PATH)
# Installs to the set path
.PHONY: install
install:
@echo "Installing to $(INSTALL_PREFIX)/bin"
@install -m 0755 $(BIN_NAME) $(INSTALL_PREFIX)/bin
# Removes all build files
.PHONY: clean
clean:
@echo "Deleting symlink to $(BIN_NAME)"
@$(RM) $(BIN_NAME)
@echo "Deleting directories"
@$(RM) -r build
@$(RM) -r bin
# Main rule, checks the executable file and symlinks to the output
all: $(BIN_PATH)/$(BIN_NAME)
@echo "Making symlink: $(BIN_NAME) -> $<"
@$(RM) $(BIN_NAME)
@ln -s $(BIN_PATH)/$(BIN_NAME) $(BIN_NAME)
# Build the executable file
$(BIN_PATH)/$(BIN_NAME): $(OBJECTS)
@echo "Linking: $@"
@$(STIME)
@$(CXX) $(OBJECTS) $(LIBS) -o $@
@echo -n "\t Link time: "
@$(ETIME)
# Add dependency files, if they exist
-include $(DEPS)
# Source file rules
# After the first compilation they will be joined with the rules from the
# dependency files to provide header dependencies
$(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT)
@echo "Compiling: $< -> $@"
@$(STIME)
@$(CXX) $(CXXFLAGS) $(INCLUDES) $(LIBS) -MMD -c $< -o $@
@echo -n "\t Compile time: "
@$(ETIME)