Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
121 lines (101 loc) · 3.05 KB
/
Copy pathMakefile
File metadata and controls
121 lines (101 loc) · 3.05 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
111
112
113
114
115
116
117
118
119
120
121
ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
RELEASE_DIR := $(ROOT_DIR)/build/release/
DEBUG_DIR := $(ROOT_DIR)/build/debug/
INSTALL_DIR := $(ROOT_DIR)/install
CMAKE := cmake $(ROOT_DIR)/source
FLAG := -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
# Enable the debug of the build or the Makefile itself
# Use: "make DEBUG_BUILD=1"
ifdef DEBUG_BUILD
CMAKE += --trace --debug-output
MAKE += --trace -d
VERBOSE := 1
else
MAKE += --no-print-directory
endif
# By default, suppress display of executed commands.
# Use: "make VERBOSE=1"
$(VERBOSE).SILENT:
.PHONY: all
all: install
.PHONY: debug
debug: install_debug
.PHONY: generate
generate:
echo "Creating directory $(RELEASE_DIR) and running cmake in Release mode"
mkdir -p $(RELEASE_DIR);
( cd $(RELEASE_DIR)$ ; $(CMAKE) -DCMAKE_BUILD_TYPE=Release $(FLAG) ) || exit $$?;
$(RELEASE_DIR)/Makefile: generate
.PHONY: build
build: $(RELEASE_DIR)/Makefile
echo "Compiling in Release mode..."
( $(MAKE) -C $(RELEASE_DIR) all ) || exit $$?;
.PHONY: install
install: build
echo "Installing Release..."
( $(MAKE) -C $(RELEASE_DIR) install ) || exit $$?;
.PHONY: generate_debug
generate_debug:
echo "Creating directory $(DEBUG_DIR) and running cmake in Debug mode"
mkdir -p $(DEBUG_DIR);
( cd $(DEBUG_DIR)$ ; $(CMAKE) -DCMAKE_BUILD_TYPE=Debug $(FLAG)) || exit $$?;
$(DEBUG_DIR)/Makefile: generate_debug
.PHONY: build_debug
build_debug: $(DEBUG_DIR)/Makefile
echo "Compiling in Debug mode..."
( $(MAKE) -C $(DEBUG_DIR) all ) || exit $$?;
.PHONY: install_debug
install_debug: build_debug
echo "Installing Debug..."
( $(MAKE) -C $(DEBUG_DIR) install ) || exit $$?;
.PHONY: clean
clean: clean_install
if [ -d $(RELEASE_DIR) ]; \
then \
echo "Cleaning compiled files"; \
( $(MAKE) -C $(RELEASE_DIR) clean ); \
echo "Deleting the Release build directory $(RELEASE_DIR)"; \
rm -rf $(RELEASE_DIR); \
else \
echo "The Release build directory does not exist"; \
fi;
.PHONY: clean_debug
clean_debug: clean_install
if [ -d $(DEBUG_DIR) ]; \
then \
echo "Cleaning compiled files"; \
( $(MAKE) -C $(DEBUG_DIR) clean ); \
echo "Deleting the Debug build directory $(DEBUG_DIR)"; \
rm -rf $(DEBUG_DIR); \
else \
echo "The Debug build directory does not exist"; \
fi;
.PHONY: clean_install
clean_install:
echo "Cleaning installed binaries and libraries"
rm -rf $(INSTALL_DIR)/
.PHONY : help
help:
echo "The following are some of the valid targets for this Makefile:"
echo ".. all (the default if no target is provided)"
echo ".. debug"
echo ".. generate"
echo ".. build"
echo ".. install"
echo ".. generate_debug"
echo ".. build_debug"
echo ".. install_debug"
echo ".. clean"
echo ".. clean_debug"
echo ".. clean_install"
if [ -d $(RELEASE_DIR) ]; \
then \
echo; echo "Targets of the CMake generated Makefile"; \
( $(MAKE) -C $(RELEASE_DIR) help ) || exit $$?; \
fi;
# Black magic: redirect all unknown rule to the CMake generated Makefile
Makefile:;
.PHONY: %
%: $(RELEASE_DIR)/Makefile
echo "Passing target '$@' to generated Makefile in $(RELEASE_DIR)"
( $(MAKE) -C $(RELEASE_DIR) $ ) || exit $$?;