Skip to content

Commit

Permalink
support build for ios
Browse files Browse the repository at this point in the history
  • Loading branch information
ideawu committed Mar 26, 2015
1 parent 1bf5d60 commit 77b860d
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ios
888*.conf
var888*
*.o
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ all:
cd src; ${MAKE}
cd tools; ${MAKE}

.PHONY: ios

ios:
#cd "${LEVELDB_PATH}"; make clean; CXXFLAGS=-stdlib=libc++ ${MAKE} PLATFORM=IOS
#cd "${SNAPPY_PATH}"; make clean; make -f Makefile-ios
cd src/util; make clean; ${MAKE} -f Makefile-ios
cd src/ssdb; make clean; ${MAKE} -f Makefile-ios

install:
mkdir -p ${PREFIX}
Expand Down
14 changes: 10 additions & 4 deletions src/ssdb/Makefile-ios
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ CFLAGS=-stdlib=libc++ -DHAVE_CONFIG_H -DIOS -I. -O2 -I$(LEVELDB_PATH)/include
SIMULATOR_CFLAGS=$(CFLAGS) -isysroot $(SIMULATOR_SDK) -arch i386 -arch x86_64
DEVICE_CFLAGS=$(CFLAGS) -isysroot $(DEVICE_SDK) -arch armv6 -arch armv7

OBJS = ssdb_impl.o iterator.o options.o \
t_kv.o t_hash.o t_zset.o t_queue.o binlog.o ttl.o
OBJS = ssdb_impl.o iterator.o options.o t_kv.o t_hash.o t_zset.o t_queue.o binlog.o ttl.o
LIB = libssdb-ios.a
OUTPUT_LIB_DIR = ../../ios
OUTPUT_HEADER_DIR = ../../ios/include/ssdb

all: $(OBJS)
rm -f libssdb-ios.a
ar -rs libssdb-ios.a $(OBJS)
rm -f $(LIB)
ar -rs $(LIB) $(OBJS)
rm -rf $(OUTPUT_HEADER_DIR) $(OUTPUT_LIB_DIR)/$(LIB)
mkdir -p $(OUTPUT_HEADER_DIR)
cp -f const.h binlog.h iterator.h options.h ssdb.h ttl.h $(OUTPUT_HEADER_DIR)
mv -f $(LIB) $(OUTPUT_LIB_DIR)

.cpp.o:
mkdir -p ios-x86
Expand Down
36 changes: 36 additions & 0 deletions src/util/Makefile-ios
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
include ../../build_config.mk

PLATFORMSROOT=/Applications/Xcode.app/Contents/Developer/Platforms
SIMULATORROOT=$(PLATFORMSROOT)/iPhoneSimulator.platform/Developer
DEVICEROOT=$(PLATFORMSROOT)/iPhoneOS.platform/Developer
IOSVERSION=$(shell defaults read $(PLATFORMSROOT)/iPhoneOS.platform/version CFBundleShortVersionString)
SIMULATOR_SDK=$(SIMULATORROOT)/SDKs/iPhoneSimulator$(IOSVERSION).sdk
DEVICE_SDK=$(DEVICEROOT)/SDKs/iPhoneOS$(IOSVERSION).sdk

CFLAGS=-stdlib=libc++ -DHAVE_CONFIG_H -DIOS -I. -O2 -I$(LEVELDB_PATH)/include
SIMULATOR_CFLAGS=$(CFLAGS) -isysroot $(SIMULATOR_SDK) -arch i386 -arch x86_64
DEVICE_CFLAGS=$(CFLAGS) -isysroot $(DEVICE_SDK) -arch armv6 -arch armv7

OBJS = config.o bytes.o sorted_set.o
LIB = libutil-ios.a
OUTPUT_LIB_DIR = ../../ios
OUTPUT_HEADER_DIR = ../../ios/include/util

all: $(OBJS)
rm -f $(LIB)
ar -rs $(LIB) $(OBJS)
rm -rf $(OUTPUT_HEADER_DIR) $(OUTPUT_LIB_DIR)/$(LIB)
mkdir -p $(OUTPUT_HEADER_DIR)
cp -f config.h bytes.h strings.h $(OUTPUT_HEADER_DIR)
mv -f $(LIB) $(OUTPUT_LIB_DIR)

.cpp.o:
mkdir -p ios-x86
mkdir -p ios-arm
$(CXX) $(SIMULATOR_CFLAGS) -c $< -o ios-x86/$@
xcrun -sdk iphoneos $(CXX) $(DEVICE_CFLAGS) -c $< -o ios-arm/$@
lipo ios-x86/$@ ios-arm/$@ -create -output $@

clean:
rm -f ${EXES} *.o *.exe *.a

6 changes: 3 additions & 3 deletions src/util/bytes.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class Bytes{

Bytes(const std::string &str){
data_ = str.data();
size_ = str.size();
size_ = (int)str.size();
}

Bytes(const char *str){
data_ = str;
size_ = strlen(str);
size_ = (int)strlen(str);
}

const char* data() const{
Expand Down Expand Up @@ -149,7 +149,7 @@ class Buffer{
}

int space() const{
return total_ - (data_ - buf) - size_;
return total_ - (int)(data_ - buf) - size_;
}

void incr(int num){
Expand Down
40 changes: 24 additions & 16 deletions src/util/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,31 @@ void set_log_level(int level);
int log_write(int level, const char *fmt, ...);


#ifdef NDEBUG
#define log_trace(fmt, args...) do{}while(0)
#ifndef IOS
#ifdef NDEBUG
#define log_trace(fmt, args...) do{}while(0)
#else
#define log_trace(fmt, args...) \
log_write(Logger::LEVEL_TRACE, "%s(%d): " fmt, __FILE__, __LINE__, ##args)
#endif

#define log_debug(fmt, args...) \
log_write(Logger::LEVEL_DEBUG, "%s(%d): " fmt, __FILE__, __LINE__, ##args)
#define log_info(fmt, args...) \
log_write(Logger::LEVEL_INFO, "%s(%d): " fmt, __FILE__, __LINE__, ##args)
#define log_warn(fmt, args...) \
log_write(Logger::LEVEL_WARN, "%s(%d): " fmt, __FILE__, __LINE__, ##args)
#define log_error(fmt, args...) \
log_write(Logger::LEVEL_ERROR, "%s(%d): " fmt, __FILE__, __LINE__, ##args)
#define log_fatal(fmt, args...) \
log_write(Logger::LEVEL_FATAL, "%s(%d): " fmt, __FILE__, __LINE__, ##args)
#else
#define log_trace(fmt, args...) \
log_write(Logger::LEVEL_TRACE, "%s(%d): " fmt, __FILE__, __LINE__, ##args)
#define log_trace(fmt, args...) do{}while(0)
#define log_debug(fmt, args...) do{}while(0)
#define log_info(fmt, args...) do{}while(0)
#define log_warn(fmt, args...) do{}while(0)
#define log_error(fmt, args...) do{}while(0)
#define log_fatal(fmt, args...) do{}while(0)
#endif

#define log_debug(fmt, args...) \
log_write(Logger::LEVEL_DEBUG, "%s(%d): " fmt, __FILE__, __LINE__, ##args)
#define log_info(fmt, args...) \
log_write(Logger::LEVEL_INFO, "%s(%d): " fmt, __FILE__, __LINE__, ##args)
#define log_warn(fmt, args...) \
log_write(Logger::LEVEL_WARN, "%s(%d): " fmt, __FILE__, __LINE__, ##args)
#define log_error(fmt, args...) \
log_write(Logger::LEVEL_ERROR, "%s(%d): " fmt, __FILE__, __LINE__, ##args)
#define log_fatal(fmt, args...) \
log_write(Logger::LEVEL_FATAL, "%s(%d): " fmt, __FILE__, __LINE__, ##args)


#endif
8 changes: 4 additions & 4 deletions src/util/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,11 @@ double str_to_double(const char *p, int size){
static inline
std::string substr(const std::string &str, int start, int size){
if(start < 0){
start = str.size() + start;
start = (int)str.size() + start;
}
if(size < 0){
// 忽略掉 abs(size) 个字节
size = (str.size() + size) - start;
size = ((int)str.size() + size) - start;
}
if(start < 0 || size_t(start) >= str.size() || size < 0){
return "";
Expand All @@ -369,11 +369,11 @@ std::string substr(const std::string &str, int start, int size){
static inline
std::string str_slice(const std::string &str, int start, int end){
if(start < 0){
start = str.size() + start;
start = (int)str.size() + start;
}
int size;
if(end < 0){
size = (str.size() + end + 1) - start;
size = ((int)str.size() + end + 1) - start;
}else{
size = end - start + 1;
}
Expand Down

0 comments on commit 77b860d

Please sign in to comment.