-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
173 lines (137 loc) · 5.27 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#
# Copyright (C) 2017-2023 Fredrik Öhrström
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
$(shell mkdir -p build)
define DQUOTE
"
endef
#' make editor quote matching happy.
SUPRE=
SUPOST=
ifneq ($(SUDO_USER),)
# Git has a security check to prevent the wrong user from running inside the git repository.
# When we run "sudo make install" this will create problems since git is running as root instead.
# Use SUPRE/SUPOST to use su to switch back to the user for the git commands.
SUPRE=su -c $(DQUOTE)
SUPOST=$(DQUOTE) $(SUDO_USER)
endif
ifneq ($(shell git status > /dev/null),)
COMMIT_HASH?=$(shell $(SUPRE) git log --pretty=format:'%H' -n 1 $(SUPOST))
TAG?=$(shell $(SUPRE) git describe --tags $(SUPOST))
BRANCH?=$(shell $(SUPRE) git rev-parse --abbrev-ref HEAD $(SUPOST))
CHANGES?=$(shell $(SUPRE) git status -s | grep -v '?? ' $(SUPOST))
else
COMMIT_HASH:=hash
TAG:=tag
BRANCH:=branch
CHANGES:=
endif
ifeq ($(COMMIT),$(TAG_COMMIT))
# Exactly on the tagged commit. The version is the tag!
VERSION:=$(TAG)
DEBVERSION:=$(TAG)
else
VERSION:=$(TAG)++
DEBVERSION:=$(TAG)++
endif
ifneq ($(strip $(CHANGES)),)
# There are changes, signify that with a +changes
VERSION:=$(VERSION) with uncommitted changes
COMMIT_HASH:=$(COMMIT_HASH) but with uncommitted changes
DEBVERSION:=$(DEBVERSION)l
endif
$(info Building $(VERSION))
$(shell echo "#define BEAK_VERSION \"$(VERSION)\"" > build/version.h.tmp)
$(shell echo "#define BEAK_COMMIT \"$(COMMIT_HASH)\"" >> build/version.h.tmp)
PREV_VERSION=$(shell cat -n build/version.h 2> /dev/null)
CURR_VERSION=$(shell cat -n build/version.h.tmp 2>/dev/null)
ifneq ($(PREV_VERSION),$(CURR_VERSION))
$(shell mv build/version.h.tmp build/version.h)
else
$(shell rm build/version.h.tmp)
endif
all: release
help:
@echo "Usage: make (release|debug|asan|clean|clean-all)"
@echo " if you have both linux64, winapi64 and arm32 configured builds,"
@echo " then add linux64, winapi64 or arm32 to build only for that particular host."
@echo "E.g.: make debug winapi64"
@echo "E.g.: make asan linux64"
@echo " make release linux64"
BUILDDIRS:=$(dir $(realpath $(wildcard build/*/spec.mk)))
ifeq (,$(BUILDDIRS))
$(error Run configure first!)
endif
VERBOSE?=@
ifeq (winapi64,$(findstring winapi64,$(MAKECMDGOALS)))
BUILDDIRS:=$(filter %x86_64-w64-mingw32%,$(BUILDDIRS))
endif
ifeq (linux64,$(findstring linux64,$(MAKECMDGOALS)))
BUILDDIRS:=$(filter %x86_64-pc-linux-gnu%,$(BUILDDIRS))
endif
ifeq (osx64,$(findstring osx64,$(MAKECMDGOALS)))
BUILDDIRS:=$(filter %x86_64-apple-darwin%,$(BUILDDIRS))
endif
ifeq (arm32,$(findstring arm32,$(MAKECMDGOALS)))
BUILDDIRS:=$(filter %arm-unknown-linux-gnueabihf%,$(BUILDDIRS))
endif
release:
@echo Building release for $(words $(BUILDDIRS)) host\(s\).
@for x in $(BUILDDIRS); do echo; echo Bulding $$(basename $$x) ; $(MAKE) --no-print-directory -C $$x release ; done
debug:
@echo Building debug for $(words $(BUILDDIRS)) host\(s\).
@for x in $(BUILDDIRS); do echo; echo Bulding $$(basename $$x) ; $(MAKE) --no-print-directory -C $$x debug ; done
asan:
@echo Building asan for $(words $(BUILDDIRS)) host\(s\).
@for x in $(BUILDDIRS); do echo; echo Bulding $$(basename $$x) ; $(MAKE) --no-print-directory -C $$x asan ; done
lcov:
@echo Generating code coverage $(words $(BUILDDIRS)) host\(s\).
@for x in $(BUILDDIRS); do echo; echo Bulding $$(basename $$x) ; $(MAKE) --no-print-directory -C $$x debug lcov ; done
test: testr
testr:
@echo Running tests on release
@for x in $(BUILDDIRS); do echo; ./test.sh $$x/release $(TEST) ; done
testd:
@echo Running tests on debug
@for x in $(BUILDDIRS); do echo; ./test.sh $$x/debug $(TEST) ; done
testa:
@echo Running tests on asan
@for x in $(BUILDDIRS); do echo; ./test.sh $$x/asan $(TEST) ; done
clean:
@echo Removing release, debug and asan builds
@for x in $(BUILDDIRS); do echo; rm -rf $$x/release $$x/debug $$x/asan $$x/generated_autocomplete.h; done
clean-all:
@echo Removing configuration and artifacts
$(VERBOSE)rm -rf $(BUILDDIRS)
DESTDIR?=/usr/local
install:
if [ -x build/x86_64-pc-linux-gnu/release/beak-media ]; then \
install -Dm 755 -s build/x86_64-pc-linux-gnu/release/beak-media $(DESTDIR)/bin/beak-media ; \
fi
install -Dm 755 -s build/x86_64-pc-linux-gnu/release/beak $(DESTDIR)/bin/beak
install -Dm 644 doc/beak.1 $(DESTDIR)/man/man1/beak.1
install -Dm 644 ./scripts/autocompletion_for_beak.sh /etc/bash_completion.d/beak
uninstall:
rm -f $(DESTDIR)/bin/beak-media
rm -f $(DESTDIR)/bin/beak
rm -f /etc/bash_completion.d/beak
rm -f $(DESTDIR)/man/man1/beak.1
linux64:
arm32:
winapi64:
.PHONY: all release debug asan test test_release test_debug clean clean-all help linux64 winapi64 arm32
server:
(cd sdf; node ../templates/server.js)