Skip to content

Commit 47914e0

Browse files
Bertrand Rousselthiagomacieira
authored andcommitted
Provide shared library
Some people may want to use tinycbor as a shared library instead of as a static library, so providing a set of .so accordingly. Even with the static library, I'm having trouble incorporating it into another shared library, so providing -fPIC option as well. Signed-off-by: Bertrand Roussel <[email protected]>
1 parent effaf7d commit 47914e0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ CBORDUMP_SOURCES = tools/cbordump/cbordump.c
3535

3636
INSTALL_TARGETS += $(bindir)/cbordump
3737
INSTALL_TARGETS += $(libdir)/libtinycbor.a
38+
INSTALL_TARGETS += $(libdir)/libtinycbor.so
39+
INSTALL_TARGETS += $(libdir)/libtinycbor.so.0
40+
INSTALL_TARGETS += $(libdir)/libtinycbor.so.$(VERSION)
3841
INSTALL_TARGETS += $(pkgconfigdir)/tinycbor.pc
3942
INSTALL_TARGETS += $(TINYCBOR_HEADERS:src/%=$(includedir)/tinycbor/%)
4043

@@ -96,7 +99,7 @@ ifneq ($(cjson-pass)$(system-cjson-pass),)
9699
endif
97100

98101
# Rules
99-
all: .config lib/libtinycbor.a bin/cbordump tinycbor.pc
102+
all: .config lib/libtinycbor.a lib/libtinycbor.so bin/cbordump tinycbor.pc
100103
all: $(if $(JSON2CBOR_SOURCES),bin/json2cbor)
101104
check: tests/Makefile | lib/libtinycbor.a
102105
$(MAKE) -C tests check
@@ -110,6 +113,10 @@ lib/libtinycbor.a: $(TINYCBOR_SOURCES:.c=.o)
110113
@$(MKDIR) -p lib
111114
$(AR) cqs $@ $^
112115

116+
lib/libtinycbor.so: $(TINYCBOR_SOURCES:.c=.pic.o)
117+
$(CC) -shared -Wl,-soname,libtinycbor.so.0 -o lib/libtinycbor.so.$(VERSION) $(LDFLAGS) $^
118+
cd lib ; ln -s libtinycbor.so.$(VERSION) libtinycbor.so ; ln -s libtinycbor.so.$(VERSION) libtinycbor.so.0
119+
113120
bin/cbordump: $(CBORDUMP_SOURCES:.c=.o) lib/libtinycbor.a
114121
@$(MKDIR) -p bin
115122
$(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) -lm
@@ -163,6 +170,7 @@ clean: mostlyclean
163170
$(RM) bin/json2cbor
164171
$(RM) lib/libtinycbor.a
165172
$(RM) tinycbor.pc
173+
$(RM) lib/libtinycbor.so*
166174
test -e tests/Makefile && $(MAKE) -C tests clean || :
167175

168176
distclean: clean
@@ -192,5 +200,8 @@ cflags += -std=c99 $(CFLAGS)
192200
%.o: %.c
193201
@test -d $(@D) || $(MKDIR) $(@D)
194202
$(CC) $(cflags) $($(basename $(notdir $@))_CCFLAGS) -c -o $@ $<
203+
%.pic.o: %.c
204+
@test -d $(@D) || $(MKDIR) $(@D)
205+
$(CC) $(cflags) -fPIC $($(basename $(notdir $@))_CCFLAGS) -c -o $@ $<
195206

196207
-include src/*.d

0 commit comments

Comments
 (0)