--- Makefile.orig	2009-09-28 20:02:18.000000000 -0600
+++ Makefile	2009-09-30 00:19:40.000000000 -0600
@@ -1,5 +1,7 @@
 PACKAGE=grok
 PREFIX=/usr/local
+INSTALL_USER=root
+INSTALL_GROUP=root
 
 CFLAGS+=-pipe -fPIC
 #CFLAGS+=-pg -g
@@ -45,7 +47,7 @@
 GROKPROGOBJ=grok_input.o grok_program.o grok_matchconf.o $(GROKOBJ)
 
 .PHONY: all
-all: grok libgrok.so
+all: grok libgrok.dylib
 
 .PHONY: package build-package test-package
 package: build-package test-package
@@ -82,9 +84,9 @@
 grok: $(GROKOBJ) conf.tab.o conf.yy.o main.o grok_config.o
 	gcc $(LDFLAGS) -g $^ -o $@
 
-libgrok.so: LDFLAGS+=-levent
-libgrok.so: $(GROKOBJ) conf.tab.o conf.yy.o main.o grok_config.o
-	gcc $(LDFLAGS) -fPIC -shared -g $^ -o $@
+libgrok.dylib: LDFLAGS+=-levent
+libgrok.dylib: $(GROKOBJ) conf.tab.o conf.yy.o main.o grok_config.o
+	gcc $(LDFLAGS) -dynamiclib -install_name @@PREFIX@@/lib/libgrok.dylib -compatibility_version 1.0.0 -current_version 1.0.0 -g $^ -o libgrok.dylib
 
 # File dependencies
 grok.h: grok_capture.h
@@ -115,10 +117,13 @@
 .c.o:
 	$(CC) -c $(CFLAGS) $< -o $@
 
-install: libgrok.so grok
-	install -m 755 -o root -g root grok $(PREFIX)/bin
-	install -m 644 -o root -g root libgrok.so $(PREFIX)/lib
+install: libgrok.dylib grok
+	for dirname in bin lib include; do \
+		mkdir -p $(PREFIX)/$$dirname; \
+	done
+	install -m 755 -o $(INSTALL_USER) -g $(INSTALL_GROUP) grok $(PREFIX)/bin/.
+	install -m 644 -o $(INSTALL_USER) -g $(INSTALL_GROUP) libgrok.dylib $(PREFIX)/lib/.
 	for header in grok.h grokre.h grok_pattern.h grok_capture.h grok_capture_xdr.h grok_match.h grok_logging.h; do \
-		install -m 644 -o root -g root $$header $(PREFIX)/include; \
+		install -m 644 -o $(INSTALL_USER) -g $(INSTALL_GROUP) $$header $(PREFIX)/include/.; \
 	done 
 
