Skip to content

Instantly share code, notes, and snippets.

@qmx
Created November 12, 2011 04:42
Show Gist options
  • Save qmx/1360052 to your computer and use it in GitHub Desktop.
Save qmx/1360052 to your computer and use it in GitHub Desktop.
From acf44a7936dd7611bc8cd64b07b5fced357f5202 Mon Sep 17 00:00:00 2001
From: Douglas Campos <[email protected]>
Date: Sat, 12 Nov 2011 02:42:40 -0200
Subject: [PATCH] generating shared lib
patch adapted from http://code.google.com/p/leveldb/issues/detail?id=27
---
Makefile | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
index 18386f2..ab8c840 100644
--- a/Makefile
+++ b/Makefile
@@ -3,12 +3,14 @@
# found in the LICENSE file. See the AUTHORS file for names of contributors.
CC = g++
+SONAME_MAJOR=0
+SONAME_MINOR=0
#-----------------------------------------------
# Uncomment exactly one of the lines labelled (A), (B), and (C) below
# to switch between compilation modes.
-OPT = -O2 -DNDEBUG # (A) Production use (optimized mode)
+OPT ?= -O2 -DNDEBUG # (A) Production use (optimized mode)
# OPT = -g2 # (B) Debug mode, w/ full line-level debugging symbols
# OPT = -O2 -g2 -DNDEBUG # (C) Profiling mode: opt, but w/debugging symbols
#-----------------------------------------------
@@ -36,9 +38,9 @@ else
GOOGLE_PERFTOOLS_LDFLAGS=
endif
-CFLAGS = -c -I. -I./include $(PORT_CFLAGS) $(PLATFORM_CFLAGS) $(OPT) $(SNAPPY_CFLAGS)
+CFLAGS += -c -I. -I./include $(PORT_CFLAGS) $(PLATFORM_CFLAGS) $(OPT) $(SNAPPY_CFLAGS) -fPIC
-LDFLAGS=$(PLATFORM_LDFLAGS) $(SNAPPY_LDFLAGS) $(GOOGLE_PERFTOOLS_LDFLAGS)
+LDFLAGS += $(PLATFORM_LDFLAGS) $(SNAPPY_LDFLAGS) $(GOOGLE_PERFTOOLS_LDFLAGS)
LIBOBJECTS = \
./db/builder.o \
@@ -103,15 +105,17 @@ PROGRAMS = db_bench $(TESTS)
BENCHMARKS = db_bench_sqlite3 db_bench_tree_db
LIBRARY = libleveldb.a
+SHARED_LIBRARY = libleveldb.so
MEMENVLIBRARY = libmemenv.a
-all: $(LIBRARY)
+all: $(LIBRARY) $(SHARED_LIBRARY)
check: $(PROGRAMS) $(TESTS)
for t in $(TESTS); do echo "***** Running $$t"; ./$$t || exit 1; done
clean:
-rm -f $(PROGRAMS) $(BENCHMARKS) $(LIBRARY) $(MEMENVLIBRARY) */*.o */*/*.o ios-x86/*/*.o ios-arm/*/*.o
+ -rm -f $(SHARED_LIBRARY).* $(SHARED_LIBRARY)
-rm -rf ios-x86/* ios-arm/*
-rm build_config.mk
@@ -119,6 +123,12 @@ $(LIBRARY): $(LIBOBJECTS)
rm -f $@
$(AR) -rs $@ $(LIBOBJECTS)
+$(SHARED_LIBRARY): $(LIBOBJECTS)
+ rm -f $@
+ $(CC) -shared $(LIBOBJECTS) $(LDFLAGS) -o $@.$(SONAME_MAJOR).$(SONAME_MINOR)
+ ln -s $@.$(SONAME_MAJOR).$(SONAME_MINOR) $@.$(SONAME_MAJOR)
+ ln -s $@.$(SONAME_MAJOR).$(SONAME_MINOR) $@
+
db_bench: db/db_bench.o $(LIBOBJECTS) $(TESTUTIL)
$(CC) $(LDFLAGS) db/db_bench.o $(LIBOBJECTS) $(TESTUTIL) -o $@
--
1.7.4.4+GitX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment