diff --git Makefile Makefile
index d624f49..4355fc7 100644
--- Makefile
+++ Makefile
@@ -3,6 +3,7 @@ TPROGS=sgf sgfsplit sgfvarsplit sgfstrip sgfinfo sgfmerge sgftf \
 	ngf2sgf nip2sgf nk2sgf gib2sgf
 
 PROGS=$(TPROGS) sgftopng ugi2sgf
+OBJECTS:=$(CSOURCES:.c=.o) sgfdbinfo.o
 
 CSOURCES:=sgf.c sgfsplit.c sgfvarsplit.c sgfstrip.c sgfinfo.c sgfmerge.c \
 	sgftf.c sgfcheck.c sgfdb.c readsgf.c readsgf0.c writesgf.c \
@@ -10,17 +11,17 @@ CSOURCES:=sgf.c sgfsplit.c sgfvarsplit.c sgfstrip.c sgfinfo.c sgfmerge.c \
 	playgogame.c tests.c errexit.c xmalloc.c sgftopng.c \
 	ftw.c ugi2sgf.c ngf2sgf.c nip2sgf.c nk2sgf.c gib2sgf.c
 
-OBJECTS:=$(CSOURCES:.c=.o) sgfdbinfo.o
-
 HSOURCES=errexit.h xmalloc.h sgfdb.h readsgf.h writesgf.h sgfinfo.h ftw.h \
 	playgogame.h sgffileinput.h sgfdbinput.h tests.h
 
 SOURCES=$(CSOURCES) $(HSOURCES)
+BINDIR=$(DESTDIR)$(PREFIX)/bin
 
-CFLAGS=-Wall -Wmissing-prototypes -O3
-
+CFLAGS+=-Wall -Wmissing-prototypes -O3
+sgfdbinfo: CFLAGS += -DREAD_FROM_DB
+sgfinfo sgfdbinfo: LDLIBS += -lcrypto
 # For systems where iconv is in a separate library
-# LDLIBS=-liconv
+#sgfcharset ugi2sgf: LDLIBS += -liconv
 # is needed for sgfcharset and ugi2sgf
 
 all: $(PROGS)
@@ -47,23 +48,16 @@ sgftf: sgftf.o readsgf.o ftw.o xmalloc.o
 
 sgfdb: sgfdb.o readsgf.o playgogame.o ftw.o xmalloc.o
 
-sgfinfo: sgfinfo.o sgffileinput.c readsgf.o playgogame.o tests.o \
-	 ftw.o xmalloc.o
-	cc $(CFLAGS) $^ -o $@ -lcrypto
+sgfinfo: sgfinfo.o sgffileinput.o readsgf.o playgogame.o tests.o ftw.o xmalloc.o
 
 sgfdbinfo: sgfdbinfo.o sgfdbinput.o readsgf.o xmalloc.o tests.o ftw.o
-	cc $(CFLAGS) $^ -o $@ -lcrypto
 
 sgfcharset: sgfcharset.o xmalloc.o
 
-sgfinfo.o: sgfinfo.c
+nk2sgf: readsgf.o writesgf.o xmalloc.o
 
 sgfdbinfo.o: sgfinfo.c
-	cc $(CFLAGS) -DREAD_FROM_DB -c sgfinfo.c -o sgfdbinfo.o
-
-sgftopng: sgftopng.o
-
-nk2sgf: readsgf.o writesgf.o xmalloc.o
+	$(CC) $(CFLAGS) -DREAD_FROM_DB $(TARGET_ARCH) -o $@ -c $<
 
 # Something like this spoils the $^ macro
 # $(PROGS): Makefile
@@ -78,5 +72,11 @@ makefile: Makefile makefile.tail
 # gnumake complains about $include
 -include $(DEPFILE)
 
+install: $(PROGS)
+	install -m 755 -D -t "$(BINDIR)" $^
+
+uninstall:
+	rm -f $(PROGS:%=$(BINDIR)/%)
+
 clean:
 	rm -f *~ $(OBJECTS) $(PROGS)
