Skip to content

Commit bc1ee4d

Browse files
committed
build shared libraries; updated version to 1.3; add Status accessors
1 parent a1ad4d1 commit bc1ee4d

File tree

5 files changed

+53
-14
lines changed

5 files changed

+53
-14
lines changed

Makefile

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
# Use of this source code is governed by a BSD-style license that can be
33
# found in the LICENSE file. See the AUTHORS file for names of contributors.
44

5+
# Inherit some settings from environment variables, if available
56
CXX ?= g++
67
CC ?= gcc
8+
INSTALL_PATH ?= $(CURDIR)
79

810
#-----------------------------------------------
911
# Uncomment exactly one of the lines labelled (A), (B), and (C) below
@@ -19,8 +21,8 @@ $(shell sh ./build_detect_platform)
1921
# this file is generated by build_detect_platform to set build flags and sources
2022
include build_config.mk
2123

22-
CFLAGS += -c -I. -I./include $(PLATFORM_CCFLAGS) $(OPT)
23-
CXXFLAGS += -c -I. -I./include $(PLATFORM_CXXFLAGS) $(OPT)
24+
CFLAGS += -I. -I./include $(PLATFORM_CCFLAGS) $(OPT)
25+
CXXFLAGS += -I. -I./include $(PLATFORM_CXXFLAGS) $(OPT)
2426

2527
LDFLAGS += $(PLATFORM_LDFLAGS)
2628

@@ -55,15 +57,33 @@ BENCHMARKS = db_bench_sqlite3 db_bench_tree_db
5557
LIBRARY = libleveldb.a
5658
MEMENVLIBRARY = libmemenv.a
5759

58-
all: $(LIBRARY)
60+
default: all
61+
62+
# Should we build shared libraries?
63+
ifneq ($(PLATFORM_SHARED_EXT),)
64+
# Update db.h if you change these.
65+
SHARED_MAJOR = 1
66+
SHARED_MINOR = 3
67+
SHARED1 = libleveldb.$(PLATFORM_SHARED_EXT)
68+
SHARED2 = $(SHARED1).$(SHARED_MAJOR)
69+
SHARED3 = $(SHARED1).$(SHARED_MAJOR).$(SHARED_MINOR)
70+
SHARED = $(SHARED1) $(SHARED2) $(SHARED3)
71+
$(SHARED3):
72+
$(CXX) $(LDFLAGS) $(PLATFORM_SHARED_LDFLAGS)$(INSTALL_PATH)/$(SHARED2) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(SOURCES) -o $(SHARED3)
73+
$(SHARED2): $(SHARED3)
74+
ln -fs $(SHARED3) $(SHARED2)
75+
$(SHARED1): $(SHARED3)
76+
ln -fs $(SHARED3) $(SHARED1)
77+
endif
78+
79+
all: $(SHARED) $(LIBRARY)
5980

60-
check: $(PROGRAMS) $(TESTS)
81+
check: all $(PROGRAMS) $(TESTS)
6182
for t in $(TESTS); do echo "***** Running $$t"; ./$$t || exit 1; done
6283

