# Installation directories.
PREFIX ?= /usr/local/selinux
BINDIR ?= $(PREFIX)/bin
MANDIR ?= $(PREFIX)/man

PAMDIR=/etc/pam.d

# libattr library and include directories, if not in /usr/lib and /usr/include.
LIBATTRDIR ?= /usr/local/lib
LIBATTRINC ?= /usr/local/include

# libselinux library and include directories.
# Pull from the local copy unless you separately installed libselinux first.
LIBSELDIR ?= ../libselinux/src
LIBSELINC ?= ../libselinux/include

CFLAGS ?= -Wall -I$(LIBSELINC) -I$(LIBATTRINC)
LDFLAGS ?= -L$(LIBSELDIR) -L$(LIBATTRDIR)
LDLIBS ?= -lselinux -lattr

CFLAGS += -DUSE_PAM
LDLIBS += -ldl -lpam -lpam_misc

TARGETS=$(patsubst %.c,%,$(wildcard *.c))

all: $(TARGETS)

install: all
	test -d $(BINDIR)      || install -m 755 -o root -g root -d $(BINDIR)
	test -d $(MANDIR)/man1 || install -m 755 -o root -g root -d $(MANDIR)/man1
	install -m 555 -o root -g root newrole $(BINDIR)
	install -m 644 -o root -g root newrole.1 $(MANDIR)/man1/
	if [ -d $(PAMDIR) ]; then \
		test -e $(PAMDIR)/newrole && rm -f $(PAMDIR)/newrole; \
		sed "/pam_rootok.so/d" $(PAMDIR)/su > $(PAMDIR)/newrole; \
	fi;

clean:
	rm -f $(TARGETS) *.o 

relabel: install
	setfilecon system_u:object_r:newrole_exec_t $(BINDIR)/newrole
