-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
138 lines (108 loc) · 4.71 KB
/
Makefile
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Path to this Makefile.
self := $(abspath $(lastword $(MAKEFILE_LIST)))
# Directory containing header files.
headers := include
# Directory containing source files.
sources := src
# Build directory.
build := build
# Directory containing release build files.
release := $(build)/release
# Directory containing debug build files.
debug := $(build)/debug
# Directory containing output binaries.
binaries := bin
# The filepath of the application.
app := $(binaries)/$(shell cat "$(sources)/app/name.txt")
# Path to the `alloinit` project initializer.
alloinit := utils/alloinit
# Flags for CMake builds.
# Utilizing CMake's parallel build options.
# Recommended: -j <number of processor cores + 1>
cmake_build_flags := -- -j5
# Flags for CMake configuration.
cmake_conf_flags := -Wno-deprecated -DBUILD_EXAMPLES=0
# Replace "help" in order to set the default recipe. For example, setting this
# line to `default: run` will run the project when `make` is called without
# arguments, instead of printing a help text.
.PHONY: default
default: help
###### Compiling and Running ######
# Compile and run a release build of the application. Installs dependencies and
# configures CMake if necessary.
.PHONY: run
run: build-release # Compile and run the application. <---
'$(app)'
# Compile and debug the application using GDB. Installs dependencies and
# configures CMake if necessary.
.PHONY: debug
debug: build-debug # Compile and debug the application with GDB.
gdb -ex run '$(app)'
# Compile a release build. Ensures that CMake is configured.
.PHONY: build-release
build-release: configure # Compile a release build.
cmake --build '$(release)' $(cmake_build_flags)
# Compile a debug build. Ensures that CMake is configured.
.PHONY: build-debug
build-debug: configure # Compile a debug build.
cmake --build '$(debug)' $(cmake_build_flags)
build: build-release # Alias for `build-release`.
# Check if any headers or source files have been added or removed to the
# project. If so, reconfigure CMake.
.PHONY: configure
configure: install-deps .sources # Ensure that CMake has been configured.
if ! diff .sources.tmp .sources ; then \
mkdir -p '$(release)' '$(debug)' ; \
cmake -B'$(release)' -DCMAKE_BUILD_TYPE=Release $(cmake_conf_flags) ; \
cmake -B'$(debug)' -DCMAKE_BUILD_TYPE=Debug $(cmake_conf_flags) ; fi
rm .sources.tmp
.PHONY: conf
conf: configure # Alias for `configure`.
# A listing of headers and sources in the project. Moves any existing `.sources`
# file to `.sources.tmp`.
.sources: .sources.tmp
find '$(headers)' '$(sources)' -type f \
-name '*.h' -o -name '*.hpp' -o -name '*.c' -o -name '*.cpp' \
| sort > .sources
# Move an existing `.sources` file to `.sources.tmp`. Used to compare the header
# and source files that existed during the previous configuration run to the
# header and source files that exist now.
.sources.tmp:
touch .sources && mv .sources .sources.tmp
###### Submodule Management ######
# Install Allolib and its extensions if they are not already installed. Not
# compatible with `alloinit`'s shared (`-S`) mode.
.PHONY: install-deps
install-deps: # Install Allolib and its extensions.
if [ -z "$$(cat .gitmodules)" ] ; then '$(alloinit)' -r . ; \
else '$(alloinit)' -S -l . -L ; fi
# Update Allolib and its extensions if they are not already installed.
# Otherwise, install them. Not compatible with `alloinit`'s shared (`-S`) mode.
.PHONY: update-deps
update-deps: # Update Alloinit and its extensions.
'$(alloinit)' -u .
# Reset Allolib and its extensions completely. Removes all generated files and
# reinstalls the libraries. Not compatible with `alloinit`'s shared (`-S`) mode.
.PHONY: reset-deps
reset-deps: distclean install-deps # Reset Allolib and its extensions.
###### Cleaning ######
# Clean up build artifacts. Removes files generated by CMake as well as
# `alloinit` temporary files and `.sources.tmp`, in case they were not removed
# automatically.
.PHONY: clean
clean: # Clean up build artifacts. <---
rm -rf '$(build)' '$(binaries)' *.alloinit.tmp .sources.tmp
# Removes all files that are automatically generated, including the contents of
# the Allolib and Allolib extensions submodules.
.PHONY: distclean
distclean: clean # Completely remove all generated files.
rm -rf allolib/ al_ext/ .sources
###### Documentation ######
# Generates a help text from this Makefile. Recipes with comments on the same
# line as the recipe are printed in alphabetical order, with the comment printed
# after the recipe name following a tab. Any tab characters preceding the hash
# character are preservd, in order to allow manual alignment.
.PHONY: help
help: # Generate a list of targets.
@cat '$(self)' | grep '^[[:alnum:]_-]*:[[:space:][:alnum:]_-]*#' | \
sed 's/^\([[:alnum:]_-]*\):[ [:alnum:]_-]*\(\t*\)/\1\t\2/' | sort