--- Makefile.orig	2010-05-06 20:14:55.000000000 +0200
+++ Makefile	2012-05-19 21:10:00.000000000 +0200
@@ -31,7 +31,7 @@
 #CFLAGS += -O3 -DDO_INLINES
 #
 #GCC flags for debugging, no optimization
-CFLAGS += -g
+#CFLAGS += -g
 #
 #GCC and LD flags for debugging, no optimization, and profile for speed
 #CFLAGS += -g -pg
@@ -45,6 +45,8 @@
 CFLAGS += -std=c99 -pedantic -Wall -Wextra -Wpointer-arith -Wstrict-prototypes
 #well, pretty carefully
 CFLAGS += -Wno-sign-compare -Wno-overlength-strings
+# to build shared library
+CFLAGS += -fPIC
 
 #These are optional.
 
@@ -97,8 +99,8 @@
 crm114_util.o					\
 crm114_regex_tre.o
 
-
-all: test simple_demo
+# .tar.gz includes linux object files -- so clean first
+all: clean libcrm114.so test simple_demo
 
 test: test.o libcrm114.a
 	$(CC) -o test $(LDFLAGS) -Wl,-M -Wl,--cref test.o libcrm114.a -ltre -lm >test.map
@@ -115,6 +117,24 @@
 libcrm114.a: $(LIBOBJS) Makefile
 	ar rc libcrm114.a $(LIBOBJS)
 
+# added for FreeBSD port patch
+libcrm114.so.0: $(LIBOBJS) Makefile
+	$(CC) -o libcrm114.so.0 -shared $(LIBOBJS)
+
+libcrm114.so: libcrm114.so.0
+	ln -fs libcrm114.so.0 libcrm114.so
+
+install: libcrm114.so.0
+	$(BSD_INSTALL_LIB) libcrm114.so.0 $(PREFIX)/lib
+	ln -fs libcrm114.so.0 $(PREFIX)/lib/libcrm114.so
+	$(BSD_INSTALL_DATA) crm114_config.h $(PREFIX)/include
+	$(BSD_INSTALL_DATA) crm114_lib.h $(PREFIX)/include
+	$(BSD_INSTALL_DATA) crm114_structs.h $(PREFIX)/include
+	$(BSD_INSTALL_DATA) crm114_sysincludes.h $(PREFIX)/include
+	$(BSD_INSTALL_DATA) -d $(PREFIX)/share/doc/libcrm114
+	$(BSD_INSTALL_DATA) HOWTO.txt $(PREFIX)/share/doc/libcrm114
+	$(BSD_INSTALL_DATA) simple_demo.c $(PREFIX)/share/doc/libcrm114
+
 $(LIBOBJS): $(LIBHDRS)
 
 clean: clean_test clean_simple_demo clean_lib clean_profiling
@@ -126,7 +146,7 @@
 	rm -f simple_demo simple_demo.map simple_demo.o simple_demo_datablock.txt
 
 clean_lib:
-	rm -f libcrm114.a $(LIBOBJS)
+	rm -f libcrm114.a libcrm114.so $(LIBOBJS)
 
 clean_profiling:
 	rm -f gmon.out *.gcov *.gcno *.gcda
