Description: Makefile modifications for Debian builds
 Add a static library and rearrange some rules to better suit Debian
 packaging needs.
Author: Julien BLACHE <jblache@debian.org>

Index: oflib-0git20070620/Makefile
===================================================================
--- oflib-0git20070620.orig/Makefile	2011-01-12 18:25:34.341016001 +0100
+++ oflib-0git20070620/Makefile	2011-06-13 10:19:32.242307929 +0200
@@ -1,27 +1,40 @@
-include_dir=/usr/local/include/ofapi
+include_dir = $(DESTDIR)/usr/include/ofapi
+lib_dir = $(DESTDIR)/usr/lib/$(MULTIARCH_PATH)
 
 LIBNAME = libofapi.so
 SONAME = $(LIBNAME).0
 SOVERSION = $(SONAME).0.0
 
+CFLAGS += -g -Wall -O2
+
 default:
-	gcc -g -Wall -D_REENTRANT -DPIC -fpic -Wl,-soname -Wl,$(SONAME) lib/*.c -shared -o $(SOVERSION)
+	gcc $(CFLAGS) -D_REENTRANT -DPIC -fpic  -Wl,-z,relro -Wl,-soname -Wl,$(SONAME) lib/*.c -shared -o $(SOVERSION)
+
+	gcc $(CFLAGS) -c lib/of_externals.c -o lib/of_externals.o
+	gcc $(CFLAGS) -c lib/of_internals.c -o lib/of_internals.o
+	gcc $(CFLAGS) -c lib/of_standard.c -o lib/of_standard.o
+
+	ar cru libofapi.a lib/*.o
+	ranlib libofapi.a
 
 install:
-	cp $(SOVERSION) /usr/local/lib
-	ln -s /usr/local/lib/$(SOVERSION) /usr/local/lib/$(SONAME)
-	ln -s /usr/local/lib/$(SOVERSION) /usr/local/lib/$(LIBNAME)
-	test -d "$(include_dir)" || mkdir "$(include_dir)"
+	mkdir -p $(lib_dir)
+	cp $(SOVERSION) $(lib_dir)
+	cp libofapi.a $(lib_dir)
+	ln -sf $(SOVERSION) $(lib_dir)/$(SONAME)
+	ln -sf $(SOVERSION) $(lib_dir)/$(LIBNAME)
+
+	mkdir -p $(include_dir)
 	cp lib/*.h $(include_dir)
 
 all:
-	make default
-	make install
-	make examples
+	$(MAKE) default
+	$(MAKE) install
+	$(MAKE) examples
 
 examples:
-	make -C example/
+	$(MAKE) -C example/
 
 clean:
-	make -C example/ clean 
-	rm -f libofapi.so.*
+	$(MAKE) -C example/ clean 
+	rm -f $(SOVERSION) lib/*.o libofapi.a
