--- Makefile.orig	2003-11-06 02:41:01.000000000 +0800
+++ Makefile	2014-06-12 00:33:45.474374245 +0800
@@ -31,16 +31,15 @@
 #
 
 # Change this to your PostgreSQL install directroy.
-PGDIR = /usr/local/pgsql
+PGDIR = ${PREFIX}
 
 
 ### NO NEED TO EDIT BELOW THIS LINE ###
 
-CC = gcc
-COPTS = -O -Wall
+#CC = gcc
 LIBS = -lpq
-CFLAGS = -I${PGDIR}/include
-LDFLAGS = -L${PGDIR}/lib
+CFLAGS+= -I${PGDIR}/include
+LDFLAGS+= -L${PGDIR}/lib
 
 
 SRCS_LOG = pglogd.c
@@ -51,7 +50,19 @@ SRCS_LOGCTL = pglogctl.c
 all : pglogd pglogctl
 
 pglogd : ${SRCS_LOG} ${HDRS_LOG}
-	${CC} ${COPTS} -o $@ ${CFLAGS} ${LDFLAGS} ${LIBS} ${SRCS_LOG}
+	${CC} -o $@ ${CFLAGS} ${LDFLAGS} ${LIBS} ${SRCS_LOG}
 
 pglogctl : ${SRCS_LOGCTL}
-	${CC} ${COPTS} -o $@ ${CFLAGS} ${LDFLAGS} ${LIBS} ${SRCS_LOGCTL}
+	${CC} -o $@ ${CFLAGS} ${LDFLAGS} ${LIBS} ${SRCS_LOGCTL}
+
+PGLOGD_SHARE=	${PREFIX}/share/pglogd
+install :
+	install -m 750 -s -c pglogd $(DESTDIR)${PREFIX}/bin
+	install -m 750 -s -c pglogctl $(DESTDIR)${PREFIX}/bin
+	install -m 755 -d $(DESTDIR)${PREFIX}/share/pglogd
+	install -m 644 -c pglogd_tables.sql $(DESTDIR)${PGLOGD_SHARE}
+	install -m 644 -c README $(DESTDIR)${PGLOGD_SHARE}
+	install -m 644 -c CHANGELOG $(DESTDIR)${PGLOGD_SHARE}
+	install -m 644 -c weblog_daily.sql $(DESTDIR)${PGLOGD_SHARE}
+	install -m 644 -c queries.txt $(DESTDIR)${PGLOGD_SHARE}
+	install -m 644 -c pglogd.conf $(DESTDIR)${PGLOGD_SHARE}
