-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
63 lines (49 loc) · 1.74 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
#
# Copyright © 2016–2017 Daniel Aleksandersen
# SPDX-License-Identifier: MIT
# License-Filename: LICENSE
#
NAME = llwr
MANPAGE = docs/man.8
SHSCRIPT = $(NAME).sh
LICENSE = LICENSE
PREFIX ?= /usr/local
SRCDIR = src
BUILDDIR = build
BINDIR = $(PREFIX)/bin
MANDIR = $(PREFIX)/share/man/man8
LEGALDIR = $(PREFIX)/share/licenses/$(NAME)
INSTALL_PROGRAM = /usr/bin/install
# (Trusts build environment!)
BASH_CMD = $(shell which bash)
CUT_CMD = $(shell which cut)
GREP_CMD = $(shell which grep)
IW_CMD= $(shell which iw)
XARGS_CMD = $(shell which xargs)
all: build
build: $(BUILDDIR)/$(SHSCRIPT)
$(BUILDDIR)/$(SHSCRIPT): $(SRCDIR)/$(SHSCRIPT)
-mkdir -p $(BUILDDIR)
cp $(SRCDIR)/$(SHSCRIPT) $(BUILDDIR)/$(SHSCRIPT)
# Harden by replacing '/bin/env X' with absolute paths
sed -i -e 's:/bin/env bash:$(BASH_CMD):g' "$(BUILDDIR)/$(SHSCRIPT)"
sed -i -e 's:/bin/env cut:$(CUT_CMD):g' "$(BUILDDIR)/$(SHSCRIPT)"
sed -i -e 's:/bin/env grep:$(GREP_CMD):g' "$(BUILDDIR)/$(SHSCRIPT)"
sed -i -e 's:/bin/env iw:$(IW_CMD):g' "$(BUILDDIR)/$(SHSCRIPT)"
sed -i -e 's:/bin/env xargs:$(XARGS_CMD):g' "$(BUILDDIR)/$(SHSCRIPT)"
install: install-exec install-docs
install-docs: $(MANPAGE) $(LICENSE)
$(INSTALL_PROGRAM) -d $(DESTDIR)$(MANDIR)/
$(INSTALL_PROGRAM) $(INSTALLFLAGS) -m 644 $(MANPAGE) $(DESTDIR)$(MANDIR)/$(NAME).8
$(INSTALL_PROGRAM) -d $(DESTDIR)$(LEGALDIR)/
$(INSTALL_PROGRAM) $(INSTALLFLAGS) -m 644 $(LICENSE) $(DESTDIR)$(LEGALDIR)/
install-exec: $(BUILDDIR)/$(SHSCRIPT)
$(INSTALL_PROGRAM) -d $(DESTDIR)$(BINDIR)/
$(INSTALL_PROGRAM) $(INSTALLFLAGS) -m 755 $(BUILDDIR)/$(SHSCRIPT) $(DESTDIR)$(BINDIR)/$(NAME)
uninstall:
-rm $(DESTDIR)$(BINDIR)/$(NAME)
-rm $(DESTDIR)$(MANDIR)/$(NAME).8
-rm -rf $(DESTDIR)$(LEGALDIR)/
clean:
-rm -rf $(BUILDDIR)/
distclean: clean