forked from slicer69/doas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
109 lines (97 loc) · 3.12 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
CAT?=cat
SED?=sed
CC?=clang
YACC?=yacc
BIN=doas
PREFIX?=/usr/local
MANDIR?=$(DESTDIR)$(PREFIX)/man
SYSCONFDIR?=$(DESTDIR)$(PREFIX)/etc
DOAS_CONF=$(SYSCONFDIR)/doas.conf
OBJECTS=doas.o env.o compat/execvpe.o compat/reallocarray.o y.tab.o
OPT?=-O2
# Can set GLOBAL_PATH here to set PATH for target user.
# TARGETPATH=-DGLOBAL_PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:\"
CFLAGS+=-Wall $(OPT) -DUSE_PAM -DDOAS_CONF=\"$(DOAS_CONF)\" $(TARGETPATH)
CPPFLAGS+=-include compat/compat.h
LDFLAGS+=-lpam
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
LDFLAGS+=-lpam_misc
CPPFLAGS+=-Icompat
CFLAGS+=-D_GNU_SOURCE
COMPAT+=closefrom.o errc.o getprogname.o setprogname.o strlcat.o strlcpy.o strtonum.o verrc.o
OBJECTS+=$(COMPAT:%.o=compat/%.o)
endif
ifeq ($(UNAME_S),FreeBSD)
CFLAGS+=-DHAVE_LOGIN_CAP_H
LDFLAGS+=-lutil
endif
ifeq ($(UNAME_S),MidnightBSD)
CFLAGS+=-DHAVE_LOGIN_CAP_H
LDFLAGS+=-lutil
endif
ifeq ($(UNAME_S),NetBSD)
CFLAGS+=-DHAVE_LOGIN_CAP_H -D_OPENBSD_SOURCE
OBJECTS=doas.o env.o y.tab.o
LDFLAGS+=-lutil
endif
ifeq ($(UNAME_S),SunOS)
SAFE_PATH?=/bin:/sbin:/usr/bin:/usr/sbin:$(PREFIX)/bin:$(PREFIX)/sbin
GLOBAL_PATH?=/bin:/sbin:/usr/bin:/usr/sbin:$(PREFIX)/bin:$(PREFIX)/sbin
CPPFLAGS+=-Icompat
CFLAGS+=-DSOLARIS_PAM -DSAFE_PATH=\"$(SAFE_PATH)\" -DGLOBAL_PATH=\"$(GLOBAL_PATH)\"
COMPAT=errc.o pm_pam_conv.o setresuid.o verrc.o
OBJECTS+=$(COMPAT:%.o=compat/%.o)
endif
ifeq ($(UNAME_S),Darwin)
CPPFLAGS+=-Icompat
COMPAT+=bsd-closefrom.o
OBJECTS+=$(COMPAT:%.o=compat/%.o)
# On MacOS the default man page path is /usr/local/share/man
MANDIR=$(DESTDIR)$(PREFIX)/share/man
endif
FINALS=doas.1.final doas.conf.5.final vidoas.final vidoas.8.final
all: $(BIN) $(FINALS)
$(BIN): $(OBJECTS)
$(CC) -o $(BIN) $(OBJECTS) $(LDFLAGS)
env.o: doas.h env.c
execvpe.o: doas.h execvpe.c
doas.o: doas.h doas.c parse.y
reallocarray.o: doas.h reallocarray.c
y.tab.o: parse.y
$(YACC) parse.y
$(CC) $(CPPFLAGS) $(CFLAGS) -c y.tab.c
install: $(BIN) $(FINALS)
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp $(BIN) $(DESTDIR)$(PREFIX)/bin/
chmod 4755 $(DESTDIR)$(PREFIX)/bin/$(BIN)
cp vidoas.final $(DESTDIR)$(PREFIX)/bin/vidoas
chmod 755 $(DESTDIR)$(PREFIX)/bin/vidoas
cp doasedit $(DESTDIR)$(PREFIX)/bin/doasedit
chmod 755 $(DESTDIR)$(PREFIX)/bin/doasedit
mkdir -p $(MANDIR)/man1
cp doas.1.final $(MANDIR)/man1/doas.1
mkdir -p $(MANDIR)/man5
cp doas.conf.5.final $(MANDIR)/man5/doas.conf.5
mkdir -p $(MANDIR)/man8
cp vidoas.8.final $(MANDIR)/man8/vidoas.8
cp doasedit.8 $(MANDIR)/man8/doasedit.8
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/doas
rm -f $(DESTDIR)$(PREFIX)/bin/vidoas
rm -f $(DESTDIR)$(PREFIX)/bin/doasedit
rm -f $(MANDIR)/man1/doas.1
rm -f $(MANDIR)/man5/doas.conf.5
rm -f $(MANDIR)/man8/vidoas.8
rm -f $(MANDIR)/man8/doasedit.8
clean:
rm -f $(BIN) $(OBJECTS) y.tab.c
rm -f *.final parse.o
# Doing it this way allows to change the original files
# only partially instead of renaming them.
doas.1.final: doas.1
doas.conf.5.final: doas.conf.5
vidoas.final: vidoas
vidoas.8.final: vidoas.8
$(FINALS):
$(CAT) $^ | $(SED) 's,@DOAS_CONF@,$(DOAS_CONF),g' > $@