Skip to content

Commit

Permalink
Add BUILD_STATIC option
Browse files Browse the repository at this point in the history
 - Enable BUILD_STATIC by default
 - If BUILD_STATIC and BUILD_SHARED are both different from 1, return an
error
 - If BUILD_STATIC is disabled, use shared library for binaries
 - If both are enabled, use the static library

Signed-off-by: Fabrice Fontaine <[email protected]>
  • Loading branch information
ffontaine authored and thiagomacieira committed Dec 7, 2017
1 parent a2dab2c commit 19b26bd
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,25 @@ TINYCBOR_SOURCES = \
CBORDUMP_SOURCES = tools/cbordump/cbordump.c

BUILD_SHARED = $(shell file -L /bin/sh 2>/dev/null | grep -q ELF && echo 1)
BUILD_STATIC = 1

ifneq ($(BUILD_STATIC),1)
ifneq ($(BUILD_SHARED),1)
$(error error: BUILD_STATIC and BUILD_SHARED can not be both disabled)
endif
endif

INSTALL_TARGETS += $(bindir)/cbordump
INSTALL_TARGETS += $(libdir)/libtinycbor.a
ifeq ($(BUILD_SHARED),1)
BINLIBRARY=lib/libtinycbor.so
INSTALL_TARGETS += $(libdir)/libtinycbor.so
INSTALL_TARGETS += $(libdir)/libtinycbor.so.0
INSTALL_TARGETS += $(libdir)/libtinycbor.so.$(VERSION)
endif
ifeq ($(BUILD_STATIC),1)
BINLIBRARY=lib/libtinycbor.a
INSTALL_TARGETS += $(libdir)/libtinycbor.a
endif
INSTALL_TARGETS += $(pkgconfigdir)/tinycbor.pc
INSTALL_TARGETS += $(TINYCBOR_HEADERS:src/%=$(includedir)/tinycbor/%)

Expand Down Expand Up @@ -103,13 +114,14 @@ ifneq ($(cjson-pass)$(system-cjson-pass),)
endif

# Rules
all: .config lib/libtinycbor.a \
all: .config \
$(if $(subst 0,,$(BUILD_STATIC)),lib/libtinycbor.a) \
$(if $(subst 0,,$(BUILD_SHARED)),lib/libtinycbor.so) \
bin/cbordump tinycbor.pc
all: $(if $(JSON2CBOR_SOURCES),bin/json2cbor)
check: tests/Makefile | lib/libtinycbor.a
check: tests/Makefile | $(BINLIBRARY)
$(MAKE) -C tests check
silentcheck: | lib/libtinycbor.a
silentcheck: | $(BINLIBRARY)
TESTARGS=-silent $(MAKE) -f $(MAKEFILE) -s check
configure: .config
.config: Makefile.configure
Expand All @@ -120,14 +132,15 @@ lib/libtinycbor.a: $(TINYCBOR_SOURCES:.c=.o)
$(AR) cqs $@ $^

lib/libtinycbor.so: $(TINYCBOR_SOURCES:.c=.pic.o)
@$(MKDIR) -p lib
$(CC) -shared -Wl,-soname,libtinycbor.so.0 -o lib/libtinycbor.so.$(VERSION) $(LDFLAGS) $^
cd lib ; ln -s libtinycbor.so.$(VERSION) libtinycbor.so ; ln -s libtinycbor.so.$(VERSION) libtinycbor.so.0

bin/cbordump: $(CBORDUMP_SOURCES:.c=.o) lib/libtinycbor.a
bin/cbordump: $(CBORDUMP_SOURCES:.c=.o) $(BINLIBRARY)
@$(MKDIR) -p bin
$(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) -lm

bin/json2cbor: $(JSON2CBOR_SOURCES:.c=.o) lib/libtinycbor.a
bin/json2cbor: $(JSON2CBOR_SOURCES:.c=.o) $(BINLIBRARY)
@$(MKDIR) -p bin
$(CC) -o $@ $(LDFLAGS) $^ $(LDFLAGS_CJSON) $(LDLIBS) -lm

Expand Down

0 comments on commit 19b26bd

Please sign in to comment.