CCFLAGS = -std=c11 -Wall -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough -pedantic -pedantic-errors -fsanitize=address -fno-omit-frame-pointer -g -D_POSIX_C_SOURCE=200809L
LDFLAGS = -lpthread

SERVER_SOURCES=src/args.c src/selector.c src/socks5nio.c src/confignio.c src/stm.c src/hello.c src/request.c src/netutils.c src/buffer.c src/server.c src/auth.c src/cmd.c src/parser.c src/parser_utils.c
CLIENT_SOURCES=src/client.c src/netutils.c
SERVER_OBJECTS=$(SERVER_SOURCES:.c=.o)
CLIENT_OBJECTS=$(CLIENT_SOURCES:.c=.o)
SERVER_TARGET=socks5d
CLIENT_TARGET=client

all: $(SERVER_OBJECTS) $(SERVER_TARGET) $(CLIENT_OBJECTS) $(CLIENT_TARGET)

%.o : %.c
	$(CC) $(CCFLAGS) -I ./include -c $< -o $@

$(SERVER_TARGET): $(SERVER_OBJECTS)
	$(CC) $(CCFLAGS) $(LDFLAGS) -I ./include -o $@ $^

$(CLIENT_TARGET): $(CLIENT_OBJECTS)
	$(CC) $(CCFLAGS) $(LDFLAGS) -I ./include -o $@ $^

clean:
	rm -f $(SERVER_OBJECTS) $(SERVER_TARGET) $(CLIENT_OBJECTS) $(CLIENT_TARGET) report.tasks strace_out

test: clean
	pvs-studio-analyzer trace -- make
	pvs-studio-analyzer analyze
	plog-converter -a '64:1,2,3;GA:1,2,3;OP:1,2,3' -t tasklist -o report.tasks PVS-Studio.log
	rm -f PVS-Studio.log
	cppcheck --quiet --enable=all --force --inconclusive -I include .

.PHONY: all clean test
