Skip to content

Commit

Permalink
Add support for building on/cross-compiling the shared library for Wi…
Browse files Browse the repository at this point in the history
…ndows and OS X

Also ensure that the shared library is versioned, and an implib is created on
Windows.
  • Loading branch information
nirbheek committed Nov 26, 2014
1 parent 9d40100 commit cae277e
Showing 1 changed file with 40 additions and 13 deletions.
53 changes: 40 additions & 13 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ USE_OPENSSL = @USE_OPENSSL@
HAVE_PCAP = @HAVE_PCAP@
HAVE_PKG_CONFIG = @HAVE_PKG_CONFIG@

.PHONY: all test build_table_apps
.PHONY: all shared_library test build_table_apps

all: test

Expand All @@ -44,10 +44,10 @@ endif
CC = @CC@
INCDIR = -Icrypto/include -I$(srcdir)/include -I$(srcdir)/crypto/include
DEFS = @DEFS@
CPPFLAGS= @CPPFLAGS@
CPPFLAGS= -fPIC @CPPFLAGS@
CFLAGS = @CFLAGS@
LIBS = @LIBS@
LDFLAGS = @LDFLAGS@ -L.
LDFLAGS = -L. @LDFLAGS@
COMPILE = $(CC) $(DEFS) $(INCDIR) $(CPPFLAGS) $(CFLAGS)
SRTPLIB = -lsrtp

Expand Down Expand Up @@ -76,12 +76,33 @@ prefix = @prefix@
exec_prefix = @exec_prefix@
includedir = @includedir@
libdir = @libdir@
bindir = @bindir@

ifeq (1, $(HAVE_PKG_CONFIG))
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libsrtp.pc
endif

SHAREDLIBVERSION = 1
ifeq (linux,$(findstring linux,@host@))
SHAREDLIB_DIR = $(libdir)
SHAREDLIB_LDFLAGS = -shared -Wl,-soname,$@
SHAREDLIBSUFFIXNOVER = so
SHAREDLIBSUFFIX = $(SHAREDLIBSUFFIXNOVER).$(SHAREDLIBVERSION)
else ifeq (mingw,$(findstring mingw,@host@))
SHAREDLIB_DIR = $(bindir)
SHAREDLIB_LDFLAGS = -shared -Wl,--out-implib,libsrtp.dll.a
SHAREDLIBVERSION =
SHAREDLIBSUFFIXNOVER = dll
SHAREDLIBSUFFIX = $(SHAREDLIBSUFFIXNOVER)
else ifeq (darwin,$(findstring darwin,@host@))
SHAREDLIB_DIR = $(libdir)
SHAREDLIB_LDFLAGS = -dynamiclib -twolevel_namespace -undefined dynamic_lookup \
-fno-common -headerpad_max_install_names -install_name $(libdir)/$@
SHAREDLIBSUFFIXNOVER = dylib
SHAREDLIBSUFFIX = $(SHAREDLIBVERSION).$(SHAREDLIBSUFFIXNOVER)
endif

# implicit rules for object files and test apps

%.o: %.c
Expand Down Expand Up @@ -122,9 +143,14 @@ libsrtp.a: $(srtpobj) $(cryptobj) $(gdoi)
ar cr libsrtp.a $^
$(RANLIB) libsrtp.a

libsrtp.so: $(srtpobj) $(cryptobj) $(gdoi)
$(CC) -shared -Wl,-soname,libsrtp.so \
-o libsrtp.so $^ $(LDFLAGS)
libsrtp.$(SHAREDLIBSUFFIX): $(srtpobj) $(cryptobj) $(gdoi)
$(CC) -shared -o $@ $(SHAREDLIB_LDFLAGS) \
$^ $(LDFLAGS) $(LIBS)
if [ -n "$(SHAREDLIBVERSION)" ]; then \
ln -sfn $@ libsrtp.$(SHAREDLIBSUFFIXNOVER); \
fi

shared_library: libsrtp.$(SHAREDLIBSUFFIX)

# libcryptomath.a contains general-purpose routines that are used to
# generate tables and verify cryptoalgorithm implementations - this
Expand Down Expand Up @@ -224,33 +250,34 @@ libsrtpdoc:
.PHONY: clean superclean distclean install

install:
@if [ -r $(DESTDIR)$(includedir)/srtp/srtp.h ]; then \
echo "you should run 'make uninstall' first"; exit 1; \
fi
$(INSTALL) -d $(DESTDIR)$(includedir)/srtp
$(INSTALL) -d $(DESTDIR)$(libdir)
$(INSTALL) -d $(DESTDIR)$(bindir)
cp $(srcdir)/include/*.h $(DESTDIR)$(includedir)/srtp
cp $(srcdir)/crypto/include/*.h $(DESTDIR)$(includedir)/srtp
if [ "$(srcdir)" != "." ]; then cp crypto/include/*.h $(DESTDIR)$(includedir)/srtp; fi
if [ -f libsrtp.a ]; then cp libsrtp.a $(DESTDIR)$(libdir)/; fi
if [ -f libsrtp.so ]; then cp libsrtp.so $(DESTDIR)$(libdir)/; fi
if [ -f libsrtp.dll.a ]; then cp libsrtp.dll.a $(DESTDIR)$(libdir)/; fi
if [ -f libsrtp.$(SHAREDLIBSUFFIX) ]; then \
cp libsrtp.$(SHAREDLIBSUFFIX) $(DESTDIR)$(SHAREDLIB_DIR)/; \
cp libsrtp.$(SHAREDLIBSUFFIXNOVER) $(DESTDIR)$(SHAREDLIB_DIR)/; \
fi
if [ "$(pkgconfig_DATA)" != "" ]; then \
$(INSTALL) -d $(DESTDIR)$(pkgconfigdir); \
cp $(srcdir)/$(pkgconfig_DATA) $(DESTDIR)$(pkgconfigdir)/; \
fi

uninstall:
rm -f $(DESTDIR)$(includedir)/srtp/*.h
rm -f $(DESTDIR)$(libdir)/libsrtp.a
rm -f $(DESTDIR)$(libdir)/libsrtp.so
rm -f $(DESTDIR)$(libdir)/libsrtp.*
-rmdir $(DESTDIR)$(includedir)/srtp
if [ "$(pkgconfig_DATA)" != "" ]; then \
rm -f $(DESTDIR)$(pkgconfigdir)/$(pkgconfig_DATA); \
fi

clean:
rm -rf $(cryptobj) $(srtpobj) $(cryptomath) TAGS \
libcryptomath.a libsrtp.a libsrtp.so core *.core test/core
libcryptomath.a libsrtp.* core *.core test/core
for a in * */* */*/*; do \
if [ -f "$$a~" ] ; then rm -f $$a~; fi; \
done;
Expand Down

0 comments on commit cae277e

Please sign in to comment.