6384
clean:
64-
-rm -f $(PROGRAMS) $(BENCHMARKS) $(LIBRARY) $(MEMENVLIBRARY) */*.o */*/*.o ios-x86/*/*.o ios-arm/*/*.o
85+
-rm -f $(PROGRAMS) $(BENCHMARKS) $(LIBRARY) $(SHARED) $(MEMENVLIBRARY) */*.o */*/*.o ios-x86/*/*.o ios-arm/*/*.o build_config.mk
6586
-rm -rf ios-x86/* ios-arm/*
66-
-rm build_config.mk
6787

6888
$(LIBRARY): $(LIBOBJECTS)
6989
rm -f $@
@@ -142,22 +162,22 @@ IOSVERSION=$(shell defaults read /Developer/Platforms/iPhoneOS.platform/version
142162

143163
.cc.o:
144164
mkdir -p ios-x86/$(dir $@)
145-
$(SIMULATORROOT)/usr/bin/$(CXX) $(CXXFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 $< -o ios-x86/$@
165+
$(SIMULATORROOT)/usr/bin/$(CXX) $(CXXFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -c $< -o ios-x86/$@
146166
mkdir -p ios-arm/$(dir $@)
147-
$(DEVICEROOT)/usr/bin/$(CXX) $(CXXFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 $< -o ios-arm/$@
167+
$(DEVICEROOT)/usr/bin/$(CXX) $(CXXFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 -c $< -o ios-arm/$@
148168
lipo ios-x86/$@ ios-arm/$@ -create -output $@
149169

150170
.c.o:
151171
mkdir -p ios-x86/$(dir $@)
152-
$(SIMULATORROOT)/usr/bin/$(CC) $(CFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 $< -o ios-x86/$@
172+
$(SIMULATORROOT)/usr/bin/$(CC) $(CFLAGS) -isysroot $(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk -arch i686 -c $< -o ios-x86/$@
153173
mkdir -p ios-arm/$(dir $@)
154-
$(DEVICEROOT)/usr/bin/$(CC) $(CFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 $< -o ios-arm/$@
174+
$(DEVICEROOT)/usr/bin/$(CC) $(CFLAGS) -isysroot $(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk -arch armv6 -arch armv7 -c $< -o ios-arm/$@
155175
lipo ios-x86/$@ ios-arm/$@ -create -output $@
156176

157177
else
158178
.cc.o:
159-
$(CXX) $(CXXFLAGS) $< -o $@
179+
$(CXX) $(CXXFLAGS) -c $< -o $@
160180

161181
.c.o:
162-
$(CC) $(CFLAGS) $< -o $@
182+
$(CC) $(CFLAGS) -c $< -o $@
163183
endif

build_detect_platform

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#
66
# build_config.mk will set the following variables:
77
# PLATFORM_LDFLAGS Linker flags
8+
# PLATFORM_SHARED_EXT Extension for shared libraries
9+
# PLATFORM_SHARED_LDFLAGS Flags for building shared library
10+
# PLATFORM_SHARED_CFLAGS Flags for compiling objects for shared library
811
# PLATFORM_CCFLAGS C compiler flags
912
# PLATFORM_CXXFLAGS C++ compiler flags. Will contain:
1013
# -DLEVELDB_PLATFORM_POSIX if cstdatomic is present
@@ -29,12 +32,17 @@ COMMON_FLAGS=
2932
PLATFORM_CCFLAGS=
3033
PLATFORM_CXXFLAGS=
3134
PLATFORM_LDFLAGS=
35+
PLATFORM_SHARED_EXT="so"
36+
PLATFORM_SHARED_LDFLAGS="-shared -Wl,-soname -Wl,"
37+
PLATFORM_SHARED_CFLAGS="-fPIC"
3238

3339
# On GCC, we pick libc's memcmp over GCC's memcmp via -fno-builtin-memcmp
3440
case "$TARGET_OS" in
3541
Darwin)
3642
PLATFORM=OS_MACOSX
3743
COMMON_FLAGS="-fno-builtin-memcmp -DOS_MACOSX"
44+
PLATFORM_SHARED_EXT=dylib
45+
PLATFORM_SHARED_LDFLAGS="-dynamiclib -install_name "
3846
PORT_FILE=port/port_posix.cc
3947
;;
4048
Linux)
@@ -143,3 +151,6 @@ echo "PLATFORM=$PLATFORM" >> build_config.mk
143151
echo "PLATFORM_LDFLAGS=$PLATFORM_LDFLAGS" >> build_config.mk
144152
echo "PLATFORM_CCFLAGS=$PLATFORM_CCFLAGS" >> build_config.mk
145153
echo "PLATFORM_CXXFLAGS=$PLATFORM_CXXFLAGS" >> build_config.mk
154+
echo "PLATFORM_SHARED_CFLAGS=$PLATFORM_SHARED_CFLAGS" >> build_config.mk
155+
echo "PLATFORM_SHARED_EXT=$PLATFORM_SHARED_EXT" >> build_config.mk
156+
echo "PLATFORM_SHARED_LDFLAGS=$PLATFORM_SHARED_LDFLAGS" >> build_config.mk

db/skiplist.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ class SkipList {
105105
port::AtomicPointer max_height_; // Height of the entire list
106106

107107
inline int GetMaxHeight() const {
108-
return reinterpret_cast<intptr_t>(max_height_.NoBarrier_Load());
108+
return static_cast<int>(
109+
reinterpret_cast<intptr_t>(max_height_.NoBarrier_Load()));
109110
}
110111

111112
// Read/written only by Insert().

include/leveldb/db.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
namespace leveldb {
1414

15+
// Update Makefile if you change these
1516
static const int kMajorVersion = 1;
16-
static const int kMinorVersion = 2;
17+
static const int kMinorVersion = 3;
1718

1819
struct Options;
1920
struct ReadOptions;

include/leveldb/status.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ class Status {
5454
// Returns true iff the status indicates a NotFound error.
5555
bool IsNotFound() const { return code() == kNotFound; }
5656

57+
// Returns true iff the status indicates a Corruption error.
58+
bool IsCorruption() const { return code() == kCorruption; }
59+
60+
// Returns true iff the status indicates an IOError.
61+
bool IsIOError() const { return code() == kIOError; }
62+
5763
// Return a string representation of this status suitable for printing.
5864
// Returns the string "OK" for success.
5965
std::string ToString() const;

0 commit comments

Comments
 (0)