$NetBSD$

--- Makefile.orig	2011-11-10 18:10:25.000000000 +0000
+++ Makefile
@@ -8,7 +8,7 @@ HDRS = all.h buffer.h child.h mode.h tex
 	window.h util.h clip.h macro.h mem.h die.h types.h rgba.h
 RELS = $(SRCS:.c=.o)
 LIBS = -lutil
-INST_DIR = $(DESTDIR)/usr
+INST_DIR = $(DESTDIR)/$(PREFIX)
 CFLAGS = -Wall -Wno-parentheses \
 -Wpointer-arith -Wcast-align -Wwrite-strings -Wstrict-prototypes \
 -Wmissing-prototypes -Wmissing-declarations
@@ -22,14 +22,19 @@ STRINGIFY = sed 's/\\/\\\\/g;s/"/\\"/g;s
 
 default: optimized display-test aoeui.1 asdfg.1
 
-aoeui: $(RELS)
-	$(CC) $(CFLAGS) -o $@ $(RELS) $(LIBS)
+aoeui: $(RELS) libs
+	$(CC) $(CFLAGS) -o $@ $(RELS) `cat libs`
 $(RELS): $(HDRS)
 help.o: aoeui.help asdfg.help
 aoeui.help: help.m4
 	m4 help.m4 | $(STRINGIFY) >$@
 asdfg.help: help.m4
 	m4 -D ASDFG help.m4 | $(STRINGIFY) >$@
+libs:
+	case `uname -s` in \
+	  Linux) echo -lutil;; \
+	  *BSD*|DragonFly) echo -lutil -lcompat;; \
+	esac >$@
 
 display-test: display-test.o display.o mem.o utf8.o
 	$(CC) $(CFLAGS) -o $@ display-test.o display.o mem.o utf8.o
@@ -60,14 +65,14 @@ profile: clean
 TAGS: $(SRCS) $(HDRS)
 	$(CTAGS) -x $(SRCS) $(HDRS) >$@
 
-install: aoeui aoeui.1.gz asdfg.1.gz
+install: aoeui aoeui.1 asdfg.1
 	install -d $(INST_DIR)/bin
-	install -d $(INST_DIR)/share/aoeui
-	install -d $(INST_DIR)/share/man/man1
+	install -d $(INST_DIR)/share/doc/aoeui
+	install -d $(INST_DIR)/man/man1
 	install aoeui $(INST_DIR)/bin
 	ln -nf $(INST_DIR)/bin/aoeui $(INST_DIR)/bin/asdfg
-	install *.txt $(INST_DIR)/share/aoeui
-	install *.1.gz $(INST_DIR)/share/man/man1
+	install *.txt $(INST_DIR)/share/doc/aoeui
+	install *.1 $(INST_DIR)/man/man1
 clean:
 	rm -f *.o *.help core gmon.out screenlog.*
 clobber: clean
