CC := cc
CFLAGS := -Wall -Wextra -Werror -pedantic
CFLAGS_RELEASE := -O2 -DNDEBUG
CFLAGS_DEBUG := -g3 -O0
CCHECK=-I. -x c - -fsyntax-only
# NOTE: exposes header impls into dynamically linked modules
LDFLAGS :=
LDLIBS :=
DEPS := \
	-I$(HOME)/git/buf/src
SOURCE := \
	src/main.c
TARGET := ductape

all: build

build: $(SOURCE)
	$(CC) -o $(TARGET) $(CFLAGS) $(DEPS) $(LDFLAGS) $^ $(LDLIBS)

build-release: $(SOURCE)
	$(CC) -o $(TARGET) $(CFLAGS) $(DEPS) $(CFLAGS_RELEASE) $(LDFLAGS) $^ $(LDLIBS)

build-debug: $(SOURCE)
	$(CC) -o $(TARGET) $(CFLAGS) $(DEPS) $(CFLAGS_DEBUG) $(LDFLAGS) $^ $(LDLIBS)

clean:
	rm -f ./$(TARGET)

install: build-release
	cp $(TARGET) /usr/local/bin/
	cp src/ductape.h /usr/local/include/
	rm ./$(TARGET)

check: src/ductape.h
	@printf '#define DUCTAPE_IMPL\n#include "%s"' "$^" | $(CC) $(CFLAGS) $(CCHECK)
