1# Installation directories.
2PREFIX ?= $(DESTDIR)/usr
3SBINDIR ?= $(DESTDIR)/sbin
4MANDIR = $(PREFIX)/share/man
5LIBDIR ?= $(PREFIX)/lib
6AUDITH = $(shell ls /usr/include/libaudit.h 2>/dev/null)
7
8PROGRESS_STEP=$(shell grep "^\#define STAR_COUNT" restore.h | awk -S '{ print $$3 }')
9ABORT_ON_ERRORS=$(shell grep "^\#define ABORT_ON_ERRORS" setfiles.c | awk -S '{ print $$3 }')
10
11CFLAGS ?= -g -Werror -Wall -W
12override CFLAGS += -I$(PREFIX)/include
13LDLIBS = -lselinux -lsepol -L$(LIBDIR)
14
15ifeq ($(AUDITH), /usr/include/libaudit.h)
16	override CFLAGS += -DUSE_AUDIT
17	LDLIBS += -laudit
18endif
19
20all: setfiles restorecon man
21
22setfiles:  setfiles.o restore.o
23
24restorecon: setfiles
25	ln -sf setfiles restorecon
26
27man:
28	@cp -af setfiles.8 setfiles.8.man
29	@cp -af restorecon.8 restorecon.8.man
30	@sed -i "s/STAR_COUNT/$(PROGRESS_STEP)/g" setfiles.8.man restorecon.8.man
31	@sed -i "s/ABORT_ON_ERRORS/$(ABORT_ON_ERRORS)/g" setfiles.8.man
32
33install: all
34	[ -d $(MANDIR)/man8 ] || mkdir -p $(MANDIR)/man8
35	-mkdir -p $(SBINDIR)
36	install -m 755 setfiles $(SBINDIR)
37	(cd $(SBINDIR) && ln -sf setfiles restorecon)
38	install -m 644 setfiles.8.man $(MANDIR)/man8/setfiles.8
39	install -m 644 restorecon.8.man $(MANDIR)/man8/restorecon.8
40
41clean:
42	rm -f setfiles restorecon *.o setfiles.8.man restorecon.8.man
43
44indent:
45	../../scripts/Lindent $(wildcard *.[ch])
46
47relabel: install
48	$(SBINDIR)/restorecon $(SBINDIR)/setfiles
49