CC = gcc
CFLAGS = -O2   -I. -I/usr/include/bsd   -DDEBIAN
LDFLAGS = -s
LDLIBS = -lbsd

INSTALL = install
LS = ls

bindir = /bin
sbindir = /sbin
usrbindir = /usr/bin
usrsbindir = /usr/sbin
libdir = /usr/lib
mandir = /usr/man
man1dir = $(mandir)/man1
man6dir = $(mandir)/man6
man8dir = $(mandir)/man8

# Programs that are installed to $(bindir).
BINPROGS = kill pwd

# Programs that are installed to $(sbindir).
SBINPROGS =

# Programs that are installed to $(usrbindir).
USRBINPROGS = banner cal calendar col colcrt colrm column from hexdump logger \
              look lorder mesg renice script tsort ul vacation wall write whois

# Programs that are installed to $(usrsbindir).
USRSBINPROGS = chroot

.c.o:
	$(CC) $(CFLAGS) -c $<

.o:
	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)

all: $(BINPROGS) $(SBINPROGS) $(USRBINPROGS) $(USRSBINPROGS)

clean:
	rm -f $(BINPROGS) $(SBINPROGS) $(USRBINPROGS) $(USRSBINPROGS)
	rm -f *.o core

install: all
	./mkinstalldirs $(bindir) $(sbindir) $(usrbindir) $(usrsbindir) \
	  $(libdir) $(man1dir) $(man6dir) $(man8dir)
	for f in $(BINPROGS); \
	do \
	  $(INSTALL) $$f $(bindir)/$$f; \
	done
	for f in $(SBINPROGS); \
	do \
	  $(INSTALL) $$f $(sbindir)/$$f; \
	done
	for f in $(USRBINPROGS); \
	do \
	  $(INSTALL) $$f $(usrbindir)/$$f; \
	done
	for f in $(USRSBINPROGS); \
	do \
	  $(INSTALL) $$f $(usrsbindir)/$$f; \
	done
	-$(INSTALL) -d $(libdir)/calendar
	for f in `$(LS) ./calendars`; \
	do \
	  $(INSTALL) -m 644 ./calendars/$$f $(libdir)/calendar/$$f; \
	done
	for f in *.1; \
	do \
	  $(INSTALL) -m 644 $$f $(man1dir)/$$f; \
	done
	for f in *.6; \
	do \
	  $(INSTALL) -m 644 $$f $(man6dir)/$$f; \
	done
	for f in *.8; \
	do \
	  $(INSTALL) -m 644 $$f $(man8dir)/$$f; \
	done

banner:   banner.o err.o getopt.o
cal:      cal.o err.o getopt.o
calendar: calendar.o err.o getopt.o
chroot:   chroot.o err.o getopt.o
col:      col.o err.o getopt.o
colcrt:   colcrt.o err.o getopt.o
colrm:    colrm.o getopt.o
column:   column.o err.o getopt.o
from:     err.o from.o getopt.o
hexdump:  conv.o display.o getopt.o hexdump.o hexsyntax.o odsyntax.o parse.o
kill:     err.o getopt.o kill.o
logger:   err.o getopt.o logger.o
look:     getopt.o look.o
lorder:   lorder.sh
mesg:     err.o getopt.o mesg.o
pwd:      err.o getopt.o pwd.o
renice:   err.o getopt.o renice.o
script:   getopt.o script.o
tsort:    err.o getopt.o tsort.o
	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) -ldb
ul:       err.o getopt.o ul.o
	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) -ltermcap
vacation: err.o getopt.o vacation.o
	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) -ldb
wall:     err.o getopt.o ttymsg.o wall.o
whois:    getopt.o whois.o
write:    err.o getopt.o write.o
