CC      ?= cc
CFLAGS  += -std=c99 -pedantic -Wall -Wextra -Os
LDFLAGS += -lelf -lz -lzstd

PREFIX  ?= /usr
BINDIR   = $(PREFIX)/bin
MANDIR   = $(PREFIX)/share/man

SRCS     = util.c pkg.c elf.c lang.c main.c
OBJS     = $(SRCS:.c=.o)

all: revdep

revdep: $(OBJS)
	$(CC) -o $@ $(OBJS) $(LDFLAGS)

%.o: %.c revdep.h
	$(CC) $(CFLAGS) -c $< -o $@

install: all
	install -Dm0755 revdep $(DESTDIR)$(BINDIR)/revdep
	install -Dm0644 man/revdep.8 $(DESTDIR)$(MANDIR)/man8/revdep.8
	install -dm0755 $(DESTDIR)/etc/revdep.d

uninstall:
	rm -f $(DESTDIR)$(BINDIR)/revdep
	rm -f $(DESTDIR)$(MANDIR)/man8/revdep.8

lint:
	mandoc -Tlint man/revdep.8

clean:
	rm -f $(OBJS) revdep

.PHONY: all clean install uninstall lint
