CC?= cc
CFLAGS?= -O2 -pipe -fPIC -fPIE -Wall -Wextra
LDFLAGS= -static-pie
RM?= rm
SYD?= syd

ECHO_SERVER=$(shell readlink -f ./echo_server)
SHELL_SERVER=$(shell readlink -f ./shell_server)

SYD_FLAGS= \
	   -pcontainer \
	   -m "allow/stat+/dev/pts/*" \
	   -m "allow/write+/dev/pts/*" \
	   -m "allow/exec+$(ECHO_SERVER)" \
	   -m "allow/exec+$(SHELL_SERVER)"

all: echo_server shell_server goshell

clean:
	$(RM) -f ./echo_server
	$(RM) -f ./server_server
	$(RM) -f ./goshell

check: test

test: shell_server
	$(SYD) $(SYD_FLAGS) -- ./shell_server

%: %.c
	$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) -lsyd

.PHONY: all check clean test
