#
# Makefile for `vis' and `unvis'.
# Copyright (c) 2017, 2018, 2022  Pauline Emily
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. Neither the name of the University nor the names of its contributors
#    may be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
SHELL = /bin/sh

prefix = /usr/local
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
datarootdir = $(prefix)/share
mandir = $(datarootdir)/man

CC = cc
CFLAGS = -g -O2
WARN = -Wall -Wextra

CFLAGS_libbsd := $(shell pkg-config --cflags libbsd-overlay) -DLIBBSD_NETBSD_VIS
LDFLAGS_libbsd := $(shell pkg-config --libs libbsd-overlay)

INSTALL = install
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = $(INSTALL) -m 644

PROG = vis unvis
MAN = $(patsubst %,%.1,$(PROG))

all: $(PROG)
.PHONY: all

clean:
	rm -f $(PROG) *.o
.PHONY: clean

install: $(PROG) $(MAN)
	mkdir -p $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)/man1
	$(INSTALL_PROGRAM) $(PROG) $(DESTDIR)$(bindir)
	$(INSTALL_DATA) $(MAN) $(DESTDIR)$(mandir)/man1
.PHONY: install

install-strip:
	@$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install
.PHONY: install-strip

foldit.o vis.o: extern.h
unvis.o:
vis: foldit.o

%: %.o
	$(CC) $(LDFLAGS) $(LDFLAGS_libbsd) $(LDADD) -o $@ $^

%.o: %.c
	$(CC) $(CFLAGS) $(CFLAGS_libbsd) $(CPPFLAGS) $(WARN) -o $@ -c $<
