#38 build and install shared objects (#39)

* Fixes #36: Added 'all' target to Makefile; fixed typos.

* Fixed all typos. Now everything builds and correctly.
* Added 'all' target, so that `qcbormin` now is built, too.
* Adapted gitignore to ignore `qcbormin`.
* Minor fixes (replaced tabs with spaces where appropriate).

Signed-off-by: Michael Eckel <michael.eckel@sit.fraunhofer.de>

* Added building and installing of shared objects.

Signed-off-by: Michael Eckel <michael.eckel@sit.fraunhofer.de>
diff --git a/Makefile b/Makefile
index 93d568b..5d02a99 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@
 
 CC=cc
 
-CFLAGS=-I inc -I test -Os 
+CFLAGS=-I inc -I test -Os -fPIC
 
 
 
@@ -22,7 +22,7 @@
 
 .PHONY: all install clean
 
-all: qcbortest qcbormin libqcbor.a
+all: qcbortest qcbormin libqcbor.a libqcbor.so
 
 qcbortest: libqcbor.a $(TEST_OBJ) cmd_line_main.o
 	$(CC) -o $@ $^  libqcbor.a
@@ -33,6 +33,9 @@
 libqcbor.a: $(QCBOR_OBJ)
 	ar -r $@ $^
 
+libqcbor.so: $(QCBOR_OBJ)
+		$(CC) $^ $(CFLAGS) -dead_strip -o $@ -shared
+
 PUBLIC_INTERFACE=inc/qcbor/UsefulBuf.h inc/qcbor/qcbor_private.h inc/qcbor/qcbor_common.h inc/qcbor/qcbor_encode.h inc/qcbor/qcbor_decode.h
 
 src/UsefulBuf.o: inc/qcbor/UsefulBuf.h
@@ -40,10 +43,9 @@
 src/qcbor_encode.o: inc/qcbor/UsefulBuf.h inc/qcbor/qcbor_private.h inc/qcbor/qcbor_common.h inc/qcbor/qcbor_decode.h src/ieee754.h
 src/iee754.o: src/ieee754.h
 
-test/run_tests.o: test/UsefulBuf_Tests.h test/float_tests.h test/run_tests.h test/qcbor_encode_tests.h\
-    test/qcbor_decode_tests.h
+test/run_tests.o: test/UsefulBuf_Tests.h test/float_tests.h test/run_tests.h test/qcbor_encode_tests.h test/qcbor_decode_tests.h
 test/UsefulBuf_Tests.o: test/UsefulBuf_Tests.h inc/qcbor/UsefulBuf.h
-test/qcbor_encode_tests.o: test/qcbor_encode_tests.h $(PUBLIC_INTERFACE) 
+test/qcbor_encode_tests.o: test/qcbor_encode_tests.h $(PUBLIC_INTERFACE)
 test/qcbor_decode_tests.o: test/qcbor_decode_tests.h $(PUBLIC_INTERFACE)
 test/float_tests.o: test/float_tests.h test/half_to_double_from_rfc7049.h $(PUBLIC_INTERFACE)
 test/half_to_double_from_rfc7049.o: test/half_to_double_from_rfc7049.h
@@ -56,16 +58,25 @@
     PREFIX := /usr/local
 endif
 
-install: libqcbor.a $(PUBLIC_INTERFACE)
+install: libqcbor.a libqcbor.so $(PUBLIC_INTERFACE)
 	install -d $(DESTDIR)$(PREFIX)/lib/
 	install -m 644 libqcbor.a $(DESTDIR)$(PREFIX)/lib/
+	install -m 755 libqcbor.so $(DESTDIR)$(PREFIX)/lib/libqcbor.so.1.0.0
+	ln -sf libqcbor.so.1 $(DESTDIR)$(PREFIX)/lib/libqcbor.so
+	ln -sf libqcbor.so.1.0.0 $(DESTDIR)$(PREFIX)/lib/libqcbor.so.1
 	install -d $(DESTDIR)$(PREFIX)/include/qcbor
-	install -m 644 inc/qcbor.h $(DESTDIR)$(PREFIX)/include/qcbor
+	install -m 644 inc/qcbor/qcbor.h $(DESTDIR)$(PREFIX)/include/qcbor
 	install -m 644 inc/qcbor/qcbor_private.h $(DESTDIR)$(PREFIX)/include/qcbor
 	install -m 644 inc/qcbor/qcbor_common.h $(DESTDIR)$(PREFIX)/include/qcbor
 	install -m 644 inc/qcbor/qcbor_decode.h $(DESTDIR)$(PREFIX)/include/qcbor
 	install -m 644 inc/qcbor/qcbor_encode.h $(DESTDIR)$(PREFIX)/include/qcbor
 	install -m 644 inc/qcbor/UsefulBuf.h $(DESTDIR)$(PREFIX)/include/qcbor
 
+uninstall: libqcbor.a $(PUBLIC_INTERFACE)
+	$(RM) -d $(DESTDIR)$(PREFIX)/include/qcbor/*
+	$(RM) -d $(DESTDIR)$(PREFIX)/include/qcbor/
+	$(RM) $(addprefix $(DESTDIR)$(PREFIX)/lib/, \
+		libqcbor.a libqcbor.so libqcbor.so.1 libqcbor.so.1.0.0)
+
 clean:
 	rm -f $(QCBOR_OBJ) $(TEST_OBJ) libqcbor.a min_use_main.o cmd_line_main.o