-
Notifications
You must be signed in to change notification settings - Fork 33
/
Makefile
159 lines (119 loc) · 4.37 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
# Makefile for fscryptctl
#
# Copyright 2017, 2020 Google LLC
#
# Authors: Joe Richey ([email protected]),
# Eric Biggers ([email protected])
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
##############################################################################
# Makefile options. These can be overridden on the command line,
# e.g. make PREFIX=/usr or PREFIX=/usr make.
# Installation path prefix
PREFIX ?= /usr/local
# Directory where the binary gets installed
BINDIR ?= $(PREFIX)/bin
# Direectory where the man page gets installed
MANDIR ?= $(PREFIX)/share/man
# C compiler flags
CFLAGS ?= -O2 -Wall
# C preprocessor flags
CPPFLAGS ?=
# Linker flags
LDFLAGS ?=
# Pass the version to the command line program (pulled from tags).
VERSION ?= $(shell git describe --tags 2>/dev/null)
override CPPFLAGS += $(if $(VERSION),-DVERSION="\"$(VERSION)\"")
##############################################################################
# Build the binary
SRC := $(wildcard *.c)
OBJ := $(SRC:.c=.o)
HDRS := $(wildcard *.h)
fscryptctl: $(OBJ)
$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $+
$(OBJ): %.o: %.c $(HDRS)
$(CC) -o $@ -c $(CPPFLAGS) $(CFLAGS) $<
##############################################################################
# Build the manual page
fscryptctl.1: fscryptctl.1.md
pandoc -s -t man $+ > $@
##############################################################################
# Don't format fscrypt_uapi.h, so that it stays identical to the kernel version.
FILES_TO_FORMAT := $(filter-out fscrypt_uapi.h, $(SRC) $(HDRS))
.PHONY: format format-check
format:
clang-format -i -style=Google $(FILES_TO_FORMAT)
format-check:
@clang-format -i -style=Google -output-replacements-xml \
$(FILES_TO_FORMAT) \
| grep "<replacement " \
| ./input_fail.py "Incorrectly formatted C files. Run \"make format\"."
##############################################################################
# Testing targets
# The 'test' target requires that $(TEST_DIR) point to a directory on a
# filesystem that supports encryption.
#
# 'test-setup' sets up the default TEST_DIR to point to a directory on a
# temporary ext4 filesystem on a loopback device. 'test-teardown' cleans up
# afterwards. Note that both of these use 'sudo'.
#
# 'test-all' runs 'test-setup', 'test', and 'test-teardown'.
TEST_IMAGE ?= /tmp/fscryptctl-test-image
TEST_DIR ?= /tmp/fscryptctl-test-dir
.PHONY: test test-setup test-teardown test-all
test: fscryptctl
@if [ ! -e "$(TEST_DIR)" ]; then \
echo 1>&2 "Directory $(TEST_DIR) does not exist, run 'make test-setup'"; \
exit 1; \
fi
TEST_DIR="$(TEST_DIR)" PATH="$$PWD:$$PATH" \
ENABLE_VALGRIND="$(ENABLE_VALGRIND)" \
python3 -m pytest test.py -s -q
# Depend on test-teardown so that anything already present is cleaned up first.
test-setup:test-teardown
dd if=/dev/zero of="$(TEST_IMAGE)" bs=1M count=32
mkfs.ext4 -b 4096 -O encrypt -F "$(TEST_IMAGE)"
mkdir -p "$(TEST_DIR)"
sudo mount -o rw,loop "$(TEST_IMAGE)" "$(TEST_DIR)"
sudo sh -c 'chown $$SUDO_UID:$$SUDO_GID "$(TEST_DIR)"'
@echo
@echo "$(TEST_DIR) is now set up."
test-teardown:
if mountpoint --quiet "$(TEST_DIR)"; then \
sudo umount "$(TEST_DIR)"; \
fi
rm -rf "$(TEST_DIR)"
rm -f "$(TEST_IMAGE)"
test-all:
$(MAKE) test-setup
$(MAKE) test
$(MAKE) test-teardown
##############################################################################
# Installation, uninstallation, and cleanup targets
all:fscryptctl fscryptctl.1
.PHONY: all install install-bin install-man uninstall clean
install-bin: fscryptctl
install -d $(DESTDIR)$(BINDIR)
install -m755 $< $(DESTDIR)$(BINDIR)
install-man: fscryptctl.1
install -d $(DESTDIR)$(MANDIR)/man1
install -m644 $< $(DESTDIR)$(MANDIR)/man1
install:install-bin install-man
uninstall:
rm -f $(DESTDIR)$(BINDIR)/fscryptctl
rm -f $(DESTDIR)$(MANDIR)/man1/fscryptctl.1
clean:
rm -f fscryptctl fscryptctl.1 *.o *.pyc
rm -rf __pycache__
rm -rf .pytest_cache
.DEFAULT_GOAL = all