$NetBSD: patch-makefile,v 1.1 2015/05/06 21:50:36 f8l Exp $

Allows overriding prefix, CFLAGS, LDFLAGS and DEFINES.
Adds necessary DEFINES for book files.
Installs (and removes) ECO database.
Adds missing options to install directories properly.
Adds one missing ${DESTDIR} in install target.

--- makefile.orig	2014-12-24 14:13:07.000000000 +0000
+++ makefile
@@ -1,23 +1,23 @@
 ####### default places (can be overridden by "make prefix=/usr install" etc.)
 
-prefix = /usr/local
+prefix ?= /usr/local
 exec_prefix = $(prefix)
 bindir = $(exec_prefix)/bin
 libdir = $(exec_prefix)/lib
 pluginsdir = $(prefix)/share/games/plugins/xboard
 
 ####### choose the line that makes the binary faster on your machine
-# CFLAGS = -O3 -Wall -fomit-frame-pointer -funroll-loops
-CFLAGS = -O3 -Wall -mtune=native --std=gnu89 -D_GNU_SOURCE
-# CFLAGS = -fprofile-generate -mtune=native -O3 -Wall --std=gnu89 -D_GNU_SOURCE
-# CFLAGS = -fprofile-use -mtune=native -O3 -Wall --std=gnu89 -D_GNU_SOURCE
-# CFLAGS = -O3 -Wall -fomit-frame-pointer --std=gnu89 -D_GNU_SOURCE
+# CFLAGS ?= -O3 -Wall -fomit-frame-pointer -funroll-loops
+CFLAGS ?= -O3 -Wall -mtune=native --std=gnu89 -D_GNU_SOURCE
+# CFLAGS ?= -fprofile-generate -mtune=native -O3 -Wall --std=gnu89 -D_GNU_SOURCE
+# CFLAGS ?= -fprofile-use -mtune=native -O3 -Wall --std=gnu89 -D_GNU_SOURCE
+# CFLAGS ?= -O3 -Wall -fomit-frame-pointer --std=gnu89 -D_GNU_SOURCE
 # -std=c99
 #-Werror removed
 
 ####### debug/tuning options for developers
-# CFLAGS = -O -Wall -g3 -static
-# CFLAGS = -O -Wall -pg
+# CFLAGS ?= -O -Wall -g3 -static
+# CFLAGS ?= -O -Wall -pg
 
 #######
 ### DEFINES
@@ -30,8 +30,11 @@ CFLAGS = -O3 -Wall -mtune=native --std=g
 ### -DLEARN_DIR=\"/var/local/lib\"
 ### -DQCAPSONLY
 
-DEFINES = -DGNUFUN
-LDFLAGS =
+DEFINES ?= -DGNUFUN
+DEFINES += -DPBOOK_DIR=\"${libdir}\"
+DEFINES += -DSBOOK_DIR=\"${libdir}\"
+DEFINES += -DECO_DIR=\"${libdir}\"
+LDFLAGS ?=
 
 OBJ = .o/phalanx.o .o/bcreate.o .o/search.o .o/io.o .o/data.o \
 	   .o/evaluate.o .o/genmoves.o .o/moving.o .o/hash.o .o/static.o \
@@ -54,16 +57,18 @@ backup:
 	makefile *.c *.h pbook.phalanx sbook.phalanx test.fin phalanx.eng
 
 install: phalanx
-	install -d 0755 $(DESTDIR)$(bindir)
+	install -dm 0755 $(DESTDIR)$(bindir)
 	install -m 0755 phalanx $(DESTDIR)$(bindir)
-	install -d 0755 $(libdir)
+	install -dm 0755 $(DESTDIR)$(libdir)
 	install -m 0644 pbook.phalanx $(DESTDIR)$(libdir)
 	install -m 0644 sbook.phalanx $(DESTDIR)$(libdir)
-	install -d 0755 $(DESTDIR)$(pluginsdir)
+	install -m 0644 eco.phalanx $(DESTDIR)$(libdir)
+	install -dm 0755 $(DESTDIR)$(pluginsdir)
 	install -m 0644 phalanx.eng $(DESTDIR)$(pluginsdir)
 
 uninstall:
 	rm -f $(DESTDIR)$(bindir)/phalanx
 	rm -f $(DESTDIR)$(libdir)/pbook.phalanx
 	rm -f $(DESTDIR)$(libdir)/sbook.phalanx
+	rm -f $(DESTDIR)$(libdir)/eco.phalanx
 	rm -f $(DESTDIR)$(pluginsdir)/phalanx.eng
