blob: 178d556e64f7a31d97da1a9401527074e3784f5d [file] [log] [blame]
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -99,7 +99,11 @@ endif # PLATFORM_SHARED_EXT
all: $(SHARED) $(LIBRARY)
-check: all $(PROGRAMS) $(TESTS)
+tests: $(TESTS)
+
+programs: $(PROGRAMS)
+
+check: all programs tests
for t in $(TESTS); do echo "***** Running $$t"; ./$$t || exit 1; done
clean:
@@ -108,7 +112,7 @@ clean:
$(LIBRARY): $(LIBOBJECTS)
rm -f $@
- $(AR) -rs $@ $(LIBOBJECTS)
+ $(AR) rs $@ $(LIBOBJECTS)
db_bench: db/db_bench.o $(LIBOBJECTS) $(TESTUTIL)
$(CXX) $(LDFLAGS) db/db_bench.o $(LIBOBJECTS) $(TESTUTIL) -o $@ $(LIBS)
@@ -190,7 +194,7 @@ write_batch_test: db/write_batch_test.o $(LIBOBJECTS) $(TESTHARNESS)
$(MEMENVLIBRARY) : $(MEMENVOBJECTS)
rm -f $@
- $(AR) -rs $@ $(MEMENVOBJECTS)
+ $(AR) rs $@ $(MEMENVOBJECTS)
memenv_test : helpers/memenv/memenv_test.o $(MEMENVLIBRARY) $(LIBRARY) $(TESTHARNESS)
$(CXX) $(LDFLAGS) helpers/memenv/memenv_test.o $(MEMENVLIBRARY) $(LIBRARY) $(TESTHARNESS) -o $@ $(LIBS)
diff --git a/build_detect_platform b/build_detect_platform
--- a/build_detect_platform
+++ b/build_detect_platform
@@ -104,6 +104,31 @@ case "$TARGET_OS" in
PLATFORM_LIBS="-lpthread"
PORT_FILE=port/port_posix.cc
;;
+ NaCl)
+ PLATFORM=OS_NACL
+ COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_NACL -DLEVELDB_PLATFORM_POSIX"
+ PLATFORM_LDFLAGS="-pthread"
+ PORT_FILE=port/port_posix.cc
+ CROSS_COMPILE=true
+ if [ "$TOOLCHAIN" = "pnacl" -o "$TOOLCHAIN" = "clang-newlib" ]; then
+ COMMON_FLAGS="$COMMON_FLAGS -DLEVELDB_ATOMIC_PRESENT"
+ # Would use -std=c++11 here but its broken on PNaCl:
+ # http://crbug.com/314944
+ PLATFORM_CXXFLAGS="-std=gnu++11"
+ fi
+ if [ "$TOOLCHAIN" = "glibc" ]; then
+ if [ "$NACL_ARCH" = "arm" ]; then
+ COMMON_FLAGS="$COMMON_FLAGS -DLEVELDB_ATOMIC_PRESENT"
+ PLATFORM_CXXFLAGS="-std=c++11"
+ else
+ COMMON_FLAGS="$COMMON_FLAGS -D__STDC_LIMIT_MACROS"
+ PLATFORM_CXXFLAGS="-std=c++0x"
+ fi
+ fi
+ if [ "$NACL_SHARED" != 1 ]; then
+ PLATFORM_SHARED_EXT=""
+ fi
+ ;;
NetBSD)
PLATFORM=OS_NETBSD
COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_NETBSD"
diff --git a/port/port_posix.h b/port/port_posix.h
--- a/port/port_posix.h
+++ b/port/port_posix.h
@@ -34,6 +34,14 @@
// See http://code.google.com/p/android/issues/detail?id=39824
#include <endian.h>
#define PLATFORM_IS_LITTLE_ENDIAN (_BYTE_ORDER == _LITTLE_ENDIAN)
+#elif defined(OS_NACL)
+ #include <sys/types.h>
+ #if defined(_NEWLIB_VERSION)
+ #include <machine/endian.h>
+ #define PLATFORM_IS_LITTLE_ENDIAN (BYTE_ORDER == LITTLE_ENDIAN)
+ #else
+ #include <endian.h>
+ #endif
#else
#include <endian.h>
#endif
@@ -52,7 +60,7 @@
#if defined(OS_MACOSX) || defined(OS_SOLARIS) || defined(OS_FREEBSD) ||\
defined(OS_NETBSD) || defined(OS_OPENBSD) || defined(OS_DRAGONFLYBSD) ||\
- defined(OS_ANDROID) || defined(OS_HPUX) || defined(CYGWIN)
+ defined(OS_ANDROID) || defined(OS_HPUX) || defined(CYGWIN) || (defined(OS_NACL) && (defined(_NEWLIB_VERSION) || defined(__BIONIC__)))
// Use fread/fwrite/fflush on platforms without _unlocked variants
#define fread_unlocked fread
#define fwrite_unlocked fwrite
diff --git a/util/env_posix.cc b/util/env_posix.cc
--- a/util/env_posix.cc
+++ b/util/env_posix.cc
@@ -24,6 +24,32 @@
#include "util/mutexlock.h"
#include "util/posix_logger.h"
+#ifdef __native_client__
+// TODO(sbc): remove once fsync/fdatasync get implemented in sel_ldr.
+#define fsync(X) 0
+#define fdatasync(X) 0
+#ifdef __GLIBC__
+#define geteuid(X) 0
+ssize_t pread(int fd, char* buf, size_t n, off_t off) {
+ off_t cur_pos;
+ ssize_t num_read;
+
+ if ((cur_pos = lseek(fd, 0, SEEK_CUR)) == (off_t)-1)
+ return -1;
+
+ if (lseek(fd, off, SEEK_SET) == (off_t)-1)
+ return -1;
+
+ num_read = read(fd, buf, n);
+
+ if (lseek(fd, cur_pos, SEEK_SET) == (off_t)-1)
+ return -1;
+
+ return num_read;
+}
+#endif
+#endif
+
namespace leveldb {
namespace {
@@ -254,6 +280,9 @@ class PosixWritableFile : public WritableFile {
};
static int LockOrUnlock(int fd, bool lock) {
+#ifdef __native_client__
+ return 0;
+#else
errno = 0;
struct flock f;
memset(&f, 0, sizeof(f));
@@ -262,6 +291,7 @@ static int LockOrUnlock(int fd, bool lock) {
f.l_start = 0;
f.l_len = 0; // Lock/unlock entire file
return fcntl(fd, F_SETLK, &f);
+#endif
}
class PosixFileLock : public FileLock {